Readability\Readability::weightAttribute PHP Method

weightAttribute() protected method

Uses regular expressions to tell if this element looks good or bad.
protected weightAttribute ( DOMElement $element, string $attribute ) : integer
$element DOMElement
$attribute string
return integer
    protected function weightAttribute($element, $attribute)
    {
        if (!$element->hasAttribute($attribute)) {
            return 0;
        }
        $weight = 0;
        // $attributeValue = trim($element->getAttribute('class')." ".$element->getAttribute('id'));
        $attributeValue = trim($element->getAttribute($attribute));
        if ($attributeValue !== '') {
            if (preg_match($this->regexps['negative'], $attributeValue)) {
                $weight -= 25;
            }
            if (preg_match($this->regexps['positive'], $attributeValue)) {
                $weight += 25;
            }
            if (preg_match($this->regexps['unlikelyCandidates'], $attributeValue)) {
                $weight -= 5;
            }
            if (preg_match($this->regexps['okMaybeItsACandidate'], $attributeValue)) {
                $weight += 5;
            }
        }
        return $weight;
    }