| Total Complexity | 12 |
| Total Lines | 80 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 5 | class Scheme implements CastInterface |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * @var CastInterface[] |
||
| 9 | */ |
||
| 10 | protected $config = []; |
||
| 11 | /** |
||
| 12 | * @var Factory |
||
| 13 | */ |
||
| 14 | protected $factory; |
||
| 15 | /** |
||
| 16 | * @var bool |
||
| 17 | */ |
||
| 18 | protected $strict; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @param array $config |
||
| 22 | * @param Factory|null $factory |
||
| 23 | * @param bool $strict |
||
| 24 | * |
||
| 25 | * @throws \Mvkasatkin\typecast\Exception |
||
| 26 | */ |
||
| 27 | public function __construct(array $config = [], Factory $factory = null, bool $strict = false) |
||
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @param array $config |
||
| 36 | * |
||
| 37 | * @return array |
||
| 38 | * @throws \Mvkasatkin\typecast\Exception |
||
| 39 | */ |
||
| 40 | protected function parseConfig(array $config): array |
||
| 41 | { |
||
| 42 | $result = []; |
||
| 43 | foreach ($config as $key => $type) { |
||
| 44 | if (\is_array($type)) { |
||
| 45 | if ($arrayOfType = $this->factory->checkArrayOfType($type)) { |
||
| 46 | $result[$key] = $arrayOfType; |
||
| 47 | } else { |
||
| 48 | $result[$key] = new self($type, $this->factory, $this->strict); |
||
| 49 | } |
||
| 50 | } elseif ($type instanceof CastInterface) { |
||
| 51 | $result[$key] = $type; |
||
| 52 | } else { |
||
| 53 | $result[$key] = $this->factory->createType($type); |
||
| 54 | } |
||
| 55 | } |
||
| 56 | |||
| 57 | return $result; |
||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @param $value |
||
| 62 | * |
||
| 63 | * @return array |
||
| 64 | */ |
||
| 65 | public function cast($value): array |
||
| 85 | } |
||
| 86 | } |
||
| 87 |