Completed
Push — master ( fd8695...cb1565 )
by Tim
20s queued 11s
created

GenericIndexedColumnCollectorObserver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 54
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 1
A getPrimaryKeyColumn() 0 4 1
A getPrimaryKey() 0 4 1
1
<?php
2
3
/**
4
 * TechDivision\Import\Observers\GenericIndexedColumnCollectorObserver
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 2021 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\Observers;
22
23
use TechDivision\Import\Utils\ColumnKeys;
24
use TechDivision\Import\Loaders\LoaderInterface;
25
use TechDivision\Import\Services\RegistryProcessorInterface;
26
27
/**
28
 * Observer that loads the data of a set of configurable columns
29
 * into the registry for further processing, e. g. validation.
30
 *
31
 * As index the column name and the value of the configurable
32
 * primary key column will be used. This makes it possible to
33
 * access the collected data later on with this primary key,
34
 * for example you want to know the frontend input type of the
35
 * attribute with the attribute code that has been configured
36
 * as primary key column.
37
 *
38
 * @author    Tim Wagner <[email protected]>
39
 * @copyright 2021 TechDivision GmbH <[email protected]>
40
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
41
 * @link      https://github.com/techdivision/import
42
 * @link      http://www.techdivision.com
43
 */
44
class GenericIndexedColumnCollectorObserver extends AbstractColumnCollectorObserver
45
{
46
47
    /**
48
     * The column name that contains the primary key of the entity we want to process.
49
     *
50
     * @var string
51
     */
52
    private $primaryKeyColumn;
53
54
    /**
55
     * Initializes the callback with the loader instance.
56
     *
57
     * @param \TechDivision\Import\Loaders\LoaderInterface             $loader            The loader for the validations
58
     * @param \TechDivision\Import\Services\RegistryProcessorInterface $registryProcessor The registry processor instance
59
     * @param boolean                                                  $mainRowOnly       The flag to decide whether or not only values of the main row has to be collected
60
     * @param string                                                   $primaryKeyColumn  The column that provides the primary key
61
     */
62
    public function __construct(
63
        LoaderInterface $loader,
64
        RegistryProcessorInterface $registryProcessor,
65
        bool $mainRowOnly = false,
66
        string $primaryKeyColumn = ColumnKeys::ATTRIBUTE_CODE
67
    ) {
68
69
        // initialize the primary key column, by default
70
        // we use the column `attribute_code`
71
        $this->primaryKeyColumn = $primaryKeyColumn;
72
73
        // pass the loader,the registry processor and
74
        // the main row flag to the parent instance
75
        parent::__construct($loader, $registryProcessor, $mainRowOnly);
76
    }
77
78
    /**
79
     * Return's the configured primary key column.
80
     *
81
     * @return string
82
     */
83
    protected function getPrimaryKeyColumn() : string
84
    {
85
        return $this->primaryKeyColumn;
86
    }
87
88
    /**
89
     * Return's the primary key value that will be used as second incdex.
90
     *
91
     * @return string The primary key to be used
92
     */
93
    protected function getPrimaryKey() : string
94
    {
95
        return $this->getValue($this->getPrimaryKeyColumn());
96
    }
97
}
98