| Conditions | 7 |
| Paths | 16 |
| Total Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 56 |
| Changes | 0 | ||
| 1 | <?php |
||
| 24 | public function jsonSerialize(): array |
||
| 25 | { |
||
| 26 | $result = []; |
||
| 27 | |||
| 28 | foreach ($this->getObjectFields() as $field => $value) { |
||
|
|
|||
| 29 | foreach ($this->jsonNonRenderableTypes() as $type) { |
||
| 30 | if ($value instanceof $type) { |
||
| 31 | continue 2; |
||
| 32 | } |
||
| 33 | } |
||
| 34 | |||
| 35 | foreach ($this->jsonNonRenderableFields() as $name) { |
||
| 36 | if ($field === $name) { |
||
| 37 | continue 2; |
||
| 38 | } |
||
| 39 | } |
||
| 40 | |||
| 41 | $result[$field] = $value; |
||
| 42 | } |
||
| 43 | |||
| 44 | // Additional information about type |
||
| 45 | if ($this instanceof Definition) { |
||
| 46 | $result['__typename'] = $this::getType()->getName(); |
||
| 47 | } |
||
| 48 | |||
| 49 | return $result; |
||
| 50 | } |
||
| 51 | |||
| 81 |
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.