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

CsvHandlerTrait::setUseSep()   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\Traits;
11
12
/**
13
 * Trait CsvHandlerTrait
14
 */
15
trait CsvHandlerTrait
16
{
17
    /**
18
     * @var array|null
19
     */
20
    protected $header;
21
22
    /**
23
     * @var string
24
     */
25
    protected $delimiter = ',';
26
27
    /**
28
     * @var string
29
     */
30
    protected $enclosure = '"';
31
32
    /**
33
     * use more widespread " as default escape char instead of default \
34
     *
35
     * @var string
36
     */
37
    protected $escape = '"';
38
39
    /**
40
     * @var bool
41
     */
42
    protected $useHeader = true;
43
44
    /**
45
     * @var bool
46
     */
47
    protected $useSep = false;
48
49
    /**
50
     * @return array|null
51
     */
52
    public function getHeader()
53
    {
54
        return $this->header;
55
    }
56
57
    /**
58
     * @param bool $useHeader
59
     *
60
     * @return $this
61
     */
62
    public function setUseHeader($useHeader)
63
    {
64
        $this->useHeader = (bool) $useHeader;
65
66
        return $this;
67
    }
68
69
    /**
70
     * @param bool $useSep
71
     *
72
     * @return $this
73
     */
74
    public function setUseSep($useSep)
75
    {
76
        $this->useSep = (bool) $useSep;
77
78
        return $this;
79
    }
80
81
    /**
82
     * @param string|null $delimiter
83
     * @param string|null $enclosure
84
     * @param string|null $escape
85
     *
86
     * @return $this
87
     */
88
    protected function initCsvOptions($delimiter = null, $enclosure = null, $escape = null)
89
    {
90
        foreach (['delimiter', 'enclosure', 'escape'] as $varName) {
91
            if ($$varName !== null) {
92
                $this->$varName = $$varName;
93
            }
94
        }
95
96
        return $this;
97
    }
98
}
99