Passed
Push — master ( bf91e1...52cffa )
by Fabrice
02:32
created

FileExtractorAbstract::getNextNonEmptyLine()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 0
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of YaEtl.
5
 *     (c) Fabrice de Stefanis / https://github.com/fab2s/YaEtl
6
 * This source file is licensed under the MIT license which you will
7
 * find in the LICENSE file or at https://opensource.org/licenses/MIT
8
 */
9
10
namespace fab2s\YaEtl\Extractors\File;
11
12
use fab2s\NodalFlow\NodalFlowException;
13
use fab2s\NodalFlow\YaEtlException;
14
use fab2s\YaEtl\Extractors\ExtractorAbstract;
15
use fab2s\YaEtl\Traits\FileHandlerTrait;
16
17
/**
18
 * Class FileExtractorAbstract
19
 */
20
abstract class FileExtractorAbstract extends ExtractorAbstract
21
{
22
    use FileHandlerTrait;
23
24
    /**
25
     * @param resource|string $input
26
     *
27
     * @throws YaEtlException
28
     * @throws NodalFlowException
29
     */
30
    public function __construct($input)
31
    {
32
        $this->initHandle($input, 'rb');
33
34
        parent::__construct();
35
    }
36
37
    /**
38
     * @param mixed $param
39
     *
40
     * @return bool
41
     */
42
    public function extract($param = null)
43
    {
44
        $this->getCarrier()->getFlowMap()->incrementNode($this->getId(), 'num_extract');
45
46
        return !feof($this->handle);
47
    }
48
49
    /**
50
     * @return string|false
51
     */
52
    protected function getNextNonEmptyLine()
53
    {
54
        while (false !== ($line = fgets($this->handle))) {
55
            if ('' === ($line = trim($line))) {
56
                continue;
57
            }
58
59
            return $line;
60
        }
61
62
        return false;
63
    }
64
65
    /**
66
     * @return string|false
67
     */
68
    protected function getNextNonEmptyChars()
69
    {
70
        do {
71
            if (false === ($char = fread($this->handle, 1))) {
72
                return false;
73
            }
74
        } while (trim($char) === '');
75
76
        return $char;
77
    }
78
}
79