File tree Expand file tree Collapse file tree 9 files changed +47
-37
lines changed
Service/Anonymize/Anonymizer Expand file tree Collapse file tree 9 files changed +47
-37
lines changed Original file line number Diff line number Diff line change @@ -37,8 +37,8 @@ public function __construct(
37
37
* @inheritdoc
38
38
* @throws LocalizedException
39
39
*/
40
- public function anonymize ($ value ): string
40
+ public function anonymize ($ value ): ? string
41
41
{
42
- return $ this ->mathRandom ->getRandomString ($ this ->length , Random::CHARS_LOWERS );
42
+ return $ value ? $ this ->mathRandom ->getRandomString ($ this ->length , Random::CHARS_LOWERS ) : null ;
43
43
}
44
44
}
Original file line number Diff line number Diff line change @@ -37,8 +37,8 @@ public function __construct(
37
37
* @inheritdoc
38
38
* @throws LocalizedException
39
39
*/
40
- public function anonymize ($ value ): string
40
+ public function anonymize ($ value ): ? string
41
41
{
42
- return $ this ->mathRandom ->getRandomString ($ this ->length );
42
+ return $ value ? $ this ->mathRandom ->getRandomString ($ this ->length ) : null ;
43
43
}
44
44
}
Original file line number Diff line number Diff line change @@ -37,8 +37,8 @@ public function __construct(
37
37
* @inheritdoc
38
38
* @throws LocalizedException
39
39
*/
40
- public function anonymize ($ value ): string
40
+ public function anonymize ($ value ): ? string
41
41
{
42
- return $ this ->mathRandom ->getRandomString ($ this ->length , Random::CHARS_UPPERS );
42
+ return $ value ? $ this ->mathRandom ->getRandomString ($ this ->length , Random::CHARS_UPPERS ) : null ;
43
43
}
44
44
}
Original file line number Diff line number Diff line change @@ -33,16 +33,16 @@ public function __construct(
33
33
* @inheritdoc
34
34
* @throws LocalizedException
35
35
*/
36
- public function anonymize ($ value ): string
36
+ public function anonymize ($ value ): ? string
37
37
{
38
- $ phrase = new Phrase (
39
- self :: PHRASE ,
40
- [
41
- $ this -> mathRandom -> getRandomString ( self :: PREFIX_LENGTH ),
42
- $ this ->mathRandom ->getRandomString (self ::SUFFIX_LENGTH ),
43
- ]
44
- );
45
-
46
- return $ phrase -> render () ;
38
+ return $ value
39
+ ? ( new Phrase (
40
+ self :: PHRASE ,
41
+ [
42
+ $ this ->mathRandom ->getRandomString (self ::PREFIX_LENGTH ),
43
+ $ this -> mathRandom -> getRandomString ( self :: SUFFIX_LENGTH ),
44
+ ]
45
+ ))-> render ()
46
+ : null ;
47
47
}
48
48
}
Original file line number Diff line number Diff line change 7
7
8
8
namespace Opengento \Gdpr \Service \Anonymize \Anonymizer ;
9
9
10
- use Exception ;
10
+ use DateTime ;
11
+ use Magento \Framework \Exception \LocalizedException ;
11
12
use Magento \Framework \Math \Random ;
12
- use Magento \Framework \Stdlib \DateTime ;
13
+ use Magento \Framework \Stdlib \DateTime as StdlibDateTime ;
13
14
use Opengento \Gdpr \Service \Anonymize \AnonymizerInterface ;
14
15
15
16
final class Date implements AnonymizerInterface
@@ -19,13 +20,22 @@ final class Date implements AnonymizerInterface
19
20
20
21
/**
21
22
* @inheritdoc
22
- * @throws Exception
23
+ * @throws LocalizedException
23
24
*/
24
- public function anonymize ($ value ): string
25
+ public function anonymize ($ value ): ? string
25
26
{
26
- $ dateTime = new \DateTime ();
27
+ return $ value ? $ this ->randomDateTime ()->format (StdlibDateTime::DATETIME_PHP_FORMAT ) : null ;
28
+ }
29
+
30
+ /**
31
+ * @return DateTime
32
+ * @throws LocalizedException
33
+ */
34
+ private function randomDateTime (): DateTime
35
+ {
36
+ $ dateTime = new DateTime ();
27
37
$ dateTime ->setTimestamp (Random::getRandomNumber (self ::MIN_TIMESTAMP , self ::MAX_TIMESTAMP ));
28
38
29
- return $ dateTime-> format (DateTime:: DATE_PHP_FORMAT ) ;
39
+ return $ dateTime ;
30
40
}
31
41
}
Original file line number Diff line number Diff line change @@ -33,16 +33,16 @@ public function __construct(
33
33
* @inheritdoc
34
34
* @throws LocalizedException
35
35
*/
36
- public function anonymize ($ value ): string
36
+ public function anonymize ($ value ): ? string
37
37
{
38
- $ phrase = new Phrase (
39
- self :: PHRASE ,
40
- [
41
- $ this -> mathRandom -> getRandomString ( self :: PREFIX_LENGTH , Random:: CHARS_LOWERS ),
42
- $ this ->mathRandom ->getRandomString (self ::SUFFIX_LENGTH , Random::CHARS_LOWERS ),
43
- ]
44
- );
45
-
46
- return $ phrase -> render () ;
38
+ return $ value
39
+ ? ( new Phrase (
40
+ self :: PHRASE ,
41
+ [
42
+ $ this ->mathRandom ->getRandomString (self ::PREFIX_LENGTH , Random::CHARS_LOWERS ),
43
+ $ this -> mathRandom -> getRandomString ( self :: SUFFIX_LENGTH , Random:: CHARS_LOWERS ),
44
+ ]
45
+ ))-> render ()
46
+ : null ;
47
47
}
48
48
}
Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ public function __construct(
48
48
* @inheritdoc
49
49
* @throws Exception
50
50
*/
51
- public function anonymize ($ entity )
51
+ public function anonymize ($ entity ): object
52
52
{
53
53
if (!is_object ($ entity )) {
54
54
throw new InvalidArgumentException (
Original file line number Diff line number Diff line change @@ -37,8 +37,8 @@ public function __construct(
37
37
* @inheritdoc
38
38
* @throws LocalizedException
39
39
*/
40
- public function anonymize ($ value ): int
40
+ public function anonymize ($ value ): ? int
41
41
{
42
- return Random::getRandomNumber ($ this ->min , $ this ->max );
42
+ return $ value ? Random::getRandomNumber ($ this ->min , $ this ->max ) : null ;
43
43
}
44
44
}
Original file line number Diff line number Diff line change @@ -13,8 +13,8 @@ final class Phone implements AnonymizerInterface
13
13
{
14
14
private const PHONE_NUMBER = '9999999999 ' ;
15
15
16
- public function anonymize ($ value ): string
16
+ public function anonymize ($ value ): ? string
17
17
{
18
- return self ::PHONE_NUMBER ;
18
+ return $ value ? self ::PHONE_NUMBER : null ;
19
19
}
20
20
}
You can’t perform that action at this time.
0 commit comments