Passed
Branch feature/logging (0a7796)
by Daniel
01:58
created

Csv::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
/**
4
 * This file is part of the Csv-Machine package.
5
 *
6
 * (c) Dan McAdams <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace RoadBunch\Csv;
13
14
use Psr\Log\LoggerInterface;
15
use Psr\Log\NullLogger;
16
17
/**
18
 * Class Csv
19
 *
20
 * @author  Dan McAdams
21
 * @package RoadBunch\Csv
22
 */
23
abstract class Csv implements CsvInterface
24
{
25
    protected $delimiter = Delimiter::DELIMITER_COMMA;
26
    protected $enclosure = Enclosure::ENCLOSURE_DOUBLE_QUOTE;
27
    protected $newline   = Newline::NEWLINE_LF;
28
    protected $escape    = Escape::ESCAPE_CHAR;
29
30
    /** @var LoggerInterface */
31
    protected $logger;
32
33
    /**
34
     * Csv constructor.
35
     * @param LoggerInterface|null $logger
36
     */
37 13
    public function __construct(LoggerInterface $logger = null)
38
    {
39 13
        $this->logger = $logger;
40 13
        $this->logger = null !== $logger ? $logger : new NullLogger();
41 13
    }
42
43
    /**
44
     * @param string $delimiter
45
     */
46 1
    public function setDelimiter(string $delimiter)
47
    {
48 1
        $this->delimiter = $delimiter;
49 1
        $this->logger->info('Delimiter character set ' . json_encode($delimiter));
50 1
    }
51
52
    /**
53
     * @param string $enclosure
54
     */
55 1
    public function setEnclosure(string $enclosure)
56
    {
57 1
        $this->enclosure = $enclosure;
58 1
        $this->logger->info('Enclosure character set ' . json_encode($enclosure));
59 1
    }
60
61
    /**
62
     * @param string $newline
63
     */
64 2
    public function setNewline(string $newline)
65
    {
66 2
        $this->newline = $newline;
67 2
        $this->logger->info('Newline character set ' . json_encode($newline));
68 2
    }
69
70
    /**
71
     * @param string $escape
72
     */
73 1
    public function setEscape(string $escape)
74
    {
75 1
        $this->escape = $escape;
76 1
        $this->logger->info('Escape character set ' . json_encode($escape));
77 1
    }
78
}
79