@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | |
33 | 33 | public $pools; |
34 | 34 | const POOL_MAIN = 0; |
35 | - const POOL_DEBUG = 1; |
|
35 | + const POOL_DEBUG = 1; |
|
36 | 36 | const POOL_ROWS = 2; |
37 | 37 | |
38 | 38 | /** |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function setInput($file) |
71 | 71 | { |
72 | - if(!file_exists($file)) { |
|
72 | + if (!file_exists($file)) { |
|
73 | 73 | throw new InvalidArgumentException('File not found.'); |
74 | 74 | } |
75 | 75 | $this->input = $file; |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | */ |
93 | 93 | public function setRules($rules) |
94 | 94 | { |
95 | - if(!is_array($rules)) { |
|
95 | + if (!is_array($rules)) { |
|
96 | 96 | $rules = [$rules]; |
97 | 97 | } |
98 | 98 | |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | */ |
139 | 139 | public function addRules($new_rules) |
140 | 140 | { |
141 | - if(!is_array($new_rules)) { |
|
141 | + if (!is_array($new_rules)) { |
|
142 | 142 | throw new InvalidArgumentException('Parameter must be an array of Rules'); |
143 | 143 | } |
144 | 144 | |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | */ |
156 | 156 | public function clearRules() |
157 | 157 | { |
158 | - foreach($this->getRules() as $rule) { |
|
158 | + foreach ($this->getRules() as $rule) { |
|
159 | 159 | unset($rule); |
160 | 160 | } |
161 | 161 | unset($this->rules); |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | */ |
172 | 172 | public function skip($size = null) |
173 | 173 | { |
174 | - if(is_null($size)) { |
|
174 | + if (is_null($size)) { |
|
175 | 175 | $this->addRule(new SkipRule()); |
176 | 176 | } else { |
177 | 177 | $this->addRule(new SkipRule($size)); |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | */ |
199 | 199 | public function id($title, $size = null) |
200 | 200 | { |
201 | - if(is_null($size)) { |
|
201 | + if (is_null($size)) { |
|
202 | 202 | $this->addColumn(new IdColumn($title)); |
203 | 203 | } else { |
204 | 204 | $this->addColumn(new IdColumn($title, $size)); |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | */ |
215 | 215 | public function int($title, $size = null) |
216 | 216 | { |
217 | - if(is_null($size)) { |
|
217 | + if (is_null($size)) { |
|
218 | 218 | $this->addColumn(new IntColumn($title)); |
219 | 219 | } else { |
220 | 220 | $this->addColumn(new IntColumn($title, $size)); |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | */ |
231 | 231 | public function date($title, $size = null) |
232 | 232 | { |
233 | - if(is_null($size)) { |
|
233 | + if (is_null($size)) { |
|
234 | 234 | $this->addColumn(new DateColumn($title)); |
235 | 235 | } else { |
236 | 236 | $this->addColumn(new DateColumn($title, $size)); |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | */ |
247 | 247 | public function float($title, $size = null) |
248 | 248 | { |
249 | - if(is_null($size)) { |
|
249 | + if (is_null($size)) { |
|
250 | 250 | $this->addColumn(new FloatColumn($title)); |
251 | 251 | } else { |
252 | 252 | $this->addColumn(new FloatColumn($title, $size)); |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | */ |
263 | 263 | public function string($title, $size = null) |
264 | 264 | { |
265 | - if(is_null($size)) { |
|
265 | + if (is_null($size)) { |
|
266 | 266 | $this->addColumn(new StringColumn($title)); |
267 | 267 | } else { |
268 | 268 | $this->addColumn(new StringColumn($title, $size)); |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | public function setColumns() |
297 | 297 | { |
298 | 298 | $columns = array_filter($this->getRules(), function($rule) { |
299 | - if($rule instanceof ColumnInterface) { |
|
299 | + if ($rule instanceof ColumnInterface) { |
|
300 | 300 | return $rule; |
301 | 301 | } |
302 | 302 | }); |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | */ |
315 | 315 | public function getColumns() |
316 | 316 | { |
317 | - if($this->dirty) { |
|
317 | + if ($this->dirty) { |
|
318 | 318 | $this->setColumns(); |
319 | 319 | $this->dirty = false; |
320 | 320 | } |
@@ -337,10 +337,10 @@ discard block |
||
337 | 337 | */ |
338 | 338 | public function begin() |
339 | 339 | { |
340 | - $this->pointer = fopen($this->input,'rb'); |
|
340 | + $this->pointer = fopen($this->input, 'rb'); |
|
341 | 341 | $this->input_stats = fstat($this->getPointer()); |
342 | 342 | |
343 | - if(is_null($this->getPointer())) { |
|
343 | + if (is_null($this->getPointer())) { |
|
344 | 344 | throw new Exception('Couldnt create the pointer at input file.'); |
345 | 345 | } |
346 | 346 | |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | */ |
376 | 376 | public function hasPool($index) |
377 | 377 | { |
378 | - if(isset($this->pools[$index])) { |
|
378 | + if (isset($this->pools[$index])) { |
|
379 | 379 | return true; |
380 | 380 | } |
381 | 381 | return false; |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | */ |
389 | 389 | public function getPool($key) |
390 | 390 | { |
391 | - if($this->hasPool($key)) { |
|
391 | + if ($this->hasPool($key)) { |
|
392 | 392 | return $this->pools[$key]; |
393 | 393 | } |
394 | 394 | throw new InvalidArgumentException('Pool with key \''.$key.'\' was not registered.'); |
@@ -456,7 +456,7 @@ discard block |
||
456 | 456 | */ |
457 | 457 | protected function addElem($element) |
458 | 458 | { |
459 | - foreach($this->getPools() as $pool) { |
|
459 | + foreach ($this->getPools() as $pool) { |
|
460 | 460 | $pool->add($element); |
461 | 461 | } |
462 | 462 | return $this; |
@@ -468,7 +468,7 @@ discard block |
||
468 | 468 | */ |
469 | 469 | public function hasNext() |
470 | 470 | { |
471 | - if($this->position() == $this->inputLength() and feof($this->getPointer())) { |
|
471 | + if ($this->position() == $this->inputLength() and feof($this->getPointer())) { |
|
472 | 472 | return false; |
473 | 473 | } |
474 | 474 | return true; |
@@ -489,15 +489,15 @@ discard block |
||
489 | 489 | */ |
490 | 490 | public function next() |
491 | 491 | { |
492 | - if(!$this->hasNext()) { |
|
492 | + if (!$this->hasNext()) { |
|
493 | 493 | return null; |
494 | 494 | } |
495 | 495 | $size = $this->nextRecordLength(); |
496 | - if($size < 1) { |
|
496 | + if ($size < 1) { |
|
497 | 497 | return null; |
498 | 498 | } |
499 | 499 | $raw_content = $this->readBits($size); |
500 | - if(is_null($raw_content)) { |
|
500 | + if (is_null($raw_content)) { |
|
501 | 501 | return null; |
502 | 502 | } |
503 | 503 | $index = $this->applyRules($raw_content, $size); |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | */ |
511 | 511 | protected function readBits($n = 1) |
512 | 512 | { |
513 | - if($this->position() + $n >= $this->inputLength() and feof($this->getPointer())) { |
|
513 | + if ($this->position() + $n >= $this->inputLength() and feof($this->getPointer())) { |
|
514 | 514 | return null; |
515 | 515 | } |
516 | 516 | return fread($this->getPointer(), $n); |
@@ -545,14 +545,14 @@ discard block |
||
545 | 545 | |
546 | 546 | foreach ($this->getRules() as $rule) { |
547 | 547 | $column_content = substr($raw, $position, $rule->getLength()); |
548 | - if($rule instanceof ColumnInterface) { |
|
548 | + if ($rule instanceof ColumnInterface) { |
|
549 | 549 | $attributes[$rule->getTitle()] = $rule::cast($column_content); |
550 | 550 | } |
551 | 551 | $position += $rule->getLength(); |
552 | 552 | } |
553 | 553 | |
554 | - if($position < $size) { |
|
555 | - $column_content = Bin::toHex(substr($raw, $position, ($size-$position))); |
|
554 | + if ($position < $size) { |
|
555 | + $column_content = Bin::toHex(substr($raw, $position, ($size - $position))); |
|
556 | 556 | $column_content = preg_split('/(?<=2020)2020(?!2020])/', $column_content); |
557 | 557 | $column_content = Hex::toStr(end($column_content)); |
558 | 558 | $attributes[$this->getVariableColumnName()] = $column_content; |
@@ -569,7 +569,7 @@ discard block |
||
569 | 569 | */ |
570 | 570 | public function exists($index, $target_pool = self::POOL_MAIN) |
571 | 571 | { |
572 | - if($this->haspool($index)) { |
|
572 | + if ($this->haspool($index)) { |
|
573 | 573 | return $this->getPool($key)->exists($index); |
574 | 574 | } |
575 | 575 | throw new InvalidArgumentException('Invalid pool.'); |
@@ -583,7 +583,7 @@ discard block |
||
583 | 583 | */ |
584 | 584 | public function elem($index, $target_pool = self::POOL_MAIN) |
585 | 585 | { |
586 | - if($this->haspool($index)) { |
|
586 | + if ($this->haspool($index)) { |
|
587 | 587 | return $this->getPool($target_pool)->elem($index); |
588 | 588 | } else { |
589 | 589 | throw new InvalidArgumentException('Invalid pool.'); |
@@ -609,7 +609,7 @@ discard block |
||
609 | 609 | public function take($number_of_elements = 1) |
610 | 610 | { |
611 | 611 | $elements = []; |
612 | - while(($number_of_elements > 0) and $this->hasNext()) |
|
612 | + while (($number_of_elements > 0) and $this->hasNext()) |
|
613 | 613 | { |
614 | 614 | $temp = $this->next(); |
615 | 615 | $objects->push($temp); |
@@ -625,9 +625,9 @@ discard block |
||
625 | 625 | */ |
626 | 626 | public function all() { |
627 | 627 | $objects = [] |
628 | - while($this->hasNext()) { |
|
628 | + while ($this->hasNext()) { |
|
629 | 629 | $next = $this->next(); |
630 | - if($next == FALSE) break; |
|
630 | + if ($next == FALSE) break; |
|
631 | 631 | $objects->push($next); |
632 | 632 | } |
633 | 633 |
@@ -627,7 +627,9 @@ |
||
627 | 627 | $objects = [] |
628 | 628 | while($this->hasNext()) { |
629 | 629 | $next = $this->next(); |
630 | - if($next == FALSE) break; |
|
630 | + if($next == FALSE) { |
|
631 | + break; |
|
632 | + } |
|
631 | 633 | $objects->push($next); |
632 | 634 | } |
633 | 635 |
@@ -4,8 +4,8 @@ |
||
4 | 4 | |
5 | 5 | class Str |
6 | 6 | { |
7 | - public static function toUtf8($str) |
|
8 | - { |
|
9 | - return utf8_encode($str); |
|
10 | - } |
|
7 | + public static function toUtf8($str) |
|
8 | + { |
|
9 | + return utf8_encode($str); |
|
10 | + } |
|
11 | 11 | } |
@@ -4,13 +4,13 @@ |
||
4 | 4 | |
5 | 5 | class Hex |
6 | 6 | { |
7 | - public static function toStr($hex) |
|
8 | - { |
|
9 | - $str = ''; |
|
10 | - for ($i = 0; $i < strlen($hex); $i += 2) { |
|
11 | - $str .= chr(hexdec(substr($hex, $i, 2))); |
|
12 | - } |
|
7 | + public static function toStr($hex) |
|
8 | + { |
|
9 | + $str = ''; |
|
10 | + for ($i = 0; $i < strlen($hex); $i += 2) { |
|
11 | + $str .= chr(hexdec(substr($hex, $i, 2))); |
|
12 | + } |
|
13 | 13 | |
14 | - return $str; |
|
15 | - } |
|
14 | + return $str; |
|
15 | + } |
|
16 | 16 | } |
@@ -4,27 +4,27 @@ |
||
4 | 4 | |
5 | 5 | class Bin |
6 | 6 | { |
7 | - /** |
|
8 | - * Converts Binary to Hexadecimal. |
|
9 | - * |
|
10 | - * @param string $bin |
|
11 | - * |
|
12 | - * @return string |
|
13 | - */ |
|
14 | - public static function toHex($bin) |
|
15 | - { |
|
16 | - return bin2hex($bin); |
|
17 | - } |
|
7 | + /** |
|
8 | + * Converts Binary to Hexadecimal. |
|
9 | + * |
|
10 | + * @param string $bin |
|
11 | + * |
|
12 | + * @return string |
|
13 | + */ |
|
14 | + public static function toHex($bin) |
|
15 | + { |
|
16 | + return bin2hex($bin); |
|
17 | + } |
|
18 | 18 | |
19 | - /** |
|
20 | - * Converts Binary to ASCII. |
|
21 | - * |
|
22 | - * @param string $bin |
|
23 | - * |
|
24 | - * @return string |
|
25 | - */ |
|
26 | - public static function toStr($bin) |
|
27 | - { |
|
28 | - return Hex::toStr(self::toHex($bin)); |
|
29 | - } |
|
19 | + /** |
|
20 | + * Converts Binary to ASCII. |
|
21 | + * |
|
22 | + * @param string $bin |
|
23 | + * |
|
24 | + * @return string |
|
25 | + */ |
|
26 | + public static function toStr($bin) |
|
27 | + { |
|
28 | + return Hex::toStr(self::toHex($bin)); |
|
29 | + } |
|
30 | 30 | } |
@@ -4,17 +4,17 @@ |
||
4 | 4 | |
5 | 5 | class IntColumn extends ColumnRule implements ColumnInterface |
6 | 6 | { |
7 | - const DEFAULT_LENGTH = 2; |
|
7 | + const DEFAULT_LENGTH = 2; |
|
8 | 8 | |
9 | - public function __construct($title, $length = self::DEFAULT_LENGTH) |
|
10 | - { |
|
11 | - $this->setTitle($title); |
|
12 | - $this->setType(self::TYPE_INT); |
|
13 | - $this->setLength($length); |
|
14 | - } |
|
9 | + public function __construct($title, $length = self::DEFAULT_LENGTH) |
|
10 | + { |
|
11 | + $this->setTitle($title); |
|
12 | + $this->setType(self::TYPE_INT); |
|
13 | + $this->setLength($length); |
|
14 | + } |
|
15 | 15 | |
16 | - public static function cast($content) |
|
17 | - { |
|
18 | - return intval($content); |
|
19 | - } |
|
16 | + public static function cast($content) |
|
17 | + { |
|
18 | + return intval($content); |
|
19 | + } |
|
20 | 20 | } |
@@ -6,24 +6,24 @@ |
||
6 | 6 | |
7 | 7 | class IdColumn extends ColumnRule implements ColumnInterface |
8 | 8 | { |
9 | - const DEFAULT_LENGTH = 1; |
|
9 | + const DEFAULT_LENGTH = 1; |
|
10 | 10 | |
11 | - public function __construct($title, $length = self::DEFAULT_LENGTH) |
|
12 | - { |
|
13 | - $this->setTitle($title); |
|
14 | - $this->setType(self::TYPE_ID); |
|
15 | - $this->setLength($length); |
|
16 | - } |
|
11 | + public function __construct($title, $length = self::DEFAULT_LENGTH) |
|
12 | + { |
|
13 | + $this->setTitle($title); |
|
14 | + $this->setType(self::TYPE_ID); |
|
15 | + $this->setLength($length); |
|
16 | + } |
|
17 | 17 | |
18 | - public static function cast($content) |
|
19 | - { |
|
20 | - $content = str_split(Bin::toHex($content), 2); |
|
18 | + public static function cast($content) |
|
19 | + { |
|
20 | + $content = str_split(Bin::toHex($content), 2); |
|
21 | 21 | |
22 | - $id = 0; |
|
23 | - foreach ($content as $power => $value) { |
|
24 | - $id += hexdec($value) * pow(256, $power); |
|
25 | - } |
|
22 | + $id = 0; |
|
23 | + foreach ($content as $power => $value) { |
|
24 | + $id += hexdec($value) * pow(256, $power); |
|
25 | + } |
|
26 | 26 | |
27 | - return intval($id); |
|
28 | - } |
|
27 | + return intval($id); |
|
28 | + } |
|
29 | 29 | } |
@@ -4,5 +4,5 @@ |
||
4 | 4 | |
5 | 5 | interface ColumnInterface |
6 | 6 | { |
7 | - public static function cast($content); |
|
7 | + public static function cast($content); |
|
8 | 8 | } |
@@ -7,39 +7,39 @@ |
||
7 | 7 | |
8 | 8 | class ColumnRule extends Rule implements RuleInterface |
9 | 9 | { |
10 | - const TYPE_DATE = 0; |
|
11 | - const TYPE_FLOAT = 1; |
|
12 | - const TYPE_ID = 2; |
|
13 | - const TYPE_INT = 3; |
|
14 | - const TYPE_STRING = 4; |
|
15 | - |
|
16 | - protected $title; |
|
17 | - protected $type; |
|
18 | - |
|
19 | - public function __construct($title, $type, $length) |
|
20 | - { |
|
21 | - $this->setTitle($title); |
|
22 | - $this->setType($type); |
|
23 | - $this->setLength($length); |
|
24 | - } |
|
25 | - |
|
26 | - public function setTitle($title) |
|
27 | - { |
|
28 | - $this->title = $title; |
|
29 | - } |
|
30 | - |
|
31 | - public function getTitle() |
|
32 | - { |
|
33 | - return $this->title; |
|
34 | - } |
|
35 | - |
|
36 | - public function setType($type) |
|
37 | - { |
|
38 | - $this->type = $type; |
|
39 | - } |
|
40 | - |
|
41 | - public function getType() |
|
42 | - { |
|
43 | - return $this->type; |
|
44 | - } |
|
10 | + const TYPE_DATE = 0; |
|
11 | + const TYPE_FLOAT = 1; |
|
12 | + const TYPE_ID = 2; |
|
13 | + const TYPE_INT = 3; |
|
14 | + const TYPE_STRING = 4; |
|
15 | + |
|
16 | + protected $title; |
|
17 | + protected $type; |
|
18 | + |
|
19 | + public function __construct($title, $type, $length) |
|
20 | + { |
|
21 | + $this->setTitle($title); |
|
22 | + $this->setType($type); |
|
23 | + $this->setLength($length); |
|
24 | + } |
|
25 | + |
|
26 | + public function setTitle($title) |
|
27 | + { |
|
28 | + $this->title = $title; |
|
29 | + } |
|
30 | + |
|
31 | + public function getTitle() |
|
32 | + { |
|
33 | + return $this->title; |
|
34 | + } |
|
35 | + |
|
36 | + public function setType($type) |
|
37 | + { |
|
38 | + $this->type = $type; |
|
39 | + } |
|
40 | + |
|
41 | + public function getType() |
|
42 | + { |
|
43 | + return $this->type; |
|
44 | + } |
|
45 | 45 | } |
@@ -8,39 +8,39 @@ |
||
8 | 8 | |
9 | 9 | class DateColumn extends ColumnRule implements ColumnInterface |
10 | 10 | { |
11 | - const DEFAULT_LENGTH = 8; |
|
12 | - |
|
13 | - public function __construct($title, $length = self::DEFAULT_LENGTH) |
|
14 | - { |
|
15 | - $this->setTitle($title); |
|
16 | - $this->setType(self::TYPE_DATE); |
|
17 | - $this->setLength($length); |
|
18 | - } |
|
19 | - |
|
20 | - public static function cast($content) |
|
21 | - { |
|
22 | - if (self::validate($content)) { |
|
23 | - return; |
|
24 | - } |
|
25 | - |
|
26 | - $content = Hex::toStr($content); |
|
27 | - |
|
28 | - try { |
|
29 | - $content = DateTime::createFromFormat('Ymd', $content); |
|
30 | - $content->setTime(0, 0, 0); |
|
31 | - } catch (Exception $e) { |
|
32 | - $content = null; |
|
33 | - } |
|
34 | - |
|
35 | - return $content; |
|
36 | - } |
|
37 | - |
|
38 | - public static function validate($content) |
|
39 | - { |
|
40 | - if (intval($content) == 0 or strlen($content) < 8 or $content == '2020202020202020') { |
|
41 | - return false; |
|
42 | - } |
|
43 | - |
|
44 | - return true; |
|
45 | - } |
|
11 | + const DEFAULT_LENGTH = 8; |
|
12 | + |
|
13 | + public function __construct($title, $length = self::DEFAULT_LENGTH) |
|
14 | + { |
|
15 | + $this->setTitle($title); |
|
16 | + $this->setType(self::TYPE_DATE); |
|
17 | + $this->setLength($length); |
|
18 | + } |
|
19 | + |
|
20 | + public static function cast($content) |
|
21 | + { |
|
22 | + if (self::validate($content)) { |
|
23 | + return; |
|
24 | + } |
|
25 | + |
|
26 | + $content = Hex::toStr($content); |
|
27 | + |
|
28 | + try { |
|
29 | + $content = DateTime::createFromFormat('Ymd', $content); |
|
30 | + $content->setTime(0, 0, 0); |
|
31 | + } catch (Exception $e) { |
|
32 | + $content = null; |
|
33 | + } |
|
34 | + |
|
35 | + return $content; |
|
36 | + } |
|
37 | + |
|
38 | + public static function validate($content) |
|
39 | + { |
|
40 | + if (intval($content) == 0 or strlen($content) < 8 or $content == '2020202020202020') { |
|
41 | + return false; |
|
42 | + } |
|
43 | + |
|
44 | + return true; |
|
45 | + } |
|
46 | 46 | } |