Passed
Pull Request — master (#15)
by
unknown
03:40
created
src/Parsers/XMLParser.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
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
 
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 		return $this;
29 29
 	}
30 30
 
31
-	public function withoutSkippingFirstElement(){
31
+	public function withoutSkippingFirstElement() {
32 32
 		$this->skipFirstElement = false;
33 33
 
34 34
 		return $this;
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 	public function each(callable $function)
38 38
 	{
39 39
 		$this->start();
40
-		while($this->reader->read()){
40
+		while ($this->reader->read()) {
41 41
 			$this->searchElement($function);
42 42
 		}
43 43
 		$this->stop();
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 
46 46
 	private function searchElement(callable $function)
47 47
 	{
48
-		if($this->isElement() && ! $this->shouldBeSkipped()){
48
+		if ($this->isElement() && ! $this->shouldBeSkipped()) {
49 49
 			$function($this->extractElement($this->reader->name));
50 50
 		}
51 51
 	}
@@ -54,19 +54,19 @@  discard block
 block discarded – undo
54 54
 	{
55 55
 		$elementCollection = (new Collection())->merge($this->getCurrentElementAttributes());
56 56
 
57
-		while($this->reader->read()){
58
-			if($this->isEndElement($elementName)){
57
+		while ($this->reader->read()) {
58
+			if ($this->isEndElement($elementName)) {
59 59
 				break;
60 60
 			}
61
-			if($this->isValue()){
62
-				if($elementCollection->isEmpty()){
61
+			if ($this->isValue()) {
62
+				if ($elementCollection->isEmpty()) {
63 63
 					return trim($this->reader->value);
64 64
 				} else {
65 65
 					return $elementCollection->put($elementName, trim($this->reader->value));
66 66
 				}
67 67
 			}
68
-			if($this->isElement()){
69
-				if($couldBeAnElementsList){
68
+			if ($this->isElement()) {
69
+				if ($couldBeAnElementsList) {
70 70
 					$foundElementName = $this->reader->name;
71 71
 					$elementCollection->push(new Collection($this->extractElement($foundElementName)));
72 72
 				} else {
@@ -79,10 +79,10 @@  discard block
 block discarded – undo
79 79
 		return $elementCollection;
80 80
 	}
81 81
 
82
-	private function getCurrentElementAttributes(){
82
+	private function getCurrentElementAttributes() {
83 83
 		$attributes = new Collection();
84
-		if($this->reader->hasAttributes)  {
85
-			while($this->reader->moveToNextAttribute()) {
84
+		if ($this->reader->hasAttributes) {
85
+			while ($this->reader->moveToNextAttribute()) {
86 86
 				$attributes->put($this->reader->name, $this->reader->value);
87 87
 			}
88 88
 		}
@@ -99,13 +99,13 @@  discard block
 block discarded – undo
99 99
 
100 100
 	private function stop()
101 101
 	{
102
-		if( ! $this->reader->close()){
102
+		if ( ! $this->reader->close()) {
103 103
 			throw new IncompleteParseException();
104 104
 		}
105 105
 	}
106 106
 
107
-	private function shouldBeSkipped(){
108
-		if($this->skipFirstElement){
107
+	private function shouldBeSkipped() {
108
+		if ($this->skipFirstElement) {
109 109
 			$this->skipFirstElement = false;
110 110
 			return true;
111 111
 		}
@@ -113,23 +113,23 @@  discard block
 block discarded – undo
113 113
 		return false;
114 114
 	}
115 115
 
116
-	private function isElement(String $elementName = null){
117
-		if($elementName){
116
+	private function isElement(String $elementName = null) {
117
+		if ($elementName) {
118 118
 			return $this->reader->nodeType == XMLReader::ELEMENT && $this->reader->name === $elementName;
119 119
 		} else {
120 120
 			return $this->reader->nodeType == XMLReader::ELEMENT;
121 121
 		}
122 122
 	}
123 123
 
124
-	private function isEndElement(String $elementName = null){
125
-		if($elementName){
124
+	private function isEndElement(String $elementName = null) {
125
+		if ($elementName) {
126 126
 			return $this->reader->nodeType == XMLReader::END_ELEMENT && $this->reader->name === $elementName;
127 127
 		} else {
128 128
 			return $this->reader->nodeType == XMLReader::END_ELEMENT;
129 129
 		}
130 130
 	}
131 131
 
132
-	private function isValue(){
132
+	private function isValue() {
133 133
 		return $this->reader->nodeType == XMLReader::TEXT || $this->reader->nodeType === XMLReader::CDATA;
134 134
 	}
135 135
 }
Please login to merge, or discard this patch.
src/Services/JsonCollectionParser.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
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
 	}
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 	{
59 59
 		$stream = @fopen($filePath, 'r');
60 60
 		if (false === $stream) {
61
-			throw new \Exception('Unable to open file for read: ' . $filePath);
61
+			throw new \Exception('Unable to open file for read: '.$filePath);
62 62
 		}
63 63
 
64 64
 		return $stream;
Please login to merge, or discard this patch.
src/Parsers/CSVParser.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 {
18 18
 	protected $reader, $source, $headers, $currentLine;
19 19
 
20
-	public static $delimiters = [",", ";"];
20
+	public static $delimiters = [ ",", ";" ];
21 21
 	public static $skipsEmptyLines = true;
22 22
 
23 23
 	public function from(String $source): StreamParserInterface
@@ -30,8 +30,8 @@  discard block
 block discarded – undo
30 30
 	public function each(callable $function)
31 31
 	{
32 32
 		$this->start();
33
-		while($this->read()){
34
-			if($this->currentLineIsValid()){
33
+		while ($this->read()) {
34
+			if ($this->currentLineIsValid()) {
35 35
 				$function($this->getCurrentLineAsCollection());
36 36
 			}
37 37
 		}
@@ -48,8 +48,8 @@  discard block
 block discarded – undo
48 48
 		return $this;
49 49
 	}
50 50
 
51
-	private function close(){
52
-		if( ! fclose($this->reader)){
51
+	private function close() {
52
+		if ( ! fclose($this->reader)) {
53 53
 			throw new IncompleteParseException();
54 54
 		}
55 55
 	}
@@ -62,20 +62,20 @@  discard block
 block discarded – undo
62 62
 	}
63 63
 
64 64
 	private function currentLineIsValid(): bool{
65
-		if(static::$skipsEmptyLines){
65
+		if (static::$skipsEmptyLines) {
66 66
 			return ! $this->currentLineIsEmpty();
67 67
 		}
68 68
 
69 69
 		return true;
70 70
 	}
71 71
 
72
-	private function currentLineIsEmpty(){
73
-		return $this->currentLine->reject(function($value){
72
+	private function currentLineIsEmpty() {
73
+		return $this->currentLine->reject(function($value) {
74 74
 			return $this->isEmptyValue($value);
75 75
 		})->isEmpty();
76 76
 	}
77 77
 
78
-	private function isEmptyValue($value){
78
+	private function isEmptyValue($value) {
79 79
 		return $value === "" || $value === null;
80 80
 	}
81 81
 
@@ -86,25 +86,25 @@  discard block
 block discarded – undo
86 86
 
87 87
 		return $headers->intersectByKeys($this->currentLine)
88 88
 			->combine($values->recursive())
89
-			->reject(function($value){
89
+			->reject(function($value) {
90 90
 				return $this->isEmptyValue($value);
91 91
 			});
92 92
 	}
93 93
 
94
-	private function formatCurrentLineValues(Collection $collection){
94
+	private function formatCurrentLineValues(Collection $collection) {
95 95
 		$this->explodeCollectionValues($collection);
96 96
 		return $collection;
97 97
 	}
98 98
 
99
-	private function explodeCollectionValues(Collection $collection){
100
-		$collection->transform(function($value){
99
+	private function explodeCollectionValues(Collection $collection) {
100
+		$collection->transform(function($value) {
101 101
 			(new Collection(static::$delimiters))->each(function($delimiter) use (&$value){
102
-				if( ! is_array($value) && strpos($value, $delimiter) !== false){
102
+				if ( ! is_array($value) && strpos($value, $delimiter) !== false) {
103 103
 					$value = explode($delimiter, $value);
104 104
 				}
105 105
 			});
106
-			if(is_array($value)){
107
-				return (new Collection($value))->reject(function($value){
106
+			if (is_array($value)) {
107
+				return (new Collection($value))->reject(function($value) {
108 108
 					return $this->isEmptyValue($value);
109 109
 				});
110 110
 			} else {
Please login to merge, or discard this patch.
src/Extensions/ChunkExtension.php 2 patches
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -13,87 +13,87 @@
 block discarded – undo
13 13
  */
14 14
 class ChunkExtension implements \Rodenastyle\StreamParser\StreamParserInterface
15 15
 {
16
-    const DEFAULT_CHUNK_SIZE = 5000;
16
+	const DEFAULT_CHUNK_SIZE = 5000;
17 17
 
18
-    /**
19
-     * @var \Rodenastyle\StreamParser\StreamParserInterface
20
-     */
21
-    private $parser;
22
-    private $iterationCount = 0;
23
-    private $chunkSize;
24
-    /** @var  callable $onChunkCompleteCallback */
25
-    private $onChunkCompleteCallback;
18
+	/**
19
+	 * @var \Rodenastyle\StreamParser\StreamParserInterface
20
+	 */
21
+	private $parser;
22
+	private $iterationCount = 0;
23
+	private $chunkSize;
24
+	/** @var  callable $onChunkCompleteCallback */
25
+	private $onChunkCompleteCallback;
26 26
 
27
-    public function __construct(\Rodenastyle\StreamParser\StreamParserInterface $parser, $chunkSize = self::DEFAULT_CHUNK_SIZE)
28
-    {
29
-        $this->parser = $parser;
30
-        $this->chunkSize = $chunkSize;
31
-    }
27
+	public function __construct(\Rodenastyle\StreamParser\StreamParserInterface $parser, $chunkSize = self::DEFAULT_CHUNK_SIZE)
28
+	{
29
+		$this->parser = $parser;
30
+		$this->chunkSize = $chunkSize;
31
+	}
32 32
 
33
-    public function from(String $source): \Rodenastyle\StreamParser\StreamParserInterface
34
-    {
35
-        return $this->parser->from($source);
36
-    }
33
+	public function from(String $source): \Rodenastyle\StreamParser\StreamParserInterface
34
+	{
35
+		return $this->parser->from($source);
36
+	}
37 37
 
38
-    public function eachChunk(callable $function): StreamParserInterface
39
-    {
40
-        $this->onChunkCompleteCallback = $function;
41
-        return $this;
42
-    }
38
+	public function eachChunk(callable $function): StreamParserInterface
39
+	{
40
+		$this->onChunkCompleteCallback = $function;
41
+		return $this;
42
+	}
43 43
 
44
-    public function each(callable $function)
45
-    {
46
-        if ($this->onChunkCompleteCallback === null) {
47
-            throw new UndefinedCallbackException("No callback is set on chunk complete");
48
-        }
49
-        // decorate function to apply both its behavior and the chunk process
50
-        $function = function ($collection) use ($function) {
51
-            $this->iterationCount++;
52
-            $function($collection);
44
+	public function each(callable $function)
45
+	{
46
+		if ($this->onChunkCompleteCallback === null) {
47
+			throw new UndefinedCallbackException("No callback is set on chunk complete");
48
+		}
49
+		// decorate function to apply both its behavior and the chunk process
50
+		$function = function ($collection) use ($function) {
51
+			$this->iterationCount++;
52
+			$function($collection);
53 53
 
54
-            if ($this->iterationCount % $this->chunkSize === 0) {
55
-                $this->executeChunkCompleteCallback();
56
-            }
57
-        };
58
-        $this->parser->each($function);
54
+			if ($this->iterationCount % $this->chunkSize === 0) {
55
+				$this->executeChunkCompleteCallback();
56
+			}
57
+		};
58
+		$this->parser->each($function);
59 59
 
60
-        // make sure no entry is left out
61
-        $this->processLastEntries();
62
-        return $this;
63
-    }
60
+		// make sure no entry is left out
61
+		$this->processLastEntries();
62
+		return $this;
63
+	}
64 64
 
65
-    /**
66
-     * @param $this
67
-     */
68
-    protected function executeChunkCompleteCallback()
69
-    {
70
-        $this->iterationCount = 0;
71
-        ($this->onChunkCompleteCallback)();
72
-    }
65
+	/**
66
+	 * @param $this
67
+	 */
68
+	protected function executeChunkCompleteCallback()
69
+	{
70
+		$this->iterationCount = 0;
71
+		($this->onChunkCompleteCallback)();
72
+	}
73 73
 
74
-    protected function processLastEntries()
75
-    {
76
-        if ($this->iterationCount % $this->chunkSize !== 0) {
77
-            $this->executeChunkCompleteCallback();
78
-        }
79
-    }
74
+	protected function processLastEntries()
75
+	{
76
+		if ($this->iterationCount % $this->chunkSize !== 0) {
77
+			$this->executeChunkCompleteCallback();
78
+		}
79
+	}
80 80
 
81 81
 
82
-    /**
83
-     * @param int $chunkSize
84
-     * @return ChunkExtension
85
-     */
86
-    public function setChunkSize(int $chunkSize): ChunkExtension
87
-    {
88
-        $this->chunkSize = $chunkSize;
89
-        return $this;
90
-    }
82
+	/**
83
+	 * @param int $chunkSize
84
+	 * @return ChunkExtension
85
+	 */
86
+	public function setChunkSize(int $chunkSize): ChunkExtension
87
+	{
88
+		$this->chunkSize = $chunkSize;
89
+		return $this;
90
+	}
91 91
 
92
-    /**
93
-     * @return \Rodenastyle\StreamParser\StreamParserInterface
94
-     */
95
-    public function getParser(): \Rodenastyle\StreamParser\StreamParserInterface
96
-    {
97
-        return $this->parser;
98
-    }
92
+	/**
93
+	 * @return \Rodenastyle\StreamParser\StreamParserInterface
94
+	 */
95
+	public function getParser(): \Rodenastyle\StreamParser\StreamParserInterface
96
+	{
97
+		return $this->parser;
98
+	}
99 99
 }
100 100
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@
 block discarded – undo
47 47
             throw new UndefinedCallbackException("No callback is set on chunk complete");
48 48
         }
49 49
         // decorate function to apply both its behavior and the chunk process
50
-        $function = function ($collection) use ($function) {
50
+        $function = function($collection) use ($function) {
51 51
             $this->iterationCount++;
52 52
             $function($collection);
53 53
 
Please login to merge, or discard this patch.
src/StreamParser.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -44,8 +44,8 @@
 block discarded – undo
44 44
 		return (new CSVParser())->from($source);
45 45
 	}
46 46
 
47
-    private function chunk(StreamParserInterface $parser)
48
-    {
49
-        return new ChunkExtension($parser);
47
+	private function chunk(StreamParserInterface $parser)
48
+	{
49
+		return new ChunkExtension($parser);
50 50
 	}
51 51
 }
52 52
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -22,8 +22,8 @@  discard block
 block discarded – undo
22 22
 
23 23
 	private function __construct()
24 24
 	{
25
-		Collection::macro('recursive', function () {
26
-			return $this->map(function ($value) {
25
+		Collection::macro('recursive', function() {
26
+			return $this->map(function($value) {
27 27
 				if (is_array($value) || is_object($value)) {
28 28
 					return (new Collection($value))->recursive();
29 29
 				}
@@ -32,15 +32,15 @@  discard block
 block discarded – undo
32 32
 		});
33 33
 	}
34 34
 
35
-	private function xml(String $source){
35
+	private function xml(String $source) {
36 36
 		return (new XMLParser())->from($source);
37 37
 	}
38 38
 
39
-	private function json(String $source){
39
+	private function json(String $source) {
40 40
 		return (new JSONParser())->from($source);
41 41
 	}
42 42
 
43
-	private function csv(String $source){
43
+	private function csv(String $source) {
44 44
 		return (new CSVParser())->from($source);
45 45
 	}
46 46
 
Please login to merge, or discard this patch.