1 | <?php |
||
11 | class Analyse extends Base implements AnalyseInterface |
||
12 | { |
||
13 | /** |
||
14 | * @var string The description for missing mandatory columns. |
||
15 | */ |
||
16 | const ERROR_REQUIRED_COLUMN_MISSING = '<strong>%d</strong> required column(s) missing:'; |
||
17 | |||
18 | /** |
||
19 | * @var string The description for CSV columns that are not in the schema. |
||
20 | */ |
||
21 | const ERROR_UNSPECIFIED_COLUMN = '<strong>%d</strong> unexpected column(s):'; |
||
22 | |||
23 | /** |
||
24 | * @var string The description for rows with missing columns. |
||
25 | */ |
||
26 | const ERROR_INCORRECT_COLUMN_COUNT = 'There are the wrong number of columns'; |
||
27 | |||
28 | /** |
||
29 | * @var string The description for rows with missing columns. |
||
30 | */ |
||
31 | const ERROR_REQUIRED_FIELD_MISSING_DATA = 'There are <strong>%d</strong> required fields with missing data:'; |
||
32 | |||
33 | /** |
||
34 | * @var string The format validation type. |
||
35 | */ |
||
36 | const VALIDATION_TYPE_FORMAT = 'Format'; |
||
37 | |||
38 | /** |
||
39 | * @var string The foreign key validation type. |
||
40 | */ |
||
41 | const VALIDATION_TYPE_FOREIGN_KEY = 'ForeignKey'; |
||
42 | |||
43 | /** |
||
44 | * @var boolean Should the analysis stop when an error is found. |
||
45 | */ |
||
46 | protected $stopIfInvalid; |
||
47 | |||
48 | /** |
||
49 | * @var Statistics Statistics information regarding the analysis. |
||
50 | */ |
||
51 | protected $statistics; |
||
52 | |||
53 | /** |
||
54 | * @var Error Details of errors found during the analysis. |
||
55 | */ |
||
56 | protected $error; |
||
57 | |||
58 | |||
59 | /** |
||
60 | * Set the dependencies if they've been provided. |
||
61 | * |
||
62 | * @param Statistics $statistics Statistics information regarding the analysis. Optional. |
||
63 | * @param Error $error Details of errors found during the analysis. Optional. |
||
64 | */ |
||
65 | 41 | public function __construct(Statistics $statistics = null, Error $error = null) |
|
70 | |||
71 | |||
72 | /** |
||
73 | * Analyse the specified file against the loaded schema. |
||
74 | * |
||
75 | * @param boolean $stopIfInvalid Should the analysis stop when the file is found to be invalid. |
||
76 | * The default is false. |
||
77 | * |
||
78 | * @return boolean true if the file passes the validation and false if not. |
||
79 | */ |
||
80 | 30 | public function validate($stopIfInvalid = false) |
|
114 | |||
115 | |||
116 | /** |
||
117 | * Return all errors. |
||
118 | * |
||
119 | * @return array The error messages. |
||
120 | */ |
||
121 | 2 | public function getErrors() |
|
125 | |||
126 | |||
127 | /** |
||
128 | * Return the statistics about this analysis. |
||
129 | * |
||
130 | * @return array The statistics. |
||
131 | */ |
||
132 | 10 | public function getStatistics() |
|
136 | |||
137 | |||
138 | /** |
||
139 | * Check if the specified column is mandatory. |
||
140 | * |
||
141 | * @param object $schemaColumn The schema column object to examine. |
||
142 | * |
||
143 | * @return boolean Whether the column is mandatory. |
||
144 | */ |
||
145 | 30 | protected function isColumnMandatory($schemaColumn) |
|
152 | |||
153 | |||
154 | /** |
||
155 | * Load and instantiate the specified validator. |
||
156 | * |
||
157 | * @param string $validationType The type of validator to load. |
||
158 | * @param string $type The type being validated. |
||
159 | * For formats this will be the field type. |
||
160 | * For foreign keys this will be the datapackage type |
||
161 | * |
||
162 | * @return object The validation object. Throws an exception on error. |
||
163 | * |
||
164 | * @throws \Exception if the validator file couldn't be loaded. |
||
165 | * @throws \Exception if the validator class definition couldn't be found. |
||
166 | */ |
||
167 | 28 | protected function instantiateValidator($validationType, $type) |
|
192 | |||
193 | |||
194 | /** |
||
195 | * Check if the file was found to be valid. |
||
196 | * This checks for any validation errors. |
||
197 | * |
||
198 | * @return boolean Is the file valid. |
||
199 | */ |
||
200 | 30 | private function isFileValid() |
|
204 | } |
||
205 |