| Conditions | 4 |
| Paths | 3 |
| Total Lines | 13 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 8 |
| CRAP Score | 4.128 |
| Changes | 0 | ||
| 1 | <?php |
||
| 16 | 43 | protected function persist($object, $action = 'persist') |
|
| 17 | { |
||
| 18 | 43 | $objectManager = $this->getObjectManager(); |
|
|
|
|||
| 19 | 43 | if ($objId = $object->getId()) { |
|
| 20 | 20 | $newObj = $objectManager->getRepository(get_class($object))->find($objId); |
|
| 21 | 20 | if (null !== $newObj && spl_object_hash($newObj) !== spl_object_hash($object)) { |
|
| 22 | Util::copy($object, $newObj); |
||
| 23 | $object = $newObj; |
||
| 24 | } |
||
| 25 | } |
||
| 26 | 43 | $objectManager->$action($object); |
|
| 27 | 43 | $objectManager->flush(); |
|
| 28 | 43 | } |
|
| 29 | } |
||
| 30 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()as an abstract method to the trait will make sure it is available.