getSerializer()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
/**
4
 * TechDivision\Import\Converter\Observers\AbstractSerializerAwareConverterObserver
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 2019 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-converter
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Converter\Observers;
22
23
use TechDivision\Import\Subjects\SubjectInterface;
24
use TechDivision\Import\Observers\ObserverFactoryInterface;
25
use TechDivision\Import\Serializers\SerializerInterface;
26
use TechDivision\Import\Serializers\SerializerAwareInterface;
27
use TechDivision\Import\Serializers\ConfigurationAwareSerializerFactoryInterface;
28
29
/**
30
 * Abstract import converter implementation that contains a customer serializer.
31
 *
32
 * @author    Tim Wagner <[email protected]>
33
 * @copyright 2019 TechDivision GmbH <[email protected]>
34
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
35
 * @link      https://github.com/techdivision/import-converter
36
 * @link      http://www.techdivision.com
37
 */
38
abstract class AbstractSerializerAwareConverterObserver extends AbstractConverterObserver implements SerializerAwareInterface, ObserverFactoryInterface
39
{
40
41
    /**
42
     * The custom serializer instance to use.
43
     *
44
     * @var \TechDivision\Import\Serializers\SerializerInterface
45
     */
46
    protected $serializer;
47
48
    /**
49
     * The serializer factory to use.
50
     *
51
     * @var \TechDivision\Import\Serializers\ConfigurationAwareSerializerFactoryInterface
52
     */
53
    protected $serializerFactory;
54
55
    /**
56
     * The constructor to initialize the instance.
57
     *
58
     * @param \TechDivision\Import\Serializers\ConfigurationAwareSerializerFactoryInterface $serializerFactory The serializer factory instance
59
     */
60 1
    public function __construct(ConfigurationAwareSerializerFactoryInterface $serializerFactory)
61
    {
62 1
        $this->serializerFactory = $serializerFactory;
63 1
    }
64
65
    /**
66
     * Will be invoked by the observer visitor when a factory has been defined to create the observer instance.
67
     *
68
     * @param \TechDivision\Import\Subjects\SubjectInterface $subject The subject instance
69
     *
70
     * @return \TechDivision\Import\Observers\ObserverInterface The observer instance
71
     */
72 1
    public function createObserver(SubjectInterface $subject)
73
    {
74
75
        // initialize the serializer with the default serializer configuration from the passed subject
76 1
        $this->setSerializer($this->serializerFactory->createSerializer($subject->getImportAdapter()->getSerializer()->getCsvConfiguration()));
77
78
        // return the instance
79 1
        return $this;
80
    }
81
82
    /**
83
     * Sets the serializer instance.
84
     *
85
     * @param \TechDivision\Import\Serializers\SerializerInterface $serializer The serializer instance
86
     *
87
     * @return void
88
     */
89 1
    public function setSerializer(SerializerInterface $serializer)
90
    {
91 1
        $this->serializer = $serializer;
92 1
    }
93
94
    /**
95
     * Returns the serializer instance.
96
     *
97
     * @return \TechDivision\Import\Serializers\SerializerInterface The serializer instance
98
     */
99 1
    public function getSerializer()
100
    {
101 1
        return $this->serializer;
102
    }
103
}
104