| Conditions | 2 |
| Paths | 2 |
| Total Lines | 12 |
| Code Lines | 6 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 6 |
| Changes | 0 | ||
| 1 | <?php |
||
| 25 | public function getEntityReference($fqcn, $property, $identifier) |
||
| 26 | { |
||
| 27 | $metadata = $this->registry->getManagerForClass($fqcn)->getClassMetadata($fqcn); |
||
| 28 | |||
| 29 | if (!$metadata->hasAssociation($property)) { |
||
| 30 | return $identifier; |
||
| 31 | } |
||
| 32 | |||
| 33 | $target = $metadata->getAssociationTargetClass($property); |
||
| 34 | |||
| 35 | return $this->registry->getManagerForClass($fqcn)->getPartialReference($target, $identifier); |
||
|
|
|||
| 36 | } |
||
| 37 | } |
||
| 38 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: