1 | <?php |
||
35 | class PreLoadAttributeIdObserver extends AbstractAttributeImportObserver |
||
36 | { |
||
37 | |||
38 | /** |
||
39 | * The attribute processor instance. |
||
40 | * |
||
41 | * @var \TechDivision\Import\Attribute\Services\AttributeBunchProcessorInterface |
||
42 | */ |
||
43 | protected $attributeBunchProcessor; |
||
44 | |||
45 | /** |
||
46 | * Initializes the observer with the passed subject instance. |
||
47 | * |
||
48 | * @param \TechDivision\Import\Attribute\Services\AttributeBunchProcessorInterface $attributeBunchProcessor The attribute bunch processor instance |
||
49 | */ |
||
50 | public function __construct(AttributeBunchProcessorInterface $attributeBunchProcessor) |
||
54 | |||
55 | /** |
||
56 | * Return's the attribute bunch processor instance. |
||
57 | * |
||
58 | * @return \TechDivision\Import\Attribute\Services\AttributeBunchProcessorInterface The attribute bunch processor instance |
||
59 | */ |
||
60 | protected function getAttributeBunchProcessor() |
||
64 | |||
65 | /** |
||
66 | * Process the observer's business logic. |
||
67 | * |
||
68 | * @return array The processed row |
||
69 | */ |
||
70 | protected function process() |
||
83 | |||
84 | /** |
||
85 | * Queries whether or not the attribute with the passed code has already been processed. |
||
86 | * |
||
87 | * @param string $attributeCode The attribute code to check |
||
88 | * |
||
89 | * @return boolean TRUE if the path has been processed, else FALSE |
||
90 | */ |
||
91 | protected function hasBeenProcessed($attributeCode) |
||
95 | |||
96 | /** |
||
97 | * Pre-load and temporary persist the attribute ID for the passed EAV attribute. |
||
98 | * |
||
99 | * @param array $attribute The EAV attribute to pre-load |
||
100 | * |
||
101 | * @return void |
||
102 | */ |
||
103 | protected function preLoadAttributeId(array $attribute) |
||
107 | |||
108 | /** |
||
109 | * Load's and return's the EAV attribute with the passed code. |
||
110 | * |
||
111 | * @param string $attributeCode The code of the EAV attribute to load |
||
112 | * |
||
113 | * @return array The EAV attribute |
||
114 | */ |
||
115 | protected function loadAttributeByAttributeCode($attributeCode) |
||
119 | } |
||
120 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: