| Conditions | 6 |
| Paths | 5 |
| Total Lines | 25 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 19 | public function transform(Assign $node, ClassData $class, $scope, $index) |
||
| 20 | { |
||
| 21 | $fetch = $node->var; |
||
| 22 | if (!$fetch instanceof PropertyFetch) { |
||
| 23 | return; |
||
| 24 | } |
||
| 25 | if (!$fetch->var instanceof Variable || $fetch->var->name !== 'this') { |
||
| 26 | return; |
||
| 27 | } |
||
| 28 | $type = $this->typeResolver->getType( |
||
| 29 | $node->expr, |
||
| 30 | $index, |
||
| 31 | $scope |
||
| 32 | ); |
||
| 33 | if ($class->hasProp($fetch->name)) { |
||
| 34 | $prop = $class->getProp($fetch->name); |
||
| 35 | if ($type instanceof FQCN) { |
||
| 36 | $prop->setType($type); |
||
| 37 | } |
||
| 38 | } else { |
||
| 39 | $class->addProp( |
||
| 40 | new ClassProperty($fetch->name, $type) |
||
| 41 | ); |
||
| 42 | } |
||
| 43 | } |
||
| 44 | |||
| 47 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.