TitleRule::check()   B
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 24
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 11
cts 11
cp 1
rs 8.6845
c 0
b 0
f 0
cc 4
eloc 12
nc 4
nop 1
crap 4
1
<?php
2
3
namespace Zortje\SEO\Page;
4
5
use Zortje\Rules\Result;
6
use Zortje\Rules\ResultCollection;
7
use Zortje\Rules\RuleInterface;
8
use Zortje\Rules\Subject;
9
10
/**
11
 * Class TitleRule
12
 *
13
 * @package Zortje\SEO\Page
14
 */
15
class TitleRule implements RuleInterface
16
{
17
18
    /**
19
     * Check title rules
20
     *
21
     * @param Subject $subject
22
     *
23
     * @return ResultCollection
24
     */
25 3
    public function check(Subject $subject): ResultCollection
26
    {
27 3
        $resultCollection = new ResultCollection();
28
29
        /**
30
         * Check
31
         */
32 3
        $contextDescription = $subject->getContextDescription();
33
34 3
        $titleTags = $subject->getDom()->getElementsByTagName('title');
35
36 3
        if ($titleTags->length === 0) {
37 1
            $resultCollection->add(new Result($contextDescription, 'Title tag is missing'));
38
39 2
        } else if ($titleTags->length === 1) {
40 1
            if (strlen($titleTags->item(0)->nodeValue) > 55) {
41 1
                $resultCollection->add(new Result($contextDescription, 'Title is longer than 55 characters'));
42
            }
43
        } else {
44 1
            $resultCollection->add(new Result($contextDescription, 'There are more than one title tag'));
45
        }
46
47 3
        return $resultCollection;
48
    }
49
}
50