Issues (2)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Breadcrumbs.php (1 issue)

Labels
Severity

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
declare(strict_types=1);
4
5
namespace Arcanedev\Breadcrumbs;
6
7
use Arcanedev\Breadcrumbs\Contracts\Breadcrumbs as BreadcrumbsContract;
8
use Closure;
9
use Illuminate\Support\HtmlString;
10
11
/**
12
 * Class     Breadcrumbs
13
 *
14
 * @author   ARCANEDEV <[email protected]>
15
 */
16
class Breadcrumbs implements BreadcrumbsContract
17
{
18
    /* -----------------------------------------------------------------
19
     |  Constants
20
     | -----------------------------------------------------------------
21
     */
22
23
    const DEFAULT_TEMPLATE = 'bootstrap-4';
24
25
    /* -----------------------------------------------------------------
26
     |  Properties
27
     | -----------------------------------------------------------------
28
     */
29
30
    /**
31
     * Default template view.
32
     *
33
     * @var string
34
     */
35
    private $template;
36
37
    /**
38
     * Supported template views.
39
     *
40
     * @var array
41
     */
42
    protected $supported = [
43
        'bootstrap-4' => 'breadcrumbs::bootstrap-4',
44
    ];
45
46
    /** @var array */
47
    protected $callbacks = [];
48
49
    /* -----------------------------------------------------------------
50
     |  Constructor
51
     | -----------------------------------------------------------------
52
     */
53
54
    /**
55
     * Create a Breadcrumbs instance.
56
     *
57
     * @param  array        $supported
58
     * @param  string|null  $template
59
     */
60 54
    public function __construct(array $supported, $template = null)
61
    {
62 54
        $this->setSupported($supported);
63 54
        $this->setTemplate($template ?: self::DEFAULT_TEMPLATE);
64 54
    }
65
66
    /* -----------------------------------------------------------------
67
     |  Getters & Setters
68
     | -----------------------------------------------------------------
69
     */
70
71
    /**
72
     * Set the supported template.
73
     *
74
     * @param  array  $supported
75
     *
76
     * @return $this
77
     */
78 54
    public function setSupported(array $supported)
79
    {
80 54
        $this->supported = $supported;
81
82 54
        return $this;
83
    }
84
85
    /**
86
     * Set default template view.
87
     *
88
     * @param  string  $template
89
     *
90
     * @return $this
91
     */
92 54
    public function setTemplate($template)
93
    {
94 54
        $this->checkTemplate($template);
95
96 54
        $this->template = $template;
97
98 54
        return $this;
99
    }
100
101
    /**
102
     * Get the template view.
103
     *
104
     * @return string
105
     */
106 18
    private function getView(): string
107
    {
108 18
        return $this->supported[$this->template];
109
    }
110
111
    /* -----------------------------------------------------------------
112
     |  Main Methods
113
     | -----------------------------------------------------------------
114
     */
115
116
    /**
117
     * Register a breadcrumb domain.
118
     *
119
     * @param  string    $name
120
     * @param  \Closure  $callback
121
     *
122
     * @return $this
123
     */
124 54
    public function register($name, Closure $callback)
125
    {
126 54
        $this->checkCallbackName($name);
127
128 54
        $this->callbacks[$name] = $callback;
129
130 54
        return $this;
131
    }
132
133
    /**
134
     * Render breadcrumbs items.
135
     *
136
     * @param  string|null  $name
137
     * @param  array        $params
138
     *
139
     * @return \Illuminate\Support\HtmlString
140
     */
141 18
    public function render($name = null, ...$params)
142
    {
143 18
        return new HtmlString(
144 18
            view($this->getView(), [
0 ignored issues
show
The method render does only exist in Illuminate\Contracts\View\View, but not in Illuminate\Contracts\View\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
145 18
                'breadcrumbs' => $this->generate($name, $params)
146 18
            ])->render()
147
        );
148
    }
149
150
    /**
151
     * Generate the breadcrumbs.
152
     *
153
     * @param  string  $name
154
     * @param  array   $params
155
     *
156
     * @return array
157
     */
158 24
    public function generate($name, ...$params): array
159
    {
160 24
        return (new Builder($this->callbacks))->call($name, $params)->toArray();
161
    }
162
163
    /* -----------------------------------------------------------------
164
     |  Check Methods
165
     | -----------------------------------------------------------------
166
     */
167
168
    /**
169
     * Check Template.
170
     *
171
     * @param  string  $template
172
     *
173
     * @throws Exceptions\InvalidTemplateException
174
     * @throws Exceptions\InvalidTypeException
175
     */
176 54
    private function checkTemplate($template): void
177
    {
178 54
        if ( ! is_string($template)) {
179 6
            $type = gettype($template);
180 6
            throw new Exceptions\InvalidTypeException(
181 6
                "The default template name must be a string, $type given."
182
            );
183
        }
184
185 54
        $template = strtolower(trim($template));
186
187 54
        if ( ! array_key_exists($template, $this->supported)) {
188 6
            throw new Exceptions\InvalidTemplateException(
189 6
                "The template [$template] is not supported."
190
            );
191
        }
192 54
    }
193
194
    /**
195
     * Check Name.
196
     *
197
     * @param  string  $name
198
     *
199
     * @throws Exceptions\InvalidTypeException
200
     */
201 54
    private function checkCallbackName(&$name): void
202
    {
203 54
        if ( ! is_string($name)) {
204 6
            $type = gettype($name);
205
206 6
            throw new Exceptions\InvalidTypeException(
207 6
                "The callback name value must be a string, $type given."
208
            );
209
        }
210
211 54
        $name = strtolower(trim($name));
212 54
    }
213
}
214