1 | <?php |
||
33 | abstract class ComponentAbstract implements ComponentInterface |
||
34 | { |
||
35 | |||
36 | /** |
||
37 | * Array of dom attributes |
||
38 | * |
||
39 | * @var array |
||
40 | */ |
||
41 | protected $dom_attributes = array(); |
||
42 | |||
43 | /** |
||
44 | * Array of component scripts |
||
45 | * |
||
46 | * @var array |
||
47 | */ |
||
48 | protected $component_scripts = array(); |
||
49 | |||
50 | /** |
||
51 | * Name of DOM attribute |
||
52 | * |
||
53 | * @var string |
||
54 | */ |
||
55 | protected $dom_attribute_name; |
||
56 | |||
57 | /** |
||
58 | * Loaded Component Method object |
||
59 | * |
||
60 | * @var object |
||
61 | */ |
||
62 | protected $methodProvider; |
||
63 | |||
64 | /** |
||
65 | * Component Constructor |
||
66 | */ |
||
67 | 58 | public function __construct() |
|
72 | |||
73 | /** |
||
74 | * Call passes all calls to no existing methods to self::methodProvider |
||
75 | * |
||
76 | * @param string $method |
||
77 | * @param array $args |
||
78 | * @throws InvalidComponentMethodException |
||
79 | */ |
||
80 | 58 | public function __call(string $method, $args) |
|
95 | |||
96 | /** |
||
97 | * Return DOM attribute contents |
||
98 | * |
||
99 | * @return string |
||
100 | */ |
||
101 | 4 | public function getDomAttributeString(): string |
|
102 | { |
||
103 | 4 | $attrs = $this->getDOMAttributesArray(); |
|
|
|||
104 | 4 | $attr_format = implode(': %s; ', array_keys($attrs)) . ': %s;'; |
|
105 | |||
106 | 4 | return vsprintf($attr_format, array_values($attrs)); |
|
107 | } |
||
108 | |||
109 | /** |
||
110 | * Set class providing component methods |
||
111 | * |
||
112 | * @param string $mp |
||
113 | * @return void |
||
114 | */ |
||
115 | 58 | public function setMethodProvider(string $mp = 'DefaultMethods') |
|
116 | { |
||
117 | 58 | $mp_class = substr(get_called_class(), 0, strrpos(get_called_class(), '\\')) . '\Methods\\' . $mp; |
|
118 | |||
119 | 58 | $this->methodProvider = new $mp_class(); |
|
120 | 58 | } |
|
121 | |||
122 | /** |
||
123 | * Does component have DOM Atributes |
||
124 | * |
||
125 | * {@inheritdoc} |
||
126 | * |
||
127 | * @return bool |
||
128 | */ |
||
129 | 2 | public function hasDOMAttributes(): bool |
|
133 | |||
134 | /** |
||
135 | * Get component DOM Atributes array |
||
136 | * |
||
137 | * {@inheritdoc} |
||
138 | * |
||
139 | * @return array |
||
140 | */ |
||
141 | 20 | public function getDOMAttributesArray(): array |
|
145 | |||
146 | /** |
||
147 | * Get Component scripts |
||
148 | * |
||
149 | * {@inheritdoc} |
||
150 | * |
||
151 | * @return array |
||
152 | */ |
||
153 | 2 | public function getComponentScripts(): array |
|
157 | |||
158 | /** |
||
159 | * Add component scripts |
||
160 | * |
||
161 | * {@inheritdoc} |
||
162 | * |
||
163 | */ |
||
164 | 1 | public function addComponentScripts(string $vendor_component, string $script_name) |
|
168 | |||
169 | /** |
||
170 | * Get DOMAttr for the entity |
||
171 | * |
||
172 | * @return DOMAttr |
||
173 | */ |
||
174 | 2 | public function getDOMAttr(): DOMAttr |
|
178 | |||
179 | /** |
||
180 | * Get Dom attribute name |
||
181 | * |
||
182 | * @return string |
||
183 | */ |
||
184 | 2 | public function getDomAttributeName(): string |
|
188 | |||
189 | /** |
||
190 | * Set Dom Attribute name |
||
191 | * |
||
192 | * @param string $dom_attribute_name |
||
193 | * @return void |
||
194 | */ |
||
195 | 58 | public function setDomAttribute(string $dom_attribute_name) |
|
199 | } |
||
200 |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.