@@ -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 |
@@ -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) { |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | * @param null $descriptor optional descriptor object - will be used as an initial descriptor |
12 | 12 | * @param bool $lenient if true - infer just basic types, without strict format requirements |
13 | 13 | */ |
14 | - public function __construct($descriptor=null, $lenient=false) |
|
14 | + public function __construct($descriptor = null, $lenient = false) |
|
15 | 15 | { |
16 | 16 | $this->descriptor = empty($descriptor) ? (object)["fields" => []] : $descriptor; |
17 | 17 | $this->fieldsInferer = new Fields\FieldsInferrer(null, $lenient); |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | $this->descriptor->fields[] = $inferredField->descriptor(); |
45 | 45 | } |
46 | 46 | $this->castRows = $this->fieldsInferer->castRows(); |
47 | - return $this->castRows[count($this->castRows)-1]; |
|
47 | + return $this->castRows[count($this->castRows) - 1]; |
|
48 | 48 | } |
49 | 49 | } |
50 | 50 |
@@ -143,7 +143,9 @@ |
||
143 | 143 | $validationErrors = []; |
144 | 144 | foreach ($this->fields() as $fieldName => $field) { |
145 | 145 | $value = array_key_exists($fieldName, $row) ? $row[$fieldName] : null; |
146 | - if (in_array($value, $this->missingValues())) $value = null; |
|
146 | + if (in_array($value, $this->missingValues())) { |
|
147 | + $value = null; |
|
148 | + } |
|
147 | 149 | try { |
148 | 150 | $outRow[$fieldName] = $field->castValue($value); |
149 | 151 | } catch (Exceptions\FieldValidationException $e) { |
@@ -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 | } |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * @param bool @lenient |
92 | 92 | * @return bool|BaseField |
93 | 93 | */ |
94 | - public static function infer($val, $descriptor=null, $lenient=false) |
|
94 | + public static function infer($val, $descriptor = null, $lenient = false) |
|
95 | 95 | { |
96 | 96 | $field = new static($descriptor); |
97 | 97 | try { |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | * @param bool @lenient |
143 | 143 | * @return string |
144 | 144 | */ |
145 | - public function getInferIdentifier($lenient=false) |
|
145 | + public function getInferIdentifier($lenient = false) |
|
146 | 146 | { |
147 | 147 | return $this->type(); |
148 | 148 | } |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | protected $descriptor; |
160 | 160 | protected $constraintsDisabled = false; |
161 | 161 | |
162 | - protected function getValidationException($errorMsg, $val=null) |
|
162 | + protected function getValidationException($errorMsg, $val = null) |
|
163 | 163 | { |
164 | 164 | return new FieldValidationException([ |
165 | 165 | new SchemaValidationError(SchemaValidationError::FIELD_VALIDATION, [ |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | |
261 | 261 | protected function checkPatternConstraint($val, $pattern) |
262 | 262 | { |
263 | - return preg_match("/^".$pattern."\$/", $val) === 1; |
|
263 | + return preg_match("/^" . $pattern . "\$/", $val) === 1; |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | protected function checkMinimumConstraint($val, $minConstraint) |
@@ -118,7 +118,9 @@ |
||
118 | 118 | final public function castValue($val) |
119 | 119 | { |
120 | 120 | if ($this->isEmptyValue($val)) { |
121 | - if ($this->required()) throw $this->getValidationException("field is required", $val); |
|
121 | + if ($this->required()) { |
|
122 | + throw $this->getValidationException("field is required", $val); |
|
123 | + } |
|
122 | 124 | return null; |
123 | 125 | } else { |
124 | 126 | return $this->validateCastValue($val); |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | |
6 | 6 | class StringField extends BaseField |
7 | 7 | { |
8 | - public function inferProperties($val, $lenient=false) |
|
8 | + public function inferProperties($val, $lenient = false) |
|
9 | 9 | { |
10 | 10 | parent::inferProperties($val, $lenient); |
11 | 11 | if (!$lenient) { |
@@ -35,12 +35,12 @@ discard block |
||
35 | 35 | return "string"; |
36 | 36 | } |
37 | 37 | |
38 | - public function getInferIdentifier($lenient=false) |
|
38 | + public function getInferIdentifier($lenient = false) |
|
39 | 39 | { |
40 | 40 | $inferId = parent::getInferIdentifier(); |
41 | 41 | $format = $this->format(); |
42 | 42 | if (!$lenient && !empty($format)) { |
43 | - $inferId .= ":".$this->format(); |
|
43 | + $inferId .= ":" . $this->format(); |
|
44 | 44 | }; |
45 | 45 | return $inferId; |
46 | 46 | } |