Skip to content

Commit

Permalink
Use constant for arrays that don't change
Browse files Browse the repository at this point in the history
  • Loading branch information
fivefilters committed Dec 7, 2024
1 parent 71ab250 commit 2d3345c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Nodes/NodeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ trait NodeTrait
*/
private bool $readabilityDataTable = false;

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

/**
* Check if the current element has a single child block element.
* Block elements are the ones defined in the divToPElements array.
* Block elements are the ones defined in the DIV_TO_P_ELEMENTS array.
*/
public function hasSingleChildBlockElement(): bool
{
$result = false;
if ($this->hasChildNodes()) {
foreach ($this->childNodes as $child) {
if (in_array($child->nodeName, $this->divToPElements)) {
if (in_array($child->nodeName, self::DIV_TO_P_ELEMENTS)) {
$result = true;
} else {
// If any of the hasSingleChildBlockElement calls return true, return true then.
Expand Down Expand Up @@ -417,7 +417,7 @@ public function isElementWithoutContent(): bool
*/
public function isPhrasingContent(): bool
{
return $this->nodeType === XML_TEXT_NODE || in_array($this->nodeName, $this->phrasing_elems) !== false ||
return $this->nodeType === XML_TEXT_NODE || in_array($this->nodeName, self::PHRASING_ELEMS) !== false ||
(!is_null($this->childNodes) &&
($this->nodeName === 'a' || $this->nodeName === 'del' || $this->nodeName === 'ins') &&
array_reduce(iterator_to_array($this->childNodes), function ($carry, $node) {
Expand Down

0 comments on commit 2d3345c

Please sign in to comment.