Completed
Push — master ( 6cd933...10e391 )
by Harry
03:44
created

StreamReader::fetch()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
crap 2
1
<?php
2
/**
3
 * This file is part of graze/data-file
4
 *
5
 * Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/data-file/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/data-file
12
 */
13
14
namespace Graze\DataFile\IO;
15
16
use Graze\DataFile\Format\Parser\ParserInterface;
17
use Graze\DataFile\Helper\OptionalLoggerTrait;
18
use Graze\DataNode\IteratorNode;
19
use Graze\DataNode\IteratorNodeInterface;
20
use Psr\Http\Message\StreamInterface;
21
use Psr\Log\LoggerAwareInterface;
22
23
class StreamReader extends IteratorNode implements ReaderInterface, LoggerAwareInterface, IteratorNodeInterface
24
{
25
    use OptionalLoggerTrait;
26
27
    /**
28
     * @param StreamInterface $stream
29
     * @param ParserInterface $parser
30
     */
31 11
    public function __construct(StreamInterface $stream, ParserInterface $parser)
32
    {
33 11
        parent::__construct($parser->parse($stream));
34 11
    }
35
36
    /**
37
     * Returns a sequential array of all items
38
     *
39
     * The callable function will be applied to each Iterator item
40
     *
41
     * @param callable|null $callable a callable function
42
     *
43
     * @return array
44
     */
45 3
    public function fetchAll(callable $callable = null)
46
    {
47 3
        return iterator_to_array($this->fetch($callable));
48
    }
49
}
50