@@ -15,15 +15,15 @@ |
||
15 | 15 | |
16 | 16 | class StreamParser |
17 | 17 | { |
18 | - public static function xml(String $source){ |
|
18 | + public static function xml(String $source) { |
|
19 | 19 | return (new XMLParser())->from($source); |
20 | 20 | } |
21 | 21 | |
22 | - public static function json(String $source){ |
|
22 | + public static function json(String $source) { |
|
23 | 23 | return (new JSONParser())->from($source); |
24 | 24 | } |
25 | 25 | |
26 | - public static function csv(String $source){ |
|
26 | + public static function csv(String $source) { |
|
27 | 27 | return (new CSVParser())->from($source); |
28 | 28 | } |
29 | 29 | } |
30 | 30 | \ No newline at end of file |
@@ -19,8 +19,8 @@ |
||
19 | 19 | |
20 | 20 | public function __construct() |
21 | 21 | { |
22 | - Collection::macro('recursive', function () { |
|
23 | - return $this->map(function ($value) { |
|
22 | + Collection::macro('recursive', function() { |
|
23 | + return $this->map(function($value) { |
|
24 | 24 | if (is_array($value) || is_object($value)) { |
25 | 25 | return (new Collection($value))->recursive(); |
26 | 26 | } |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | |
18 | 18 | class XMLParser implements StreamParserInterface |
19 | 19 | { |
20 | - protected $reader,$source; |
|
20 | + protected $reader, $source; |
|
21 | 21 | |
22 | 22 | protected $skipFirstElement = true; |
23 | 23 | |
@@ -31,19 +31,19 @@ discard block |
||
31 | 31 | public function each(callable $function) |
32 | 32 | { |
33 | 33 | $this->start(); |
34 | - while($this->reader->read()){ |
|
34 | + while ($this->reader->read()) { |
|
35 | 35 | $this->searchElement($function); |
36 | 36 | } |
37 | 37 | $this->stop(); |
38 | 38 | } |
39 | 39 | |
40 | - public function withoutSkippingFirstElement(){ |
|
40 | + public function withoutSkippingFirstElement() { |
|
41 | 41 | $this->skipFirstElement = false; |
42 | 42 | } |
43 | 43 | |
44 | 44 | private function searchElement(callable $function) |
45 | 45 | { |
46 | - if($this->isElement() && ! $this->shouldBeSkipped()){ |
|
46 | + if ($this->isElement() && ! $this->shouldBeSkipped()) { |
|
47 | 47 | $function($this->extractElement($this->reader->name)); |
48 | 48 | } |
49 | 49 | } |
@@ -52,15 +52,15 @@ discard block |
||
52 | 52 | { |
53 | 53 | $elementCollection = (new Collection())->merge($this->getCurrentElementAttributes()); |
54 | 54 | |
55 | - while($this->reader->read()){ |
|
56 | - if($this->isEndElement($elementName)){ |
|
55 | + while ($this->reader->read()) { |
|
56 | + if ($this->isEndElement($elementName)) { |
|
57 | 57 | break; |
58 | 58 | } |
59 | - if($this->isElement()){ |
|
59 | + if ($this->isElement()) { |
|
60 | 60 | $foundElementName = $this->reader->name; |
61 | 61 | $elementCollection->put($foundElementName, $this->extractElement($foundElementName)); |
62 | 62 | } |
63 | - if($this->isValue()){ |
|
63 | + if ($this->isValue()) { |
|
64 | 64 | $elementCollection = $this->reader->value; |
65 | 65 | } |
66 | 66 | } |
@@ -68,10 +68,10 @@ discard block |
||
68 | 68 | return $elementCollection; |
69 | 69 | } |
70 | 70 | |
71 | - private function getCurrentElementAttributes(){ |
|
71 | + private function getCurrentElementAttributes() { |
|
72 | 72 | $attributes = new Collection(); |
73 | - if($this->reader->hasAttributes) { |
|
74 | - while($this->reader->moveToNextAttribute()) { |
|
73 | + if ($this->reader->hasAttributes) { |
|
74 | + while ($this->reader->moveToNextAttribute()) { |
|
75 | 75 | $attributes->put($this->reader->name, $this->reader->value); |
76 | 76 | } |
77 | 77 | } |
@@ -88,13 +88,13 @@ discard block |
||
88 | 88 | |
89 | 89 | private function stop() |
90 | 90 | { |
91 | - if( ! $this->reader->close()){ |
|
91 | + if ( ! $this->reader->close()) { |
|
92 | 92 | throw new IncompleteParseException(); |
93 | 93 | } |
94 | 94 | } |
95 | 95 | |
96 | - private function shouldBeSkipped(){ |
|
97 | - if($this->skipFirstElement){ |
|
96 | + private function shouldBeSkipped() { |
|
97 | + if ($this->skipFirstElement) { |
|
98 | 98 | $this->skipFirstElement = false; |
99 | 99 | return true; |
100 | 100 | } |
@@ -102,23 +102,23 @@ discard block |
||
102 | 102 | return false; |
103 | 103 | } |
104 | 104 | |
105 | - private function isElement(String $elementName = null){ |
|
106 | - if($elementName){ |
|
105 | + private function isElement(String $elementName = null) { |
|
106 | + if ($elementName) { |
|
107 | 107 | return $this->reader->nodeType == XMLReader::ELEMENT && $this->reader->name === $elementName; |
108 | 108 | } else { |
109 | 109 | return $this->reader->nodeType == XMLReader::ELEMENT; |
110 | 110 | } |
111 | 111 | } |
112 | 112 | |
113 | - private function isEndElement(String $elementName = null){ |
|
114 | - if($elementName){ |
|
113 | + private function isEndElement(String $elementName = null) { |
|
114 | + if ($elementName) { |
|
115 | 115 | return $this->reader->nodeType == XMLReader::END_ELEMENT && $this->reader->name === $elementName; |
116 | 116 | } else { |
117 | 117 | return $this->reader->nodeType == XMLReader::END_ELEMENT; |
118 | 118 | } |
119 | 119 | } |
120 | 120 | |
121 | - private function isValue(){ |
|
121 | + private function isValue() { |
|
122 | 122 | return $this->reader->nodeType == XMLReader::CDATA || $this->reader->nodeType == XMLReader::TEXT; |
123 | 123 | } |
124 | 124 | } |
125 | 125 | \ No newline at end of file |
@@ -17,12 +17,12 @@ discard block |
||
17 | 17 | { |
18 | 18 | protected $reader, $source, $headers, $currentLine; |
19 | 19 | |
20 | - public static $delimiters = [",", ";"]; |
|
20 | + public static $delimiters = [ ",", ";" ]; |
|
21 | 21 | |
22 | 22 | public function __construct() |
23 | 23 | { |
24 | - Collection::macro('recursive', function () { |
|
25 | - return $this->map(function ($value) { |
|
24 | + Collection::macro('recursive', function() { |
|
25 | + return $this->map(function($value) { |
|
26 | 26 | if (is_array($value) || is_object($value)) { |
27 | 27 | return (new Collection($value))->recursive(); |
28 | 28 | } |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | public function each(callable $function) |
42 | 42 | { |
43 | 43 | $this->start(); |
44 | - while($this->read()){ |
|
44 | + while ($this->read()) { |
|
45 | 45 | $function($this->getCurrentLineAsCollection()); |
46 | 46 | } |
47 | 47 | $this->close(); |
@@ -57,8 +57,8 @@ discard block |
||
57 | 57 | return $this; |
58 | 58 | } |
59 | 59 | |
60 | - private function close(){ |
|
61 | - if( ! fclose($this->reader)){ |
|
60 | + private function close() { |
|
61 | + if ( ! fclose($this->reader)) { |
|
62 | 62 | throw new IncompleteParseException(); |
63 | 63 | } |
64 | 64 | } |
@@ -76,15 +76,15 @@ discard block |
||
76 | 76 | return $headers->intersectByKeys($this->currentLine)->combine($values->recursive()); |
77 | 77 | } |
78 | 78 | |
79 | - private function formatCurrentLineValues(Collection $collection){ |
|
79 | + private function formatCurrentLineValues(Collection $collection) { |
|
80 | 80 | $this->explodeCollectionValues($collection); |
81 | 81 | return $collection; |
82 | 82 | } |
83 | 83 | |
84 | - private function explodeCollectionValues(Collection $collection){ |
|
85 | - $collection->transform(function($value){ |
|
84 | + private function explodeCollectionValues(Collection $collection) { |
|
85 | + $collection->transform(function($value) { |
|
86 | 86 | collect(static::$delimiters)->each(function($delimiter) use (&$value){ |
87 | - if( ! is_array($value) && strpos($value, $delimiter) !== false){ |
|
87 | + if ( ! is_array($value) && strpos($value, $delimiter) !== false) { |
|
88 | 88 | $value = explode($delimiter, $value); |
89 | 89 | } |
90 | 90 | }); |
@@ -43,7 +43,7 @@ |
||
43 | 43 | throw $e; |
44 | 44 | } |
45 | 45 | |
46 | - if( ! fclose($stream)){ |
|
46 | + if ( ! fclose($stream)) { |
|
47 | 47 | throw new IncompleteParseException(); |
48 | 48 | } |
49 | 49 | } |