| Conditions | 4 |
| Paths | 3 |
| Total Lines | 17 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 11 |
| CRAP Score | 4 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php namespace Pz\Doctrine\Rest\Traits; |
||
| 57 | 8 | protected function getRelatedEntity($item) |
|
| 58 | { |
||
| 59 | 8 | if (!isset($item['id']) || !isset($item['type'])) { |
|
| 60 | 1 | throw RestException::createUnprocessable('Relation item without identifiers.') |
|
| 61 | 1 | ->error( |
|
| 62 | 1 | 'invalid-data', |
|
| 63 | 1 | ['pointer' => $this->field()], |
|
| 64 | 1 | 'Relation item without `id` or `type`.' |
|
| 65 | ); |
||
| 66 | } |
||
| 67 | |||
| 68 | 8 | if ($this->related()->getResourceKey() !== $item['type']) { |
|
| 69 | 1 | throw RestException::createUnprocessable('Different resource type in delete request.') |
|
| 70 | 1 | ->error('invalid-data', ['pointer' => $this->field()], 'Type is not in sync with relation.'); |
|
| 71 | } |
||
| 72 | |||
| 73 | 7 | return $this->related()->findById($item['id']); |
|
| 74 | } |
||
| 76 |