Metadata::allowsPhpVersion()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author Kévin Gomez https://github.com/K-Phoen <[email protected]>
4
 */
5
6
namespace PHPSA\Analyzer\Pass;
7
8
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
9
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
10
11
/**
12
 * Describes an analyzer pass.
13
 */
14
class Metadata
15
{
16
    /** @var string */
17
    private $name;
18
19
    /** @var string|null */
20
    private $description;
21
22
    /** @var \Symfony\Component\Config\Definition\Builder\NodeDefinition */
23
    private $configuration;
24
25
    /** @var string|null */
26
    private $requiredPhpVersion;
27
28
    /**
29
     * @param string $name
30
     * @param string|null $description
31
     *
32
     * @return Metadata
33
     */
34 1
    public static function create($name, $description = null)
35
    {
36 1
        $treeBuilder = new TreeBuilder();
37
38 1
        $config = $treeBuilder->root($name)
39 1
            ->info($description)
40 1
            ->canBeDisabled()
41
        ;
42
43 1
        return new self($name, $config, $description);
44
    }
45
46
    /**
47
     * @param string $name
48
     * @param NodeDefinition $config
49
     * @param string|null $description
50
     */
51 1
    public function __construct($name, NodeDefinition $config, $description = null)
52
    {
53 1
        $this->name = $name;
54 1
        $this->configuration = $config;
55 1
        $this->description = $description;
56 1
    }
57
58
    /**
59
     * @return string
60
     */
61 1
    public function getName()
62
    {
63 1
        return $this->name;
64
    }
65
66
    /**
67
     * @return string|null
68
     */
69
    public function getDescription()
70
    {
71
        return $this->description;
72
    }
73
74
    /**
75
     * @param string $description
76
     */
77
    public function setDescription($description)
78
    {
79
        $this->description = $description;
80
    }
81
82
    /**
83
     * @return NodeDefinition
84
     */
85 1
    public function getConfiguration()
86
    {
87 1
        return $this->configuration;
88
    }
89
90
    /**
91
     * @return string|null
92
     */
93
    public function getRequiredPhpVersion()
94
    {
95
        return $this->requiredPhpVersion;
96
    }
97
98
    /**
99
     * @param string $requiredPhpVersion
100
     */
101 1
    public function setRequiredPhpVersion($requiredPhpVersion)
102
    {
103 1
        $this->requiredPhpVersion = $requiredPhpVersion;
104 1
    }
105
106
    /**
107
     * Tells if the current analyzer can be used with code written in a given PHP version.
108
     *
109
     * @param string $version
110
     *
111
     * @return bool
112
     */
113 1
    public function allowsPhpVersion($version)
114
    {
115 1
        return $this->requiredPhpVersion === null || version_compare($version, $this->requiredPhpVersion, '>=');
116
    }
117
}
118