Completed
Push — master ( dd07bc...4a603a )
by Jan-Petter
05:48
created

directive::getValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace vipnytt\XRobotsTagParser;
4
5
use vipnytt\XRobotsTagParser\directives;
6
use vipnytt\XRobotsTagParser\directives\directiveInterface;
7
8
final class directive
9
{
10
    private $object;
11
12
    /**
13
     * Constructor
14
     *
15
     * @param string $directive
16
     * @param string $rule
17
     * @param array $options
18
     */
19
    public function __construct($directive, $rule, $options)
20
    {
21
        $class = __NAMESPACE__ . "\\directives\\$directive";
22
        if (!class_exists($class)) {
23
            trigger_error('Directive class does not exist', E_USER_ERROR);
24
        }
25
        $object = new $class($rule, $options);
26
        if (!$object instanceof directiveInterface) {
27
            trigger_error('Directive class invalid', E_USER_ERROR);
28
        }
29
        $this->object = $object;
30
    }
31
32
    /**
33
     * Get rule array
34
     *
35
     * @return array
36
     */
37
    public function getArray()
38
    {
39
        return [
40
            $this->object->getDirective() => $this->object->getValue()
41
        ];
42
    }
43
44
    /**
45
     * Get rule value
46
     *
47
     * @return string
48
     */
49
    public function getValue()
50
    {
51
        return $this->object->getValue();
52
    }
53
}
54