Passed
Push — master ( bb35d3...bc1c68 )
by Fabrice
03:52
created

FileExtractorAbstract::__destruct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 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
     * @var string
26
     */
27
    protected $srcFile;
28
29
    /**
30
     * @param resource|string $input
31
     *
32
     * @throws YaEtlException
33
     * @throws NodalFlowException
34
     */
35
    public function __construct($input)
36
    {
37
        if (is_resource($input)) {
38
            $this->handle = $input;
39
        } elseif (is_file($input)) {
40
            $this->srcFile = $input;
41
        } else {
42
            throw new YaEtlException('Input is either not a resource or not a file');
43
        }
44
45
        parent::__construct();
46
    }
47
48
    /**
49
     * @param mixed $param
50
     *
51
     * @return bool
52
     */
53
    public function extract($param = null)
54
    {
55
        if ($this->srcFile !== null) {
56
            $this->handle = fopen($this->srcFile, 'rb');
57
        }
58
59
        if (!is_resource($this->handle)) {
60
            return false;
61
        }
62
63
        $this->getCarrier()->getFlowMap()->incrementNode($this->getId(), 'num_extract');
64
65
        return rewind($this->handle);
66
    }
67
}
68