GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Nip_Helper_Url::__call()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 9
nc 3
nop 2
dl 0
loc 13
ccs 0
cts 8
cp 0
crap 20
rs 9.2
c 0
b 0
f 0
1
<?php
2
use Nip\Dispatcher\Dispatcher;
3
4
/**
5
 * Class Nip_Helper_Url
6
 */
7
class Nip_Helper_Url extends Nip\Helpers\AbstractHelper
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
8
{
9
    use \Nip\Router\RouterAwareTrait;
10
11
    protected $pieces = [];
12
13
    /**
14
     * Singleton
15
     * @return Nip_Helper_URL
16
     */
17
    static public function instance()
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
18
    {
19
        static $instance;
20
        if (!($instance instanceof self)) {
21
            $instance = new self();
22
        }
23
24
        return $instance;
25
    }
26
27
    /**
28
     * @param $name
29
     * @param $arguments
30
     * @return $this|mixed
31
     */
32
    public function __call($name, $arguments)
33
    {
34
        if ($name == ucfirst($name)) {
35
            $this->pieces[] = Dispatcher::reverseControllerName($name);
36
            return $this;
37
        } else {
38
            $this->pieces[] = $name;
39
        }
40
41
        $name = $this->pieces ? implode(".", $this->pieces) : '';
42
        $this->pieces = [];
43
        return $this->assemble($name, isset($arguments[0]) ? $arguments[0] : null);
44
    }
45
46
    /**
47
     * @param $name
48
     * @param bool $params
49
     * @return mixed
50
     */
51
    public function assemble($name, $params = false)
52
    {
53
        return $this->getRouter()->assembleFull($name, $params);
0 ignored issues
show
Documentation introduced by
$params is of type boolean, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
54
    }
55
56
    /**
57
     * @param $name
58
     * @param bool $params
59
     * @return mixed
60
     */
61
    public function get($name, $params = false)
62
    {
63
        return $this->assemble($name, $params);
64
    }
65
66
    /**
67
     * @param $name
68
     * @param bool $params
69
     * @return mixed|string
70
     */
71
    public function route($name, $params = false)
72
    {
73
        return $this->getRouter()->assemble($name, $params);
0 ignored issues
show
Documentation introduced by
$params is of type boolean, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
74
    }
75
76
    /**
77
     * @param array $params
78
     * @return string
79
     */
80
    public function base($params = [])
81
    {
82
        $currentRoute = $this->getRouter()->getCurrent();
83
        $base = $currentRoute ? $currentRoute->getBase($params) : request()->root();
84
85
        return $base.($params ? "?".http_build_query($params) : '');
86
    }
87
88
    /**
89
     * Reverse of the PHP built-in function parse_url
90
     *
91
     * @see http://php.net/parse_url
92
     * @param array $params
93
     * @return string
94
     */
95
    public function build($params)
96
    {
97
        return ((isset($params['scheme'])) ? $params['scheme'] . '://' : '')
98
        . ((isset($params['user'])) ? $params['user'] . ((isset($params['pass'])) ? ':' . $params['pass'] : '') . '@' : '')
99
        . ((isset($params['host'])) ? $params['host'] : '')
100
        . ((isset($params['port'])) ? ':' . $params['port'] : '')
101
        . ((isset($params['path'])) ? $params['path'] : '')
102
        . ((isset($params['query'])) ? '?' . $params['query'] : '')
103
        . ((isset($params['fragment'])) ? '#' . $params['fragment'] : '');
104
    }
105
106
    /**
107
     * Replaces all non-alphanumeric characters and returns dash-separated string
108
     *
109
     * @param string $input
110
     * @return string
111
     */
112
    public function encode($input)
113
    {
114
        $chars = [
115
            '&#x102;' => 'a',
116
            '&#x103;' => 'a',
117
            '&#xC2;' => 'A',
118
            '&#xE2;' => 'a',
119
            '&#xCE;' => 'I',
120
            '&#xEE;' => 'i',
121
            '&#x218;' => 'S',
122
            '&#x219;' => 's',
123
            '&#x15E;' => 'S',
124
            '&#x15F;' => 's',
125
            '&#x21A;' => 'T',
126
            '&#x21B;' => 't',
127
            '&#354;' => 'T',
128
            '&#355;' => 't'
129
        ];
130
131
        $change = $with = [];
132
        foreach ($chars as $i => $v) {
133
            $change[] = html_entity_decode($i, ENT_QUOTES, 'UTF-8');
134
            $with[] = $v;
135
        }
136
        $input = str_replace($change, $with, $input);
137
138
        preg_match_all("/[a-z0-9]+/i", $input, $sections);
139
        return strtolower(implode("-", $sections[0]));
140
    }
141
142
    public function getRequest()
143
    {
144
    }
145
}
146