|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Subjects\ValidatorSubject |
|
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 |
|
18
|
|
|
* @link http://www.techdivision.com |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Subjects; |
|
22
|
|
|
|
|
23
|
|
|
use TechDivision\Import\Utils\RegistryKeys; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Generic validator subject implementation. |
|
27
|
|
|
* |
|
28
|
|
|
* @author Tim Wagner <[email protected]> |
|
29
|
|
|
* @copyright 2019 TechDivision GmbH <[email protected]> |
|
30
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
31
|
|
|
* @link https://github.com/techdivision/import |
|
32
|
|
|
* @link http://www.techdivision.com |
|
33
|
|
|
*/ |
|
34
|
|
|
class ValidatorSubject extends AbstractSubject |
|
35
|
|
|
{ |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* The validation errors. |
|
39
|
|
|
* |
|
40
|
|
|
* @var array |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $validations = array(); |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Clean up the global data after importing the variants. |
|
46
|
|
|
* |
|
47
|
|
|
* @param string $serial The serial of the actual import |
|
48
|
|
|
* |
|
49
|
|
|
* @return void |
|
50
|
|
|
*/ |
|
51
|
|
View Code Duplication |
public function tearDown($serial) |
|
|
|
|
|
|
52
|
|
|
{ |
|
53
|
|
|
|
|
54
|
|
|
// invoke the parent method |
|
55
|
|
|
parent::tearDown($serial); |
|
56
|
|
|
|
|
57
|
|
|
// load the registry processor |
|
58
|
|
|
$registryProcessor = $this->getRegistryProcessor(); |
|
59
|
|
|
|
|
60
|
|
|
// update the source directory for the next subject |
|
61
|
|
|
$registryProcessor->mergeAttributesRecursive(RegistryKeys::STATUS, array(RegistryKeys::VALIDATIONS => $this->getValidations())); |
|
62
|
|
|
|
|
63
|
|
|
// log a debug message with the new source directory |
|
64
|
|
|
$this->getSystemLogger()->debug( |
|
65
|
|
|
sprintf('Subject %s successfully updated validation data for import %s', get_class($this), $serial) |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Return's the array with the validation errors. |
|
71
|
|
|
* |
|
72
|
|
|
* @return array The validation errors |
|
73
|
|
|
*/ |
|
74
|
|
|
public function getValidations() |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->validations; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Merge the passed validation errors into the status. |
|
81
|
|
|
* |
|
82
|
|
|
* @param array $validations The validation errors to merge |
|
83
|
|
|
* |
|
84
|
|
|
* @return void |
|
85
|
|
|
*/ |
|
86
|
|
|
public function mergeValidations(array $validations) |
|
87
|
|
|
{ |
|
88
|
|
|
$this->validations = array_replace_recursive($this->validations, $validations); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.