CookiesVariable::set()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 8
Bugs 1 Features 0
Metric Value
cc 1
eloc 9
c 8
b 1
f 0
nc 1
nop 8
dl 0
loc 19
rs 9.9666

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
/**
4
 * Cookies plugin for Craft CMS
5
 *
6
 * @link      https://nystudio107.com/
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @copyright tag
Loading history...
7
 * @copyright Copyright (c) nystudio107
0 ignored issues
show
Coding Style introduced by
@copyright tag must contain a year and the name of the copyright holder
Loading history...
8
 * @license   MIT License https://opensource.org/licenses/MIT
9
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
10
11
namespace nystudio107\cookies\variables;
12
13
use nystudio107\cookies\Cookies;
14
15
/**
16
 * Cookies template variables
17
 *
18
 * @author    nystudio107
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @package tag
Loading history...
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
Coding Style introduced by
Tag value for @author tag indented incorrectly; expected 2 spaces but found 4
Loading history...
19
 * @package   Cookies
0 ignored issues
show
Coding Style introduced by
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
20
 * @since     1.1.0
0 ignored issues
show
Coding Style introduced by
The tag in position 3 should be the @author tag
Loading history...
Coding Style introduced by
Tag value for @since tag indented incorrectly; expected 3 spaces but found 5
Loading history...
21
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
22
class CookiesVariable
23
{
24
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $name should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $value should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $expire should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $path should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $domain should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $secure should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $httpOnly should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $sameSite should have a doc-comment as per coding-style.
Loading history...
25
     * Set a cookie
26
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
27
    public function set(
28
        string $name = "",
29
        string $value = "",
30
        int    $expire = 0,
31
        string $path = "/",
32
        string $domain = "",
33
        bool   $secure = false,
34
        bool   $httpOnly = false,
35
        string $sameSite = 'Lax',
36
    ): void {
37
        Cookies::$plugin->cookies->set(
38
            $name,
39
            $value,
40
            $expire,
41
            $path,
42
            $domain,
43
            $secure,
44
            $httpOnly,
45
            $sameSite
46
        );
47
    }
48
49
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $name should have a doc-comment as per coding-style.
Loading history...
50
     * Get a cookie
51
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
52
    public function get(string $name): string
53
    {
54
        return Cookies::$plugin->cookies->get($name);
55
    }
56
57
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $name should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $value should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $expire should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $path should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $domain should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $secure should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $httpOnly should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $sameSite should have a doc-comment as per coding-style.
Loading history...
58
     * Set a secure cookie
59
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
60
    public function setSecure(
61
        string $name = "",
62
        string $value = "",
63
        int    $expire = 0,
64
        string $path = "/",
65
        string $domain = "",
66
        bool   $secure = false,
67
        bool   $httpOnly = false,
68
        string $sameSite = 'Lax',
69
    ): void {
70
        Cookies::$plugin->cookies->setSecure(
71
            $name,
72
            $value,
73
            $expire,
74
            $path,
75
            $domain,
76
            $secure,
77
            $httpOnly,
78
            $sameSite
79
        );
80
    }
81
82
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $name should have a doc-comment as per coding-style.
Loading history...
83
     * Get a secure cookie
84
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
85
    public function getSecure(string $name): string
86
    {
87
        return Cookies::$plugin->cookies->getSecure($name);
88
    }
89
}
90