Passed
Push — master ( a0f654...53c07a )
by Fabrice
02:26
created

FileExtractorAbstract::extract()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
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 rewind($this->handle);
47
    }
48
49
    /**
50
     * @param bool $lookUpBom
51
     *
52
     * @return string|bool
53
     */
54
    protected function getNextNonEmptyLine($lookUpBom = false)
55
    {
56
        while (false !== ($line = fgets($this->handle))) {
57
            if ('' === ($line = trim($line))) {
58
                continue;
59
            }
60
61
            if ($lookUpBom) {
62
                $lookUpBom = false;
63
                if ('' === ($line = $this->readBom($line))) {
64
                    continue;
65
                }
66
            }
67
68
            return $line;
69
        }
70
71
        return false;
72
    }
73
}
74