Issues (6)

src/RequestContextTrait.php (3 issues)

Severity
1
<?php
2
/**
3
 * Webino™ (http://webino.sk)
4
 *
5
 * @link        https://github.com/webino/request
6
 * @copyright   Copyright (c) 2019 Webino, s.r.o. (http://webino.sk)
7
 * @author      Peter Bačinský <[email protected]>
8
 * @license     BSD-3-Clause
9
 */
10
11
namespace Webino;
12
13
/**
14
 * Trait RequestContextTrait
15
 * @package request
16
 */
17
trait RequestContextTrait
18
{
19
    /**
20
     * @var array
21
     */
22
    private $params;
23
24
    /**
25
     * @return array
26
     */
27
    abstract protected function createParams(): array;
28
29
    /**
30
     * @return array
31
     */
32
    protected function getParams(): array
33
    {
34
        $this->params or $this->params = $this->createParams();
35
        return $this->params;
36
    }
37
38
    /**
39
     * @param array $params
40
     */
41
    protected function setParams(array $params): void
42
    {
43
        $this->params = $params;
44
    }
45
46
    /**
47
     * @param string $offset
48
     * @return bool
49
     */
50
    public function offsetExists($offset)
51
    {
52
        return array_key_exists((string) $offset, $this->getParams());
53
    }
54
55
    /**
56
     * @param string $offset
57
     * @return mixed
58
     */
59
    public function offsetGet($offset)
60
    {
61
        return $this->offsetExists($offset) ? $this->getParams()[(string) $offset] : null;
62
    }
63
64
    /**
65
     * @param string $offset
66
     * @param mixed $value
67
     */
68
    public function offsetSet($offset, $value)
0 ignored issues
show
The parameter $value is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

68
    public function offsetSet($offset, /** @scrutinizer ignore-unused */ $value)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $offset is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

68
    public function offsetSet(/** @scrutinizer ignore-unused */ $offset, $value)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
69
    {
70
        // read-only
71
    }
72
73
    /**
74
     * @param string $offset
75
     */
76
    public function offsetUnset($offset)
0 ignored issues
show
The parameter $offset is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

76
    public function offsetUnset(/** @scrutinizer ignore-unused */ $offset)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
77
    {
78
        // read-only
79
    }
80
81
    /**
82
     * @return array
83
     */
84
    public function toArray(): array
85
    {
86
        return (array) $this->getParams();
87
    }
88
}
89