Completed
Pull Request — master (#81)
by Tim
04:12
created

LexerConfigFactory::createLexerConfig()   B

Complexity

Conditions 6
Paths 32

Size

Total Lines 34
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
dl 0
loc 34
ccs 0
cts 20
cp 0
rs 8.439
c 0
b 0
f 0
cc 6
eloc 13
nc 32
nop 0
crap 42
1
<?php
2
3
/**
4
 * TechDivision\Import\Adapter\Csv\LexerConfigFactory
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2016 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/techdivision/import
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Adapter\Csv;
22
23
use Goodby\CSV\Import\Standard\LexerConfig;
24
use TechDivision\Import\ConfigurationInterface;
25
26
/**
27
 * Factory implementation for a CSV lexer configuration.
28
 *
29
 * @author    Tim Wagner <[email protected]>
30
 * @copyright 2016 TechDivision GmbH <[email protected]>
31
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
32
 * @link      https://github.com/techdivision/import
33
 * @link      http://www.techdivision.com
34
 */
35
class LexerConfigFactory implements LexerConfigFactoryInterface
36
{
37
38
    /**
39
     * The configuration instance.
40
     *
41
     * @var \TechDivision\Import\Configuration\ConfigurationInterface
42
     */
43
    protected $configuration;
44
45
    /**
46
     * Initialize the adapter with the configuration.
47
     *
48
     * @param \TechDivision\Import\Configuration\ConfigurationInterface $configuration The configuration instance
49
     */
50
    public function __construct(ConfigurationInterface $configuration)
51
    {
52
        $this->configuration = $configuration;
0 ignored issues
show
Documentation Bug introduced by
It seems like $configuration of type object<TechDivision\Impo...ConfigurationInterface> is incompatible with the declared type object<TechDivision\Impo...ConfigurationInterface> of property $configuration.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
53
    }
54
55
    /**
56
     * Factory method to create a new lexer configuration instance.
57
     *
58
     * @return \Goodby\CSV\Import\Standard\LexerConfig The lexer configuration
59
     */
60
    public function createLexerConfig()
61
    {
62
63
        // initialize the lexer configuration
64
        $config = new LexerConfig();
65
66
        // query whether or not a delimiter character has been configured
67
        if ($delimiter = $this->configuration->getDelimiter()) {
68
            $config->setDelimiter($delimiter);
69
        }
70
71
        // query whether or not a custom escape character has been configured
72
        if ($escape = $this->configuration->getEscape()) {
73
            $config->setEscape($escape);
74
        }
75
76
        // query whether or not a custom enclosure character has been configured
77
        if ($enclosure = $this->configuration->getEnclosure()) {
78
            $config->setEnclosure($enclosure);
79
        }
80
81
        // query whether or not a custom source charset has been configured
82
        if ($fromCharset = $this->configuration->getFromCharset()) {
83
            $config->setFromCharset($fromCharset);
84
        }
85
86
        // query whether or not a custom target charset has been configured
87
        if ($toCharset = $this->configuration->getToCharset()) {
88
            $config->setToCharset($toCharset);
89
        }
90
91
        // return the lexer configuratio
92
        return $config;
93
    }
94
}
95