| Total Complexity | 2 |
| Total Lines | 41 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 7 | abstract class Transformer |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var object |
||
| 11 | */ |
||
| 12 | protected $item; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Create a new instance. |
||
| 16 | * |
||
| 17 | * @param object $item |
||
| 18 | */ |
||
| 19 | public function __construct($item) |
||
| 20 | { |
||
| 21 | throw_if(! $this->validate($item), new Exception('Expected argument of type "'.get_class($item).'" "'.get_class($item).'" given.')); |
||
| 22 | $this->item = $item; |
||
| 23 | } |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Convert the object instance to an array. |
||
| 27 | * |
||
| 28 | * @return array |
||
| 29 | */ |
||
| 30 | abstract public function toArray(): array; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Determine which class of object should be transform. |
||
| 34 | * |
||
| 35 | * @return string |
||
| 36 | */ |
||
| 37 | abstract public function objectClass(): string; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Check if the given object item is an instance of the determined class. |
||
| 41 | * |
||
| 42 | * @param $item |
||
| 43 | * @return bool |
||
| 44 | */ |
||
| 45 | protected function validate($item) |
||
| 48 | } |
||
| 49 | } |
||
| 50 |