Completed
Push — master ( 1c14d6...2c9995 )
by Dawid
02:08
created

ApiVersion   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 33
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 3
A getApiVersion() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiechu\SymfonyCommonsBundle\Annotation\Controller;
6
7
use Doctrine\Common\Annotations\Annotation\Target;
8
9
/**
10
 * @Annotation
11
 * @Target("CLASS")
12
 */
13
class ApiVersion
14
{
15
    /**
16
     * @var string
17
     */
18
    protected $apiVersion;
19
20
    /**
21
     * @param array $values
22
     *
23
     * @throws \InvalidArgumentException
24
     */
25
    public function __construct(array $values)
26
    {
27
        if (!isset($values['value'])) {
28
            throw new \InvalidArgumentException('No API version provided');
29
        }
30
31
        if (!preg_match('/^[0-9]{1}\.[0-9]{1}$/', $values['value'])) {
32
            throw new \InvalidArgumentException('API version must have X.X format');
33
        }
34
35
        $this->apiVersion = (string) $values['value'];
36
    }
37
38
    /**
39
     * @return string
40
     */
41
    public function getApiVersion(): string
42
    {
43
        return $this->apiVersion;
44
    }
45
}
46