Skip to content

Commit 2d3345c

Browse files
committed
Use constant for arrays that don't change
1 parent 71ab250 commit 2d3345c

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/Nodes/NodeTrait.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ trait NodeTrait
3131
*/
3232
private bool $readabilityDataTable = false;
3333

34-
private array $divToPElements = [
34+
private const DIV_TO_P_ELEMENTS = [
3535
'blockquote',
3636
'dl',
3737
'div',
@@ -47,7 +47,7 @@ trait NodeTrait
4747
* The commented out elements qualify as phrasing content but tend to be
4848
* removed by readability when put into paragraphs, so we ignore them here.
4949
*/
50-
private array $phrasing_elems = [
50+
private const PHRASING_ELEMS = [
5151
// 'CANVAS', 'IFRAME', 'SVG', 'VIDEO',
5252
'abbr', 'audio', 'b', 'bdo', 'br', 'button', 'cite', 'code', 'data',
5353
'datalist', 'dfn', 'em', 'embed', 'i', 'img', 'input', 'kbd', 'label',
@@ -367,14 +367,14 @@ public function hasSingleTagInsideElement(string $tag): bool
367367

368368
/**
369369
* Check if the current element has a single child block element.
370-
* Block elements are the ones defined in the divToPElements array.
370+
* Block elements are the ones defined in the DIV_TO_P_ELEMENTS array.
371371
*/
372372
public function hasSingleChildBlockElement(): bool
373373
{
374374
$result = false;
375375
if ($this->hasChildNodes()) {
376376
foreach ($this->childNodes as $child) {
377-
if (in_array($child->nodeName, $this->divToPElements)) {
377+
if (in_array($child->nodeName, self::DIV_TO_P_ELEMENTS)) {
378378
$result = true;
379379
} else {
380380
// If any of the hasSingleChildBlockElement calls return true, return true then.
@@ -417,7 +417,7 @@ public function isElementWithoutContent(): bool
417417
*/
418418
public function isPhrasingContent(): bool
419419
{
420-
return $this->nodeType === XML_TEXT_NODE || in_array($this->nodeName, $this->phrasing_elems) !== false ||
420+
return $this->nodeType === XML_TEXT_NODE || in_array($this->nodeName, self::PHRASING_ELEMS) !== false ||
421421
(!is_null($this->childNodes) &&
422422
($this->nodeName === 'a' || $this->nodeName === 'del' || $this->nodeName === 'ins') &&
423423
array_reduce(iterator_to_array($this->childNodes), function ($carry, $node) {

0 commit comments

Comments
 (0)