Completed
Push — master ( f172d4...76e139 )
by devosc
02:14
created

src/Cookie/Config/Container.php (3 issues)

Check that methods always have a scope defined

Best Practice Minor

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 *
4
 */
5
6
namespace Mvc5\Cookie\Config;
7
8
use Mvc5\Arg;
9
use Mvc5\Config\Config;
10
11
trait Container
12
{
13
    /**
14
     *
15
     */
16
    use Config;
17
18
    /**
19
     * @var array
20
     */
21
    protected $defaults = [
22
        Arg::EXPIRE    => 0,
23
        Arg::PATH      => '/',
24
        Arg::DOMAIN    => '',
25
        Arg::SECURE    => false,
26
        Arg::HTTP_ONLY => true
27
    ];
28
29
    /**
30
     * @param array $defaults
31
     */
32 42
    function __construct(array $defaults = [])
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
33
    {
34 42
        $defaults && $this->defaults = $defaults + $this->defaults;
35 42
    }
36
37
    /**
38
     * @param $name
39
     * @param $value
40
     * @param $expire
41
     * @param $path
42
     * @param $domain
43
     * @param $secure
44
     * @param $httponly
45
     * @return array
46
     */
47 10
    protected function cookie($name, $value, $expire, $path, $domain, $secure, $httponly)
48
    {
49
        return [
50 10
            Arg::NAME      => $name,
51 10
            Arg::VALUE     => $value,
52 6
            Arg::EXPIRE    => $expire   ?? $this->defaults[Arg::EXPIRE],
53 8
            Arg::PATH      => $path     ?? $this->defaults[Arg::PATH],
54 8
            Arg::DOMAIN    => $domain   ?? $this->defaults[Arg::DOMAIN],
55 8
            Arg::SECURE    => $secure   ?? $this->defaults[Arg::SECURE],
56 10
            Arg::HTTP_ONLY => $httponly ?? $this->defaults[Arg::HTTP_ONLY]
57
        ];
58
    }
59
60
    /**
61
     * @param string     $name
62
     * @param string     $path
63
     * @param string     $domain
64
     * @param bool|false $secure
65
     * @param bool|true  $httponly
66
     */
67 4
    function remove($name, $path = null, $domain = null, $secure = null, $httponly = null)
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
68
    {
69 4
        $this->setCookie($name, false, 946706400, $path, $domain, $secure, $httponly);
70 4
    }
71
72
    /**
73
     * @param string     $name
74
     * @param string     $value
75
     * @param int        $expire
76
     * @param string     $path
77
     * @param string     $domain
78
     * @param bool|false $secure
79
     * @param bool|true  $httponly
80
     * @return string
81
     */
82 3
    function set($name, $value, $expire = null, $path = null, $domain = null, $secure = null, $httponly = null)
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
83
    {
84 3
        $this->setCookie($name, $value, $expire, $path, $domain, $secure, $httponly);
85
86 3
        return $value;
87
    }
88
89
    /**
90
     * @param $name
91
     * @param $value
92
     * @param $expire
93
     * @param $path
94
     * @param $domain
95
     * @param $secure
96
     * @param $httponly
97
     * @return array
98
     */
99 8
    protected function setCookie($name, $value, $expire, $path, $domain, $secure, $httponly)
100
    {
101 8
        return $this->config[$name] = $this->cookie($name, $value, $expire, $path, $domain, $secure, $httponly);
102
    }
103
}
104