This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Carnage\EncryptedColumn; |
||
4 | |||
5 | use Carnage\EncryptedColumn\Container\KeyContainer; |
||
6 | use Carnage\EncryptedColumn\Container\VersionedContainer; |
||
7 | use Carnage\EncryptedColumn\Dbal\EncryptedColumn; |
||
8 | use Carnage\EncryptedColumn\Dbal\EncryptedColumnLegacySupport; |
||
9 | use Carnage\EncryptedColumn\Encryptor\HaliteEncryptor; |
||
10 | use Carnage\EncryptedColumn\Encryptor\LegacyEncryptor; |
||
11 | use Carnage\EncryptedColumn\Serializer\LegacySerializer; |
||
12 | use Carnage\EncryptedColumn\Serializer\PhpSerializer; |
||
13 | use Carnage\EncryptedColumn\Service\EncryptionService; |
||
14 | use Carnage\EncryptedColumn\ValueObject\Key; |
||
15 | use Carnage\EncryptedColumn\ValueObject\KeyIdentity; |
||
16 | use Doctrine\ORM\EntityManagerInterface; |
||
17 | |||
18 | final class Setup |
||
19 | { |
||
20 | private $keyPath; |
||
21 | 1 | private $enableLegacy = false; |
|
22 | private $legacyKey; |
||
23 | 1 | private $keyContainer; |
|
24 | 1 | ||
25 | public function __construct() |
||
26 | { |
||
27 | $this->keyContainer = new KeyContainer(); |
||
28 | 1 | } |
|
29 | |||
30 | 1 | public function register(EntityManagerInterface $em) |
|
31 | { |
||
32 | 1 | if ($this->enableLegacy) { |
|
33 | 1 | $this->doRegisterLegacy($em); |
|
34 | 1 | } else { |
|
35 | $this->doRegister($em); |
||
36 | } |
||
37 | 1 | } |
|
38 | |||
39 | 1 | View Code Duplication | public function enableLegacy(string $legacyKey) |
0 ignored issues
–
show
|
|||
40 | 1 | { |
|
41 | $this->enableLegacy = true; |
||
42 | $this->legacyKey = $legacyKey; |
||
43 | 1 | ||
44 | $key = new Key($legacyKey); |
||
45 | 1 | $this->keyContainer->addKey($key); |
|
46 | 1 | $this->keyContainer->tagKey('legacy', $key->getIdentifier()->toString()); |
|
47 | 1 | ||
48 | 1 | return $this; |
|
49 | 1 | } |
|
50 | |||
51 | View Code Duplication | public function withKeyPath(string $keypath) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
52 | { |
||
53 | $this->keyPath = $keypath; |
||
54 | |||
55 | 1 | $key = new Key($keypath); |
|
56 | $this->keyContainer->addKey($key); |
||
57 | 1 | $this->keyContainer->tagKey('default', $key->getIdentifier()->toString()); |
|
58 | 1 | ||
59 | 1 | return $this; |
|
60 | } |
||
61 | |||
62 | 1 | public function withKey(string $key, array $tags = []) |
|
63 | { |
||
64 | $key = new Key($key); |
||
65 | 1 | $keyId = $key->getIdentifier()->toString(); |
|
66 | $this->keyContainer->addKey($key); |
||
67 | 1 | ||
68 | 1 | foreach ($tags as $tag) { |
|
69 | 1 | $this->keyContainer->tagKey($tag, $keyId); |
|
70 | } |
||
71 | 1 | ||
72 | return $this; |
||
73 | } |
||
74 | |||
75 | private function buildEncryptionService(): EncryptionService |
||
76 | { |
||
77 | $encryptors = self::buildEncryptorsContainer(); |
||
78 | $serializers = self::buildSerilaizerContainer(); |
||
79 | return new EncryptionService( |
||
80 | $encryptors->get(HaliteEncryptor::IDENTITY), |
||
0 ignored issues
–
show
$encryptors->get(\Carnag...iteEncryptor::IDENTITY) of type object<Carnage\Encrypted...ner\VersionedInterface> is not a sub-type of object<Carnage\Encrypted...tor\EncryptorInterface> . It seems like you assume a child interface of the interface Carnage\EncryptedColumn\...iner\VersionedInterface to be always present.
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass. Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type. ![]() |
|||
81 | $serializers->get(PhpSerializer::IDENTITY), |
||
0 ignored issues
–
show
$serializers->get(\Carna...hpSerializer::IDENTITY) of type object<Carnage\Encrypted...ner\VersionedInterface> is not a sub-type of object<Carnage\Encrypted...er\SerializerInterface> . It seems like you assume a child interface of the interface Carnage\EncryptedColumn\...iner\VersionedInterface to be always present.
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass. Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type. ![]() |
|||
82 | $encryptors, |
||
83 | $serializers, |
||
84 | $this->keyContainer |
||
85 | ); |
||
86 | } |
||
87 | |||
88 | private function buildEncryptorsContainer(): VersionedContainer |
||
89 | { |
||
90 | 1 | $services = [new HaliteEncryptor($this->keyPath)]; |
|
0 ignored issues
–
show
The call to
HaliteEncryptor::__construct() has too many arguments starting with $this->keyPath .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the ![]() |
|||
91 | if ($this->enableLegacy) { |
||
92 | 1 | $services[] = new LegacyEncryptor($this->legacyKey); |
|
0 ignored issues
–
show
The call to
LegacyEncryptor::__construct() has too many arguments starting with $this->legacyKey .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the ![]() |
|||
93 | 1 | } |
|
94 | 1 | //@TODO add legacy encryptor, throw exceptions if required keys aren't specified |
|
95 | 1 | return new VersionedContainer(...$services); |
|
96 | 1 | } |
|
97 | |||
98 | 1 | private function buildSerilaizerContainer(): VersionedContainer |
|
99 | { |
||
100 | $services = [new PhpSerializer()]; |
||
101 | if ($this->enableLegacy) { |
||
102 | $services[] = new LegacySerializer(); |
||
103 | } |
||
104 | return new VersionedContainer(...$services); |
||
105 | } |
||
106 | |||
107 | /** |
||
108 | * @param EntityManagerInterface $em |
||
109 | */ |
||
110 | View Code Duplication | private function doRegister(EntityManagerInterface $em) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
111 | { |
||
112 | EncryptedColumn::create($this->buildEncryptionService()); |
||
113 | $conn = $em->getConnection(); |
||
114 | $conn->getDatabasePlatform()->registerDoctrineTypeMapping( |
||
115 | EncryptedColumn::ENCRYPTED, |
||
116 | EncryptedColumn::ENCRYPTED |
||
117 | ); |
||
118 | } |
||
119 | |||
120 | /** |
||
121 | * @param EntityManagerInterface $em |
||
122 | */ |
||
123 | View Code Duplication | private function doRegisterLegacy(EntityManagerInterface $em) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
124 | { |
||
125 | EncryptedColumnLegacySupport::create($this->buildEncryptionService()); |
||
126 | $conn = $em->getConnection(); |
||
127 | $conn->getDatabasePlatform()->registerDoctrineTypeMapping( |
||
128 | EncryptedColumnLegacySupport::ENCRYPTED, |
||
129 | EncryptedColumnLegacySupport::ENCRYPTED |
||
130 | ); |
||
131 | } |
||
132 | } |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.