1 | <?php |
||
25 | trait ContainerTrait |
||
26 | { |
||
27 | use FactoryTrait; |
||
28 | use ReferenceTrait; |
||
29 | |||
30 | /** |
||
31 | * for configuration lookup |
||
32 | * |
||
33 | * @var ConfigInterface |
||
34 | */ |
||
35 | protected $config; |
||
36 | |||
37 | /** |
||
38 | * delegator for object lookup |
||
39 | * |
||
40 | * @var ContainerInterface |
||
41 | */ |
||
42 | protected $delegator; |
||
43 | |||
44 | /** |
||
45 | * object pool |
||
46 | * |
||
47 | * @var array |
||
48 | */ |
||
49 | protected $objects; |
||
50 | |||
51 | /** |
||
52 | * service prefix |
||
53 | * |
||
54 | * @var string |
||
55 | */ |
||
56 | protected $prefix = 'di.service.'; |
||
57 | |||
58 | /** |
||
59 | * common prefix |
||
60 | * |
||
61 | * @var string |
||
62 | */ |
||
63 | protected $common = 'di.common'; |
||
64 | |||
65 | /** |
||
66 | * init the container |
||
67 | * |
||
68 | * @param ConfigInterface $config |
||
69 | * @param ContainerInterface $delegator |
||
70 | * @return void |
||
71 | */ |
||
72 | protected function initContainer( |
||
82 | |||
83 | /** |
||
84 | * Reload all service definitions |
||
85 | * |
||
86 | * @return void |
||
87 | */ |
||
88 | protected function reloadAll(): void |
||
100 | |||
101 | /** |
||
102 | * Get the instance |
||
103 | * |
||
104 | * @param string $id |
||
105 | * @return object |
||
106 | */ |
||
107 | protected function getInstance(string $id): object |
||
120 | |||
121 | /** |
||
122 | * creaet a new instance |
||
123 | * |
||
124 | * @param string $id |
||
125 | * @return object |
||
126 | */ |
||
127 | protected function newInstance(string $id): object |
||
134 | |||
135 | /** |
||
136 | * Try find a service in the definition |
||
137 | * |
||
138 | * @param string $id |
||
139 | * @return bool |
||
140 | */ |
||
141 | protected function hasDefinition(string $id): bool |
||
145 | |||
146 | /** |
||
147 | * get the raw id as defined in $config |
||
148 | * |
||
149 | * @param string $id |
||
150 | * @return string |
||
151 | */ |
||
152 | protected function getRawId(string $id): string |
||
156 | |||
157 | /** |
||
158 | * {@inheritDoc} |
||
159 | */ |
||
160 | protected function getReference(string $name) |
||
164 | |||
165 | /** |
||
166 | * execute common methods for newed objects |
||
167 | * |
||
168 | * @param object $object |
||
169 | * @return void |
||
170 | */ |
||
171 | protected function executeCommon(object $object): void |
||
184 | } |
||
185 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.