1 | <?php |
||
11 | class Table implements \Iterator |
||
12 | { |
||
13 | /** |
||
14 | * @param DataSources\DataSourceInterface $dataSource |
||
15 | * @param Schema $schema |
||
16 | * @throws Exceptions\DataSourceException |
||
17 | */ |
||
18 | public function __construct($dataSource, $schema) |
||
24 | |||
25 | /** |
||
26 | * @param DataSources\DataSourceInterface $dataSource |
||
27 | * @param Schema $schema |
||
28 | * @param int $numPeekRows |
||
29 | * @return array of validation errors |
||
30 | */ |
||
31 | public static function validate($dataSource, $schema, $numPeekRows=10) |
||
55 | |||
56 | /** |
||
57 | * called on each iteration to get the next row |
||
58 | * depends on order of fields in the schema to match to the order of fields from the data source |
||
59 | * @return array |
||
60 | * @throws TableRowValidationException |
||
61 | */ |
||
62 | public function current() { |
||
66 | |||
67 | // not interesting, standard iterator functions |
||
68 | // to simplify we prevent rewinding - so you can only iterate once |
||
69 | public function __destruct() {$this->dataSource->close();} |
||
74 | |||
75 | protected $currentLine = 0; |
||
76 | protected $dataSource; |
||
77 | protected $schema; |
||
78 | |||
79 | /** |
||
80 | * validates the given line against the table schema |
||
81 | * casts the values to the native representation according to the schema |
||
82 | * @param array $line |
||
83 | * @return array |
||
84 | * @throws TableRowValidationException |
||
85 | */ |
||
86 | protected function filterLine($line) |
||
115 | } |
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return
,die
orexit
statements that have been added for debug purposes.In the above example, the last
return false
will never be executed, because a return statement has already been met in every possible execution path.