Passed
Pull Request — master (#23)
by
unknown
06:50
created

GlobalDataPlugin   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 11
c 1
b 0
f 0
dl 0
loc 48
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getCountryRegions() 0 3 1
A process() 0 14 1
1
<?php
2
3
/**
4
 * TechDivision\Import\Customer\Address\Plugins\GlobalDataPlugin
5
 *
6
 * PHP version 7
7
 *
8
 * @author    Stefan Jaroschek <[email protected]>
9
 * @copyright 2023 TechDivision GmbH <[email protected]>
10
 * @license   https://opensource.org/licenses/MIT
11
 * @link      https://github.com/techdivision/import
12
 * @link      http://www.techdivision.com
13
 */
14
declare(strict_types=1);
15
16
namespace TechDivision\Import\Customer\Address\Plugins;
17
18
use TechDivision\Import\ApplicationInterface;
19
use TechDivision\Import\Customer\Address\Services\CustomerAddressBunchProcessorInterface;
20
use TechDivision\Import\Plugins\AbstractPlugin;
21
use TechDivision\Import\Customer\Address\Utils\RegistryKeys;
22
23
/**
24
 * Plugin that loads the global data.
25
 *
26
 * @author    MET  <[email protected]>
27
 * @copyright 2023 TechDivision GmbH <[email protected]>
28
 * @license   https://opensource.org/licenses/MIT
29
 * @link      https://github.com/techdivision/import
30
 * @link      http://www.techdivision.com
31
 */
32
class GlobalDataPlugin extends AbstractPlugin
33
{
34
    /**
35
     * @var CustomerAddressBunchProcessorInterface
36
     */
37
    protected $customerAddressBunchProcessor;
38
39
    /**
40
     * @param ApplicationInterface $application
41
     * @param CustomerAddressBunchProcessorInterface $customerAddressBunchProcessor
42
     */
43
    public function __construct(
44
        ApplicationInterface $application,
45
        CustomerAddressBunchProcessorInterface $customerAddressBunchProcessor
46
    ){
47
        $this->customerAddressBunchProcessor = $customerAddressBunchProcessor;
48
        parent::__construct($application);
49
    }
50
51
    /**
52
     * Process the plugin functionality.
53
     *
54
     * @return void
55
     * @throws \Exception Is thrown, if the plugin can not be processed
56
     */
57
    public function process()
58
    {
59
        // initialize the array for the global data
60
        $globalData = array();
61
62
        // initialize the global data
63
        $globalData[RegistryKeys::COUNTRY_REGIONS] = $this->getCountryRegions();
64
65
        $globalData = array_merge($this->getImportProcessor()->getGlobalData(), $globalData);
66
67
        // add the status with the global data
68
        $this->getRegistryProcessor()->mergeAttributesRecursive(
69
            RegistryKeys::STATUS,
70
            array(RegistryKeys::GLOBAL_DATA => $globalData)
71
        );
72
    }
73
74
    /**
75
     * @return mixed
76
     */
77
    public function getCountryRegions()
78
    {
79
        return $this->customerAddressBunchProcessor->loadDirectoryCountryRegions();
80
    }
81
}
82