Completed
Push — master ( 9c731f...99dba7 )
by Dawid
16:51 queued 11:11
created

ApiVersion   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 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 When no API version provided or wrong format
24
     */
25 23
    public function __construct(array $values)
26
    {
27 23
        if (!isset($values['value'])) {
28 1
            throw new \InvalidArgumentException('No API version provided');
29
        }
30
31 22
        $stringifiedValue = (string) $values['value'];
32
33 22
        if (!preg_match('/^\d{1,}(?:\.\d{1,}){0,1}$/', $stringifiedValue)) {
34 4
            throw new \InvalidArgumentException('API version must have X or X.X format');
35
        }
36
37 18
        $this->apiVersion = $stringifiedValue;
38 18
    }
39
40
    /**
41
     * @return string
42
     */
43 9
    public function getApiVersion(): string
44
    {
45 9
        return $this->apiVersion;
46
    }
47
}
48