Completed
Push — master ( 0ce8a4...9a185e )
by Tim
9s
created

ExporterTrait   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 58
c 0
b 0
f 0
wmc 8
lcom 0
cbo 2
ccs 0
cts 27
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getExporterInstance() 0 4 1
C getExportConfig() 0 39 7
1
<?php
2
3
/**
4
 * TechDivision\Import\Utils\ExporterTrait
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\Utils;
22
23
use Goodby\CSV\Export\Standard\Exporter;
24
use Goodby\CSV\Export\Standard\ExporterConfig;
25
26
/**
27
 * The trait implementation for the exporter initialization functionality.
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
trait ExporterTrait
36
{
37
38
    /**
39
     * Initialize and return a new exporter instance.
40
     *
41
     * @return \Goodby\CSV\Export\Standard\Exporter The exporter instance
42
     */
43
    protected function getExporterInstance()
44
    {
45
        return new Exporter($this->getExportConfig());
46
    }
47
48
    /**
49
     * Initialize and return the exporter configuration.
50
     *
51
     * @return \Goodby\CSV\Export\Standard\ExporterConfig The exporter configuration
52
     */
53
    protected function getExportConfig()
54
    {
55
56
        // initialize the lexer configuration
57
        $config = new ExporterConfig();
58
59
        // query whether or not a delimiter character has been configured
60
        if ($delimiter = $this->getConfiguration()->getDelimiter()) {
0 ignored issues
show
Bug introduced by
It seems like getConfiguration() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
61
            $config->setDelimiter($delimiter);
62
        }
63
64
        // query whether or not a custom escape character has been configured
65
        if ($escape = $this->getConfiguration()->getEscape()) {
0 ignored issues
show
Bug introduced by
It seems like getConfiguration() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
66
            $config->setEscape($escape);
67
        }
68
69
        // query whether or not a custom enclosure character has been configured
70
        if ($enclosure = $this->getConfiguration()->getEnclosure()) {
0 ignored issues
show
Bug introduced by
It seems like getConfiguration() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
71
            $config->setEnclosure($enclosure);
72
        }
73
74
        // query whether or not a custom source charset has been configured
75
        if ($fromCharset = $this->getConfiguration()->getFromCharset()) {
0 ignored issues
show
Bug introduced by
It seems like getConfiguration() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
76
            $config->setFromCharset($fromCharset);
77
        }
78
79
        // query whether or not a custom target charset has been configured
80
        if ($toCharset = $this->getConfiguration()->getToCharset()) {
0 ignored issues
show
Bug introduced by
It seems like getConfiguration() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
81
            $config->setToCharset($toCharset);
82
        }
83
84
        // query whether or not a custom file mode has been configured
85
        if ($fileMode = $this->getConfiguration()->getFileMode()) {
0 ignored issues
show
Bug introduced by
It seems like getConfiguration() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
86
            $config->setFileMode($fileMode);
87
        }
88
89
        // return the lexer configuratio
90
        return $config;
91
    }
92
}
93