Total Complexity | 10 |
Total Lines | 65 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
24 | abstract class Base implements FileGatewayInterface |
||
25 | { |
||
26 | /** @var ReaderInterface $concretion */ |
||
27 | protected $concretion; |
||
28 | |||
29 | /** @var string $type */ |
||
30 | protected $type; |
||
31 | |||
32 | /** |
||
33 | * Base constructor. |
||
34 | * @throws Exception |
||
35 | */ |
||
36 | public function __construct() |
||
37 | { |
||
38 | try { |
||
39 | $this->concretion = ReaderFactory::createFromType($this->type); |
||
40 | } catch (UnsupportedTypeException $exception) { |
||
41 | throw new Exception("Reader Agent Class does not exist"); |
||
42 | } |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * @inheritDoc |
||
47 | */ |
||
48 | public function fetchData(string $fileName): Iterator |
||
49 | { |
||
50 | $this->concretion->open($fileName); |
||
51 | $sheet = $this->getActiveSheet(); |
||
52 | |||
53 | return $this->yieldData($sheet); |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * @return SheetInterface |
||
58 | * @throws ReaderNotOpenedException |
||
59 | */ |
||
60 | private function getActiveSheet(): SheetInterface |
||
67 | } |
||
68 | } |
||
|
|||
69 | } |
||
70 | |||
71 | /** |
||
72 | * @param SheetInterface $sheet |
||
73 | * |
||
74 | * @return Generator |
||
75 | */ |
||
76 | private function yieldData(SheetInterface $sheet) |
||
80 | } |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * @inheritDoc |
||
85 | */ |
||
86 | public function asArray($object) |
||
91 |
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: