@@ -38,7 +38,7 @@ |
||
| 38 | 38 | |
| 39 | 39 | /** |
| 40 | 40 | * @param integer $code |
| 41 | - * @param mixed $extraDetails |
|
| 41 | + * @param string $extraDetails |
|
| 42 | 42 | */ |
| 43 | 43 | protected function addError($code, $extraDetails=null) |
| 44 | 44 | { |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * @param integer $code |
| 41 | 41 | * @param mixed $extraDetails |
| 42 | 42 | */ |
| 43 | - protected function addError($code, $extraDetails=null) |
|
| 43 | + protected function addError($code, $extraDetails = null) |
|
| 44 | 44 | { |
| 45 | 45 | $this->errors[] = new SchemaValidationError($code, $extraDetails); |
| 46 | 46 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | $this->applyForeignKeysResourceHack($descriptor); |
| 54 | 54 | $validator->validate( |
| 55 | 55 | $descriptor, |
| 56 | - (object)['$ref' => 'file://' . realpath(dirname(__FILE__)).'/schemas/table-schema.json'] |
|
| 56 | + (object)['$ref' => 'file://' . realpath(dirname(__FILE__)) . '/schemas/table-schema.json'] |
|
| 57 | 57 | ); |
| 58 | 58 | if (!$validator->isValid()) { |
| 59 | 59 | foreach ($validator->getErrors() as $error) { |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | */ |
| 7 | 7 | abstract class BaseDataSource implements DataSourceInterface |
| 8 | 8 | { |
| 9 | - public function __construct($dataSource, $options=null) |
|
| 9 | + public function __construct($dataSource, $options = null) |
|
| 10 | 10 | { |
| 11 | 11 | $this->dataSource = $dataSource; |
| 12 | 12 | $this->options = empty($options) ? (object)[] : $options; |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | protected $dataSource; |
| 28 | 28 | protected $options; |
| 29 | 29 | |
| 30 | - protected function getOption($name, $default=null) |
|
| 30 | + protected function getOption($name, $default = null) |
|
| 31 | 31 | { |
| 32 | 32 | if (isset($this->options->{$name})) { |
| 33 | 33 | return $this->options->{$name}; |
@@ -19,7 +19,7 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | public function __construct($validationErrors) |
| 21 | 21 | { |
| 22 | - parent::__construct("Schema failed validation: ".SchemaValidationError::getErrorMessages($validationErrors)); |
|
| 22 | + parent::__construct("Schema failed validation: " . SchemaValidationError::getErrorMessages($validationErrors)); |
|
| 23 | 23 | $this->validationErrors = $validationErrors; |
| 24 | 24 | } |
| 25 | 25 | } |
@@ -8,7 +8,7 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | class DataSourceException extends \Exception |
| 10 | 10 | { |
| 11 | - public function __construct($message, $rowNum=0) |
|
| 11 | + public function __construct($message, $rowNum = 0) |
|
| 12 | 12 | { |
| 13 | 13 | if (!empty($rowNum)) $message = "row {$rowNum}: {$message}"; |
| 14 | 14 | parent::__construct($message); |
@@ -10,7 +10,9 @@ |
||
| 10 | 10 | { |
| 11 | 11 | public function __construct($message, $rowNum=0) |
| 12 | 12 | { |
| 13 | - if (!empty($rowNum)) $message = "row {$rowNum}: {$message}"; |
|
| 13 | + if (!empty($rowNum)) { |
|
| 14 | + $message = "row {$rowNum}: {$message}"; |
|
| 15 | + } |
|
| 14 | 16 | parent::__construct($message); |
| 15 | 17 | } |
| 16 | 18 | } |
@@ -14,12 +14,12 @@ |
||
| 14 | 14 | public function __construct($descriptor, $descriptorSource, $errorMessage) |
| 15 | 15 | { |
| 16 | 16 | if (!empty($descriptor) && empty($descriptorSource)) { |
| 17 | - $message = "error decoding descriptor ".json_encode($descriptor).": {$errorMessage}"; |
|
| 17 | + $message = "error decoding descriptor " . json_encode($descriptor) . ": {$errorMessage}"; |
|
| 18 | 18 | } elseif (!empty($descriptor) && !empty($descriptorSource)) { |
| 19 | - $message = "error decoding descriptor from source ".json_encode($descriptorSource) |
|
| 20 | - ." - ".json_encode($descriptor).": {$errorMessage}"; |
|
| 19 | + $message = "error decoding descriptor from source " . json_encode($descriptorSource) |
|
| 20 | + ." - " . json_encode($descriptor) . ": {$errorMessage}"; |
|
| 21 | 21 | } elseif (empty($descriptor) && !empty($descriptorSource)) { |
| 22 | - $message = "error loading descriptor from source ".json_encode($descriptorSource) |
|
| 22 | + $message = "error loading descriptor from source " . json_encode($descriptorSource) |
|
| 23 | 23 | .": {$errorMessage}"; |
| 24 | 24 | } else { |
| 25 | 25 | $message = "unexpected load error: {$errorMessage}"; |
@@ -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)); |
@@ -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 |
@@ -1,7 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace frictionlessdata\tableschema; |
| 3 | 3 | use frictionlessdata\tableschema\Exceptions\DataSourceException; |
| 4 | -use frictionlessdata\tableschema\Fields\BaseField; |
|
| 5 | 4 | |
| 6 | 5 | /** |
| 7 | 6 | * represents a data source which validates against a table schema |
@@ -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 |
@@ -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 | } |