TitleRule   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 35
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B check() 0 24 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