Issues (6)

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/Resource.php (2 issues)

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
 * Codeburner Framework.
5
 *
6
 * @author Alex Rohleder <[email protected]>
7
 * @copyright 2016 Alex Rohleder
8
 * @license http://opensource.org/licenses/MIT
9
 */
10
11
namespace Codeburner\Router;
12
13
/**
14
 * Representation of a group of several routes with same
15
 * controller and respecting the resourceful actions.
16
 *
17
 * @author Alex Rohleder <[email protected]>
18
 */
19
20
class Resource extends Group
21
{
22
23
    /**
24
     * @inheritdoc
25
     * @throws \BadMethodCallException
26
     */
27
28
    public function setMethod($method)
29
    {
30
        throw new \BadMethodCallException("Resources can't chance they http method.");
31
    }
32
33
    /**
34
     * Remove the routes without the passed methods.
35
     *
36
     * @param string|string[] $methods
37
     * @return self
38
     */
39
40 1
    public function only($methods)
41
    {
42 1
        $this->filterByMethod((array) $methods, false);
43 1
        return $this;
44
    }
45
46
    /**
47
     * Remove the routes with the passed methods.
48
     *
49
     * @param string|string[] $methods
50
     * @return self
51
     */
52
53 1
    public function except($methods)
54
    {
55 1
        $this->filterByMethod((array) $methods, true);
56 1
        return $this;
57
    }
58
59
    /**
60
     * Forget the grouped routes filtering by http methods.
61
     *
62
     * @param string[] $methods
63
     * @param bool $alt Should remove?
64
     */
65
66 2
    private function filterByMethod(array $methods, $alt)
67
    {
68 2
        $methods = array_flip(array_map('strtolower', $methods));
69
70 2
        foreach ($this->routes as $route) {
71 2
            if (isset($methods[$route->getAction()[1]]) === $alt) {
72 2
                $route->forget();
73 2
            }
74 2
        }
75 2
    }
76
77
    /**
78
     * Translate the "make" or "edit" from resources path.
79
     *
80
     * @param string[] $translations
81
     * @return self
82
     */
83
84
    public function translate(array $translations)
85
    {
86
        foreach ($this->routes as $route) {
87
            $action = $route->getAction()[1];
88
89
            if ($action === "make" && isset($translations["make"])) {
90
                $route->setPatternWithoutReset(str_replace("make", $translations["make"], $route->getPattern()));
91
            } elseif ($action === "edit" && isset($translations["edit"])) {
92
                $route->setPatternWithoutReset(str_replace("edit", $translations["edit"], $route->getPattern()));
93
            }
94
        }
95
96
        return $this;
97
    }
98
99
    /**
100
     * Add a route or a group of routes to the resource, it means that
101
     * every added route will now receive the parameters of the resource, like id.
102
     *
103
     * @param Route|Group $route
104
     * @return self
105
     */
106
107
    public function member($route)
108
    {
109
        $resource = new self;
110
        $resource->set($route);
111
        $this->nest($resource);
0 ignored issues
show
$resource is of type object<Codeburner\Router\Resource>, but the function expects a object<self>.

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...
112
    }
113
114
    /**
115
     * Nested routes capture the relation between a resource and another resource.
116
     *
117
     * @param self $resource
118
     * @return self
119
     */
120
121 3
    public function nest(self $resource)
122
    {
123 3
        foreach ($this->routes as $route) {
124 3
            if ($route->getAction()[1] === "show") {
125 3
                $this->set($resource->forget()->setPrefix($this->getNestedPrefix($route->getPattern()))); break;
126
            }
127 3
        }
128
129 3
        return $this;
130
    }
131
132
    /**
133
     * Nest resources but with only build routes with the minimal amount of information
134
     * to uniquely identify the resource.
135
     *
136
     * @param self $resource
137
     * @return self
138
     */
139
140 1
    public function shallow(self $resource)
141
    {
142 1
        $newResource = new self;
143 1
        $resource->forget();
144 1
        $routes = $resource->all();
145
146 1
        foreach ($routes as $route) {
147 1
            if (strpos("index make create", $route->getAction()[1]) !== false) {
148 1
                $newResource->set($route);
149 1
            }
150 1
        }
151
152 1
        return $this->nest($newResource);
0 ignored issues
show
$newResource is of type object<Codeburner\Router\Resource>, but the function expects a object<self>.

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...
153
    }
154
155
    /**
156
     * Resolve the nesting pattern, setting the prefixes based on
157
     * parent resources patterns.
158
     *
159
     * @param string $pattern
160
     * @return string
161
     */
162
163 3
    protected function getNestedPrefix($pattern)
164
    {
165 3
        $segments = explode("/", $pattern);
166 3
        $pattern = "";
167
168 3
        foreach ($segments as $index => $segment) {
169 3
            if (strpos($segment, "{") === 0) {
170 3
                   $pattern .= "/{" . $segments[$index - 1] . "_" . ltrim($segment, "{");
171 3
            } else $pattern .= $segment;
172 3
        }
173
174 3
        return $pattern;
175
    }
176
177
}
178