Issues (320)

Security Analysis    not enabled

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/php/Apix/Resources.php (5 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
 *
5
 * This file is part of the Apix Project.
6
 *
7
 * (c) Franck Cassedanne <franck at ouarz.net>
8
 *
9
 * @license     http://opensource.org/licenses/BSD-3-Clause  New BSD License
10
 *
11
 */
12
13
namespace Apix;
14
15
use Apix\Entity,
16
    Apix\Entity\EntityInterface;
17
18
/**
19
 * Represents a collection of resources.
20
 */
21
class Resources
22
{
23
24
    /**
25
     * @var array
26
     */
27
    protected $resources = array();
28
29
    /**
30
     * @var EntityInterface
31
     */
32
    protected $entity = null;
33
34
    /**
35
     * Sets an entity object.
36
     *
37
     * @param EntityInterface $entity An entity object
38
     */
39
    public function setEntity(EntityInterface $entity)
40
    {
41
        $this->entity = $entity;
42
    }
43
44
    /**
45
     * Gets the current entity object.
46
     *
47
     * @return EntityInterface
48
     */
49
    public function getEntity()
50
    {
51
        return $this->entity;
52
    }
53
54
    /**
55
     * Adds a resource entity.
56
     *
57
     * @param  string $name     A resource name
58
     * @param  array  $resource A resource definition array
0 ignored issues
show
There is no parameter named $resource. Did you maybe mean $resources?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
59
     * @return Entity
60
     */
61
    public function add($name, array $resources)
62
    {
63
        switch(true):
64
65
            case isset($resources['action'])
66
                && $resources['action'] instanceof \Closure:
67
                $this->setEntity(
68
                    new Entity\EntityClosure()
69
                );
70
            break;
71
72
            case isset($resources['controller']):
73
            default:
74
                $this->setEntity(
75
                    new Entity\EntityClass()
76
                );
77
78
        endswitch;
79
80
        if (!isset($this->resources[$name])) {
81
            $entity = get_class($this->getEntity());
82
            $this->resources[$name] = new $entity(); //new Entity($group);
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
83
        }
84
        $this->resources[$name]->append($resources);
85
86
        return $this->resources[$name];
87
    }
88
89
    /**
90
     * Checks wether a specified resource name exists.
91
     *
92
     * @param  string  $name The resource name to check
93
     * @return boolean
94
     */
95
    public function has($name)
96
    {
97
        return isset($this->resources[$name]);
98
    }
99
100
    /**
101
     * Returns all the resources.
102
     *
103
     * @return array The array of resources
104
     */
105
    public function toArray()
106
    {
107
        return $this->resources;
108
    }
109
110
    /**
111
     * Gets the specified resource entity.
112
     *
113
     * @param  string                 $name The resource name to retrieve.
114
     * @throws /DomainException       404
115
     * @return Entity/EntityInterface
0 ignored issues
show
The doc-type Entity/EntityInterface could not be parsed: Unknown type name "Entity/EntityInterface" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
116
     */
117
    public function getResource($name)
118
    {
119
        if (isset($this->resources[$name])) {
120
            return $this->resources[$name];
121
        }
122
123
        throw new \DomainException(
124
            sprintf('Invalid resource entity specified (%s).', $name), 404
125
        );
126
    }
127
128
    /**
129
     * Gets the specified ressource entity from a route object.
130
     *
131
     * @param  Router                 $route  The resource route object.
132
     * @param  boolean                $follow Wether to handle the default actions.
133
     * @throws /DomainException       404
134
     * @return Entity/EntityInterface
0 ignored issues
show
The doc-type Entity/EntityInterface could not be parsed: Unknown type name "Entity/EntityInterface" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
135
     */
136
    public function get(Router &$route, $follow=true)
137
    {
138
        $entity = $this->getResource(
139
            $route->getName()
140
        );
141
142
        // swap if aliased/redirected
143
        if ($redirect = $entity->getRedirect()) {
144
            $entity = $this->getResource($redirect);
145
        }
146
147
        // handles the default actions but do not override a local action definition.
148
        if ($follow) {
149
150
            $method = $route->getMethod();
151
152
            if ( $method == 'HEAD' && $entity->hasMethod('GET') ) {
153
                $route->setMethod('GET');
154
            }
155
156
            if (
157
                ( $redirect = $entity->getDefaultAction($method) )
158
                && !$entity->hasMethod($method)
159
            ) {
160
                $entity = $this->getResource($redirect);
161
                #$route->setParams(array('entity' => clone $entity));
0 ignored issues
show
Unused Code Comprehensibility introduced by
69% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
162
            }
163
        }
164
165
        // set this entity route.
166
        $entity->setRoute($route);
167
168
        return $entity;
169
    }
170
171
}
172