Beispiel #1
0
 /**
  * Check title rules
  *
  * @param Subject $subject
  *
  * @return ResultCollection
  */
 public function check(Subject $subject) : ResultCollection
 {
     $resultCollection = new ResultCollection();
     /**
      * Check
      */
     $contextDescription = $subject->getContextDescription();
     $titleTags = $subject->getDom()->getElementsByTagName('title');
     if ($titleTags->length === 0) {
         $resultCollection->add(new Result($contextDescription, 'Title tag is missing'));
     } else {
         if ($titleTags->length === 1) {
             if (strlen($titleTags->item(0)->nodeValue) > 55) {
                 $resultCollection->add(new Result($contextDescription, 'Title is longer than 55 characters'));
             }
         } else {
             $resultCollection->add(new Result($contextDescription, 'There are more than one title tag'));
         }
     }
     return $resultCollection;
 }
Beispiel #2
0
 /**
  * Check image rules
  *
  * @param Subject $subject
  *
  * @return ResultCollection
  */
 public function check(Subject $subject) : ResultCollection
 {
     $resultCollection = new ResultCollection();
     /**
      * Check
      */
     $contextDescription = $subject->getContextDescription();
     $imgTags = $subject->getDom()->getElementsByTagName('img');
     /**
      * @var \DOMElement $imgTag
      */
     $missingAltAttributes = 0;
     foreach ($imgTags as $imgTag) {
         $altAttribute = $imgTag->attributes->getNamedItem('alt');
         if (!$altAttribute || empty($altAttribute->nodeValue)) {
             $missingAltAttributes++;
         }
     }
     if ($missingAltAttributes > 0) {
         $resultCollection->add(new Result($contextDescription, "{$missingAltAttributes} img tag is missing alt attribute"));
     }
     return $resultCollection;
 }