Skip to content

Commit de73a44

Browse files
authored
Merge pull request #9 from hnhdigital-os/analysis-rrVmwL
Apply fixes from StyleCI
2 parents 3738070 + 802d122 commit de73a44

File tree

2 files changed

+37
-34
lines changed

2 files changed

+37
-34
lines changed

src/Html.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ public function s(\Closure|string|bool|null $value = true): string
10371037
* (Re)Define an attribute.
10381038
*
10391039
* @param string|array<mixed>|null $name
1040-
* @param ?string $value
1040+
* @param ?string $value
10411041
*/
10421042
public function set($name, $value = null): Html
10431043
{

src/Markup.php

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
class Markup implements ArrayAccess
1818
{
1919
/**
20-
* Specifies if attribute values and text input sould be protected from XSS injection
20+
* Specifies if attribute values and text input sould be protected from XSS injection.
2121
*/
2222
public static bool $avoidXSS = false;
2323

@@ -45,9 +45,9 @@ class Markup implements ArrayAccess
4545
* @var array<int, string>
4646
*/
4747
protected array $autocloseTagsList = [
48-
'img', 'br', 'hr', 'input', 'area', 'link', 'meta', 'param', 'base', 'col', 'command', 'keygen', 'source'
48+
'img', 'br', 'hr', 'input', 'area', 'link', 'meta', 'param', 'base', 'col', 'command', 'keygen', 'source',
4949
];
50-
50+
5151
/**
5252
* @var array<mixed>
5353
*/
@@ -56,23 +56,23 @@ class Markup implements ArrayAccess
5656
protected function __construct(string $tag, ?self $top = null)
5757
{
5858
$this->tag = $tag;
59-
$this->top =& $top;
59+
$this->top = &$top;
6060
$this->attributeList = [];
6161
$this->content = [];
6262
$this->autoclosed = in_array($this->tag, $this->autocloseTagsList);
6363
$this->text = '';
6464
}
6565

6666
/**
67-
* Alias for getParent()
67+
* Alias for getParent().
6868
*/
6969
public function __invoke(): self
7070
{
7171
return $this->getParent();
7272
}
7373

7474
/**
75-
* Create a new Markup
75+
* Create a new Markup.
7676
*/
7777
public static function createElement(string $tag = ''): self
7878
{
@@ -83,8 +83,7 @@ public static function createElement(string $tag = ''): self
8383
}
8484

8585
/**
86-
*
87-
* Add element at an existing Markup
86+
* Add element at an existing Markup.
8887
*/
8988
public function addElement(self|string $tag = ''): self
9089
{
@@ -105,6 +104,7 @@ public function addElement(self|string $tag = ''): self
105104

106105
/**
107106
* (Re)Define an attribute or many attributes.
107+
*
108108
* @param string|array<mixed> $attribute
109109
*/
110110
public function set(string|array $attribute, ?string $value = null): self
@@ -121,40 +121,41 @@ public function set(string|array $attribute, ?string $value = null): self
121121
}
122122

123123
/**
124-
* alias to method "set"
124+
* alias to method "set".
125+
*
125126
* @param string|array<mixed> $attribute
126127
*/
127128
public function attr($attribute, ?string $value = null): self
128129
{
129-
return call_user_func_array(array($this, 'set'), func_get_args());
130+
return call_user_func_array([$this, 'set'], func_get_args());
130131
}
131132

132133
/**
133-
* Checks if an attribute is set for this tag and not null
134+
* Checks if an attribute is set for this tag and not null.
134135
*/
135136
public function offsetExists(mixed $offset): bool
136137
{
137138
return isset($this->attributeList[$offset]);
138139
}
139140

140141
/**
141-
* Returns the value the attribute set for this tag
142+
* Returns the value the attribute set for this tag.
142143
*/
143144
public function offsetGet(mixed $offset): mixed
144145
{
145146
return $this->offsetExists($offset) ? $this->attributeList[$offset] : null;
146147
}
147148

148149
/**
149-
* Sets the value an attribute for this tag
150+
* Sets the value an attribute for this tag.
150151
*/
151152
public function offsetSet(mixed $offset, mixed $value): void
152153
{
153154
$this->attributeList[$offset] = $value;
154155
}
155156

156157
/**
157-
* Removes an attribute
158+
* Removes an attribute.
158159
*/
159160
public function offsetUnset(mixed $offset): void
160161
{
@@ -174,24 +175,23 @@ public function text(?string $value): self
174175
}
175176

176177
/**
177-
* Returns the top element
178+
* Returns the top element.
178179
*/
179180
public function getTop(): self
180181
{
181182
return $this->top === null ? $this : $this->top;
182183
}
183184

184185
/**
185-
*
186-
* Return parent of current element
186+
* Return parent of current element.
187187
*/
188188
public function getParent(): ?self
189189
{
190190
return $this->parent;
191191
}
192192

193193
/**
194-
* Return first child of parent of current object
194+
* Return first child of parent of current object.
195195
*/
196196
public function getFirst(): ?self
197197
{
@@ -205,7 +205,7 @@ public function getPrevious(): ?static
205205
{
206206
$prev = $this;
207207

208-
if (! is_null($this->parent)) {
208+
if (!is_null($this->parent)) {
209209
foreach ($this->parent->content as $c) {
210210
if ($c === $this) {
211211
break;
@@ -234,6 +234,7 @@ public function getNext(): ?self
234234
}
235235
}
236236
}
237+
237238
return $next;
238239
}
239240

@@ -250,6 +251,7 @@ public function remove(): ?self
250251
foreach ($parent->content as $key => $value) {
251252
if ($parent->content[$key] == $this) {
252253
unset($parent->content[$key]);
254+
253255
return $parent;
254256
}
255257
}
@@ -259,27 +261,27 @@ public function remove(): ?self
259261
}
260262

261263
/**
262-
* Generation method
264+
* Generation method.
263265
*/
264266
public function __toString(): string
265267
{
266268
return $this->getTop()->toString();
267269
}
268270

269271
/**
270-
* Generation method
272+
* Generation method.
271273
*/
272274
public function toString(): string
273275
{
274276
$string = '';
275277

276278
if (!empty($this->tag)) {
277-
$string .= '<' . $this->tag;
279+
$string .= '<'.$this->tag;
278280
$string .= $this->attributesToString();
279281
if ($this->autoclosed) {
280282
$string .= '/>';
281283
} else {
282-
$string .= '>' . $this->contentToString() . '</' . $this->tag . '>';
284+
$string .= '>'.$this->contentToString().'</'.$this->tag.'>';
283285
}
284286
} else {
285287
$string .= $this->text;
@@ -290,38 +292,39 @@ public function toString(): string
290292
}
291293

292294
/**
293-
* Return current list of attribute as a string $key="$val" $key2="$val2"
295+
* Return current list of attribute as a string $key="$val" $key2="$val2".
294296
*/
295297
protected function attributesToString(): string
296298
{
297299
$string = '';
298-
$XMLConvention = in_array(static::$outputLanguage, array(ENT_XML1, ENT_XHTML));
300+
$XMLConvention = in_array(static::$outputLanguage, [ENT_XML1, ENT_XHTML]);
299301
if (!empty($this->attributeList)) {
300302
foreach ($this->attributeList as $key => $value) {
301-
if ($value!==null && ($value!==false || $XMLConvention)) {
302-
$string.= ' ' . $key;
303-
if ($value===true) {
303+
if ($value !== null && ($value !== false || $XMLConvention)) {
304+
$string .= ' '.$key;
305+
if ($value === true) {
304306
if ($XMLConvention) {
305307
$value = $key;
306308
} else {
307309
continue;
308310
}
309311
}
310-
$string.= '="' . implode(
312+
$string .= '="'.implode(
311313
' ',
312314
array_map(
313315
static::$avoidXSS ? 'static::unXSS' : 'strval',
314-
is_array($value) ? $value : array($value)
316+
is_array($value) ? $value : [$value]
315317
)
316-
) . '"';
318+
).'"';
317319
}
318320
}
319321
}
322+
320323
return $string;
321324
}
322325

323326
/**
324-
* return current list of content as a string
327+
* return current list of content as a string.
325328
*/
326329
protected function contentToString(): string
327330
{
@@ -337,7 +340,7 @@ protected function contentToString(): string
337340
}
338341

339342
/**
340-
* Protects value from XSS injection by replacing some characters by XML / HTML entities
343+
* Protects value from XSS injection by replacing some characters by XML / HTML entities.
341344
*/
342345
public static function unXSS(string $input): string
343346
{

0 commit comments

Comments
 (0)