Issues (2921)

src/Check/CheckArraybleTrait.php (29 issues)

1
<?php
2
3
/**
4
 * This file is part of the `tvi/monitor-bundle` project.
5
 *
6
 * (c) https://github.com/turnaev/monitor-bundle/graphs/contributors
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
0 ignored issues
show
PHP version not specified
Loading history...
Missing @category tag in file comment
Loading history...
Missing @package tag in file comment
Loading history...
Missing @author tag in file comment
Loading history...
Missing @license tag in file comment
Loading history...
Missing @link tag in file comment
Loading history...
11
12
namespace Tvi\MonitorBundle\Check;
13
14
use JMS\Serializer\Annotation as JMS;
15
16
/**
0 ignored issues
show
Missing short description in doc comment
Loading history...
17
 * @author Vladimir Turnaev <[email protected]>
18
 */
0 ignored issues
show
Missing @category tag in class comment
Loading history...
Missing @package tag in class comment
Loading history...
Missing @license tag in class comment
Loading history...
Missing @link tag in class comment
Loading history...
19
trait CheckArraybleTrait // implements \ArrayAccess, \Iterator, \Countable
20
{
21
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
22
     * @JMS\Exclude()
23
     *
24
     * @var CheckInterface[]
25
     */
26
    protected $checks = [];
27
28 25
    public function count(): int
0 ignored issues
show
Missing doc comment for function count()
Loading history...
29
    {
30 25
        return \count($this->checks);
31
    }
32
33
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
34
     * @param string $offset
0 ignored issues
show
Missing parameter comment
Loading history...
35
     *
36
     * @return bool
37
     */
38 2
    public function offsetExists($offset)
39
    {
40 2
        return isset($this->checks[$offset]);
41
    }
42
43
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
44
     * @param string $offset
0 ignored issues
show
Missing parameter comment
Loading history...
45
     *
46
     * @return CheckInterface
47
     */
48 116
    public function offsetGet($offset)
49
    {
50 116
        if ($this->checks[$offset] instanceof Proxy) {
51 116
            $this->checks[$offset] = $this->checks[$offset]();
52
        }
53
54 116
        return $this->checks[$offset];
55
    }
56
57
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
58
     * @param string         $offset
0 ignored issues
show
Missing parameter comment
Loading history...
59
     * @param CheckInterface $value
0 ignored issues
show
Missing parameter comment
Loading history...
60
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
61 1
    public function offsetSet($offset, $value)
62
    {
63 1
        $this->checks[$offset] = $value;
64 1
    }
65
66
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
67
     * @param string $offset
0 ignored issues
show
Missing parameter comment
Loading history...
68
     *
69
     * @return CheckInterface
70
     */
71 1
    public function offsetUnset($offset)
72
    {
73 1
        unset($this->checks[$offset]);
74 1
    }
75
76
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
77
     * @return CheckInterface
78
     */
79 109
    public function current()
80
    {
81 109
        $key = $this->key();
82
83 109
        return $this->offsetGet($key);
84
    }
85
86
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
87
     * @return CheckInterface
88
     */
89 109
    public function next()
90
    {
91 109
        return next($this->checks);
92
    }
93
94
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
95
     * @return string
96
     */
97 109
    public function key()
98
    {
99 109
        return key($this->checks);
100
    }
101
102
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
103
     * @return bool
104
     */
105 110
    public function valid()
106
    {
107 110
        return (bool) key($this->checks);
108
    }
109
110 110
    public function rewind()
0 ignored issues
show
Missing doc comment for function rewind()
Loading history...
111
    {
112 110
        reset($this->checks);
113 110
    }
114
115
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
116
     * @return CheckInterface[]
117
     */
118 77
    public function toArray()
119
    {
120 77
        $out = [];
121 77
        foreach ($this as $k => $v) {
122 76
            $out[$k] = $v;
123
        }
124
125 77
        return $out;
126
    }
127
}
128