Params::getInt()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Bavix\Cases;
4
5
/**
6
 * Class Params
7
 * @package Bavix\Cases
8
 */
9
class Params
10
{
11
12
    /**
13
     * @var array
14
     */
15
    protected $annotations;
16
17
    /**
18
     * Params constructor.
19
     * @param array $annotations
20
     */
21
    public function __construct(array $annotations)
22
    {
23
        $this->annotations = $annotations;
24
    }
25
26
    /**
27
     * @param string $name
28
     * @param array $default
29
     * @return array
30
     */
31
    protected function getAttribute(string $name, array $default = []): array
32
    {
33
        return $this->annotations['method'][$name] ?? $default;
34
    }
35
36
    /**
37
     * @param string $name
38
     * @param int $default
39
     * @return int
40
     */
41
    protected function getInt(string $name, int $default = 0): int
42
    {
43
        return \current($this->getAttribute($name, [$default]));
44
    }
45
46
    /**
47
     * @param string $name
48
     * @param string $default
49
     * @return string
50
     */
51
    protected function getString(string $name, string $default): string
52
    {
53
        return \current($this->getAttribute($name, [$default]));
54
    }
55
56
    /**
57
     * @return int
58
     */
59
    public function getWidth(): int
60
    {
61
        return $this->getInt('width', 1024);
62
    }
63
64
    /**
65
     * @return int
66
     */
67
    public function getHeight(): int
68
    {
69
        return $this->getInt('height', 768);
70
    }
71
72
    /**
73
     * @return string
74
     */
75
    public function getPath(): string
76
    {
77
        return $this->getString('path', '/');
78
    }
79
80
    /**
81
     * @return string
82
     */
83
    public function getBrowser(): string
84
    {
85
        return $this->getString('browser', $_ENV['BROWSER']);
86
    }
87
88
}
89