| Conditions | 4 |
| Paths | 4 |
| Total Lines | 23 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 4 |
| Changes | 0 | ||
| 1 | <?php |
||
| 34 | 3 | public function normalizeLink(string $path, $object, NormalizerContextInterface $context) |
|
| 35 | { |
||
| 36 | 3 | $callback = $this->callback; |
|
| 37 | |||
| 38 | 3 | $link = $callback($path, $object, $context); |
|
| 39 | |||
| 40 | 3 | if (null === $link) { |
|
| 41 | 1 | return null; |
|
| 42 | } |
||
| 43 | |||
| 44 | 2 | if (!$link instanceof LinkInterface) { |
|
| 45 | 1 | $type = is_object($link) ? get_class($link) : gettype($link); |
|
| 46 | |||
| 47 | 1 | throw SerializerLogicException::createInvalidLinkTypeReturned($path, $type); |
|
| 48 | } |
||
| 49 | |||
| 50 | return [ |
||
| 51 | 1 | 'href' => $link->getHref(), |
|
| 52 | 1 | 'templated' => $link->isTemplated(), |
|
| 53 | 1 | 'rel' => $link->getRels(), |
|
| 54 | 1 | 'attributes' => $link->getAttributes(), |
|
| 55 | ]; |
||
| 56 | } |
||
| 57 | } |
||
| 58 |