@@ -13,87 +13,87 @@ |
||
| 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 |
@@ -47,7 +47,7 @@ |
||
| 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 | |
@@ -44,8 +44,8 @@ |
||
| 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 |
@@ -22,8 +22,8 @@ discard block |
||
| 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 |
||
| 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 | |