@@ -3,11 +3,11 @@ discard block |
||
| 3 | 3 | |
| 4 | 4 | class SchemaValidationError |
| 5 | 5 | { |
| 6 | - const LOAD_FAILED=1; |
|
| 7 | - const SCHEMA_VIOLATION=8; |
|
| 8 | - const FIELD_VALIDATION=21; |
|
| 9 | - const ROW_FIELD_VALIDATION=22; |
|
| 10 | - const ROW_VALIDATION=23; |
|
| 6 | + const LOAD_FAILED = 1; |
|
| 7 | + const SCHEMA_VIOLATION = 8; |
|
| 8 | + const FIELD_VALIDATION = 21; |
|
| 9 | + const ROW_FIELD_VALIDATION = 22; |
|
| 10 | + const ROW_VALIDATION = 23; |
|
| 11 | 11 | |
| 12 | 12 | public $code; |
| 13 | 13 | public $extraDetails; |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @param integer $code |
| 17 | 17 | * @param mixed $extraDetails |
| 18 | 18 | */ |
| 19 | - public function __construct($code, $extraDetails=null) |
|
| 19 | + public function __construct($code, $extraDetails = null) |
|
| 20 | 20 | { |
| 21 | 21 | $this->code = $code; |
| 22 | 22 | $this->extraDetails = $extraDetails; |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | */ |
| 62 | 62 | public static function getErrorMessages($validationErrors) |
| 63 | 63 | { |
| 64 | - return implode(", ", array_map(function($validationError){ |
|
| 64 | + return implode(", ", array_map(function($validationError) { |
|
| 65 | 65 | /** @var SchemaValidationError $validationError */ |
| 66 | 66 | return $validationError->getMessage(); |
| 67 | 67 | }, $validationErrors)); |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | */ |
| 7 | 7 | class InferSchema extends Schema |
| 8 | 8 | { |
| 9 | - public function __construct($descriptor=null, $lenient=false) |
|
| 9 | + public function __construct($descriptor = null, $lenient = false) |
|
| 10 | 10 | { |
| 11 | 11 | $this->descriptor = empty($descriptor) ? (object)["fields" => []] : $descriptor; |
| 12 | 12 | $this->fieldsInferer = new Fields\FieldsInferrer(null, $lenient); |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | $this->descriptor->fields[] = $inferredField->descriptor(); |
| 40 | 40 | } |
| 41 | 41 | $this->castRows = $this->fieldsInferer->castRows(); |
| 42 | - return $this->castRows[count($this->castRows)-1]; |
|
| 42 | + return $this->castRows[count($this->castRows) - 1]; |
|
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | 45 | |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | * @param int $numPeekRows |
| 27 | 27 | * @return array of validation errors |
| 28 | 28 | */ |
| 29 | - public static function validate($dataSource, $schema, $numPeekRows=10) |
|
| 29 | + public static function validate($dataSource, $schema, $numPeekRows = 10) |
|
| 30 | 30 | { |
| 31 | 31 | try { |
| 32 | 32 | $table = new static($dataSource, $schema); |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | // validation error in one of the fields |
| 50 | 50 | return array_map(function($validationError) use ($i) { |
| 51 | 51 | return new SchemaValidationError(SchemaValidationError::ROW_FIELD_VALIDATION, [ |
| 52 | - "row" => $i+1, |
|
| 52 | + "row" => $i + 1, |
|
| 53 | 53 | "field" => $validationError->extraDetails["field"], |
| 54 | 54 | "error" => $validationError->extraDetails["error"], |
| 55 | 55 | "value" => $validationError->extraDetails["value"], |
@@ -73,11 +73,11 @@ discard block |
||
| 73 | 73 | |
| 74 | 74 | // not interesting, standard iterator functions |
| 75 | 75 | // to simplify we prevent rewinding - so you can only iterate once |
| 76 | - public function __destruct() {$this->dataSource->close();} |
|
| 77 | - public function rewind() {if ($this->currentLine == 0) {$this->currentLine = 1;} else {throw new \Exception("rewind is not supported");}} |
|
| 78 | - public function key() {return $this->currentLine;} |
|
| 79 | - public function next() {$this->currentLine++;} |
|
| 80 | - public function valid() {return !$this->dataSource->isEof();} |
|
| 76 | + public function __destruct() {$this->dataSource->close(); } |
|
| 77 | + public function rewind() {if ($this->currentLine == 0) {$this->currentLine = 1; } else {throw new \Exception("rewind is not supported"); }} |
|
| 78 | + public function key() {return $this->currentLine; } |
|
| 79 | + public function next() {$this->currentLine++; } |
|
| 80 | + public function valid() {return !$this->dataSource->isEof(); } |
|
| 81 | 81 | |
| 82 | 82 | protected $currentLine = 0; |
| 83 | 83 | protected $dataSource; |
@@ -37,7 +37,9 @@ |
||
| 37 | 37 | $i = 0; |
| 38 | 38 | try { |
| 39 | 39 | foreach ($table as $row) { |
| 40 | - if (++$i > $numPeekRows) break; |
|
| 40 | + if (++$i > $numPeekRows) { |
|
| 41 | + break; |
|
| 42 | + } |
|
| 41 | 43 | } |
| 42 | 44 | } catch (Exceptions\DataSourceException $e) { |
| 43 | 45 | // general error in getting the next row from the data source |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | throw new FieldValidationException([ |
| 34 | 34 | new SchemaValidationError( |
| 35 | 35 | SchemaValidationError::SCHEMA_VIOLATION, |
| 36 | - "Could not find a valid field for descriptor: ".json_encode($descriptor)) |
|
| 36 | + "Could not find a valid field for descriptor: " . json_encode($descriptor)) |
|
| 37 | 37 | ]); |
| 38 | 38 | } |
| 39 | 39 | |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | * @return mixed |
| 44 | 44 | * @throws FieldValidationException |
| 45 | 45 | */ |
| 46 | - public static function infer($val, $descriptor=null, $lenient=false) |
|
| 46 | + public static function infer($val, $descriptor = null, $lenient = false) |
|
| 47 | 47 | { |
| 48 | 48 | foreach (static::$fieldClasses as $fieldClass) { |
| 49 | 49 | /** @var BaseField $fieldClass */ |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | throw new FieldValidationException([ |
| 55 | 55 | new SchemaValidationError( |
| 56 | 56 | SchemaValidationError::SCHEMA_VIOLATION, |
| 57 | - "Could not find a valid field for value: ".json_encode($val)) |
|
| 57 | + "Could not find a valid field for value: " . json_encode($val)) |
|
| 58 | 58 | ]); |
| 59 | 59 | } |
| 60 | 60 | } |
| 61 | 61 | \ No newline at end of file |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | |
| 7 | 7 | abstract class BaseField |
| 8 | 8 | { |
| 9 | - public function __construct($descriptor=null) |
|
| 9 | + public function __construct($descriptor = null) |
|
| 10 | 10 | { |
| 11 | 11 | $this->descriptor = empty($descriptor) ? (object)[] : $descriptor; |
| 12 | 12 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * @param bool @lenient |
| 45 | 45 | * @return bool|BaseField |
| 46 | 46 | */ |
| 47 | - public static function infer($val, $descriptor=null, $lenient=false) |
|
| 47 | + public static function infer($val, $descriptor = null, $lenient = false) |
|
| 48 | 48 | { |
| 49 | 49 | $field = new static($descriptor); |
| 50 | 50 | try { |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | * @param bool @lenient |
| 95 | 95 | * @return string |
| 96 | 96 | */ |
| 97 | - public function getInferIdentifier($lenient=false) |
|
| 97 | + public function getInferIdentifier($lenient = false) |
|
| 98 | 98 | { |
| 99 | 99 | return $this->type(); |
| 100 | 100 | } |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | |
| 111 | 111 | protected $descriptor; |
| 112 | 112 | |
| 113 | - protected function getValidationException($errorMsg, $val=null) |
|
| 113 | + protected function getValidationException($errorMsg, $val = null) |
|
| 114 | 114 | { |
| 115 | 115 | return new FieldValidationException([ |
| 116 | 116 | new SchemaValidationError(SchemaValidationError::FIELD_VALIDATION, [ |
@@ -8,7 +8,7 @@ |
||
| 8 | 8 | /** |
| 9 | 9 | * @param null|array $rows optional initial rows to infer by, each row is an array of field name => field value |
| 10 | 10 | */ |
| 11 | - public function __construct($rows=null, $lenient=false) |
|
| 11 | + public function __construct($rows = null, $lenient = false) |
|
| 12 | 12 | { |
| 13 | 13 | $this->lenient = $lenient; |
| 14 | 14 | if (!empty($rows)) { |
@@ -116,7 +116,9 @@ |
||
| 116 | 116 | try { |
| 117 | 117 | $rowNum = 0; |
| 118 | 118 | foreach ($this->inputRows as $inputRow) { |
| 119 | - if (!array_key_exists($rowNum, $this->castRows)) $this->castRows[$rowNum] = []; |
|
| 119 | + if (!array_key_exists($rowNum, $this->castRows)) { |
|
| 120 | + $this->castRows[$rowNum] = []; |
|
| 121 | + } |
|
| 120 | 122 | $this->castRows[$rowNum][$fieldName] = $inferredField->castValue($inputRow[$fieldName]); |
| 121 | 123 | $rowNum++; |
| 122 | 124 | } |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | return isset($this->descriptor()->format) ? $this->descriptor()->format : null; |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | - public function inferProperties($val, $lenient=false) |
|
| 13 | + public function inferProperties($val, $lenient = false) |
|
| 14 | 14 | { |
| 15 | 15 | parent::inferProperties($val, $lenient); |
| 16 | 16 | if (!$lenient) { |
@@ -39,12 +39,12 @@ discard block |
||
| 39 | 39 | return "string"; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - public function getInferIdentifier($lenient=false) |
|
| 42 | + public function getInferIdentifier($lenient = false) |
|
| 43 | 43 | { |
| 44 | 44 | $inferId = parent::getInferIdentifier(); |
| 45 | 45 | $format = $this->format(); |
| 46 | 46 | if (!$lenient && !empty($format)) { |
| 47 | - $inferId .= ":".$this->format(); |
|
| 47 | + $inferId .= ":" . $this->format(); |
|
| 48 | 48 | }; |
| 49 | 49 | return $inferId; |
| 50 | 50 | } |