StreamReader::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 2
crap 1
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\Log\LoggerAwareInterface;
21
22
class StreamReader extends IteratorNode implements ReaderInterface, LoggerAwareInterface, IteratorNodeInterface
23
{
24
    use OptionalLoggerTrait;
25
26
    /**
27
     * @param resource        $stream
28
     * @param ParserInterface $parser
29
     */
30 11
    public function __construct($stream, ParserInterface $parser)
31
    {
32 11
        parent::__construct($parser->parse($stream));
33 11
    }
34
35
    /**
36
     * Returns a sequential array of all items
37
     *
38
     * The callable function will be applied to each Iterator item
39
     *
40
     * @param callable|null $callable a callable function
41
     *
42
     * @return array
43
     */
44 3
    public function fetchAll(callable $callable = null)
45
    {
46 3
        return iterator_to_array($this->fetch($callable));
47
    }
48
}
49