| Total Complexity | 4 |
| Total Lines | 56 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 8 | class HigherOrderCollectionProxy |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * The collection being operated on. |
||
| 12 | * |
||
| 13 | * @var \MiotApi\Util\Collection\Collection |
||
| 14 | */ |
||
| 15 | protected $collection; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * The method being proxied. |
||
| 19 | * |
||
| 20 | * @var string |
||
| 21 | */ |
||
| 22 | protected $method; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Create a new proxy instance. |
||
| 26 | * |
||
| 27 | * @param \MiotApi\Util\Collection\Collection $collection |
||
| 28 | * @param string $method |
||
| 29 | * |
||
| 30 | * @return void |
||
| 31 | */ |
||
| 32 | public function __construct(Collection $collection, $method) |
||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Proxy accessing an attribute onto the collection items. |
||
| 40 | * |
||
| 41 | * @param string $key |
||
| 42 | * |
||
| 43 | * @return mixed |
||
| 44 | */ |
||
| 45 | public function __get($key) |
||
| 46 | { |
||
| 47 | return $this->collection->{$this->method}(function ($value) use ($key) { |
||
| 48 | return is_array($value) ? $value[$key] : $value->{$key}; |
||
| 49 | }); |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Proxy a method call onto the collection items. |
||
| 54 | * |
||
| 55 | * @param string $method |
||
| 56 | * @param array $parameters |
||
| 57 | * |
||
| 58 | * @return mixed |
||
| 59 | */ |
||
| 60 | public function __call($method, $parameters) |
||
| 64 | }); |
||
| 65 | } |
||
| 67 |