Issues (9)

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/Container.php (1 issue)

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
namespace Acelaya\SlimContainerSm;
3
4
use Acelaya\SlimContainerSm\Exception\BadMethodCallException;
5
use Acelaya\SlimContainerSm\Factory\CallbackWrapper;
6
use Slim\Helper\Set;
7
use Zend\ServiceManager\ServiceManager;
8
9
/**
10
 * Class Container
11
 * @author Alejandro Celaya Alastrué
12
 * @link http://www.alejandrocelaya.com
13
 */
14
class Container extends Set implements SlimContainerConsumibleInterface
15
{
16
    /**
17
     * @var ServiceManager
18
     */
19
    protected $sm;
20
21
    public function __construct(ServiceManager $sm = null)
22
    {
23 14
        parent::__construct();
24
        $this->initServiceManager($sm);
25 14
    }
26 14
27 14
    protected function initServiceManager(ServiceManager $sm = null)
28
    {
29
        $this->sm = $sm ?: new ServiceManager();
30
        $this->sm->setAllowOverride(true);
31
    }
32
33
    /**
34 6
     * Set data key to value
35
     * @param string $key   The data key
36 6
     * @param mixed  $value The data value
37 1
     */
38 1
    public function set($key, $value)
39 6
    {
40
        if (is_callable($value)) {
41 6
            $this->registerFactory($key, $value, false);
42
        } else {
43
            $this->sm->setService($key, $value);
44
        }
45
    }
46
47
    /**
48
     * Get data value with key
49 3
     * @param  string $key     The data key
50
     * @param  mixed  $default The value to return if data key does not exist
51 3
     * @return mixed           The data value, or the default value
52
     */
53
    public function get($key, $default = null)
54
    {
55
        return $this->has($key) ? $this->sm->get($key) : $default;
56
    }
57
58 1
    /**
59
     * Fetch set data
60 1
     * @return array This set's key-value data array
61
     */
62
    public function all()
63
    {
64
        throw new BadMethodCallException('It is not possible to fetch all services registered in a ServiceManager');
65
    }
66
67 4
    /**
68
     * Fetch set data keys
69 4
     * @return array This set's key-value data array keys
70
     */
71
    public function keys()
72
    {
73
        throw new BadMethodCallException('It is not possible to get service names registered in a ServiceManager');
74
    }
75
76
    /**
77 7
     * Does this set contain a key?
78
     * @param  string  $key The data key
79 7
     * @return boolean
80
     */
81
    public function has($key)
82
    {
83
        return $this->sm->has($key);
84
    }
85
86 1
    /**
87
     * Remove value with key from this set
88 1
     * @param string $key The data key
89 1
     */
90
    public function remove($key)
91
    {
92
        $this->sm->setService($key, null);
0 ignored issues
show
null is of type null, but the function expects a array|object.

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...
93
    }
94 1
95
    /**
96 1
     * Clear all values
97 1
     */
98 1
    public function clear()
99 1
    {
100 1
        $this->initServiceManager();
101
    }
102
103
    /**
104
     * Countable
105 1
     */
106
    public function count()
107 1
    {
108
        throw new BadMethodCallException('It is not possible to count the number of services in a ServiceManager');
109
    }
110
111
    /**
112
     * IteratorAggregate
113 1
     */
114
    public function getIterator()
115 1
    {
116
        throw new BadMethodCallException('It is not possible to generate an iterator from a ServiceManager');
117
    }
118
119
    /**
120
     * Ensure a value or object will remain globally unique
121
     * @param string $key The value or object name
122
     * @param $value
123
     * @return mixed
124 2
     */
125
    public function singleton($key, $value)
126 2
    {
127 1
        if (is_callable($value)) {
128 1
            $this->registerFactory($key, $value);
129 1
        } else {
130
            $this->sm->setService($key, $value);
131 2
        }
132
    }
133
134
    /**
135
     * Makes this to consume the services defined in provided container
136
     *
137 14
     * @param Set $container
138
     * @return mixed
139 14
     */
140 14
    public function consumeSlimContainer(Set $container)
141 14
    {
142
        foreach ($container as $key => $value) {
143
            if ($value instanceof \Closure) {
144
                // Try to determin if this belongs to a singleton or not
145
                $refFunc = new \ReflectionFunction($value);
146 1
                // Slim singletons have a static 'object' variable
147
                $shared = in_array('object', $refFunc->getStaticVariables());
148 1
                $this->registerFactory($key, $value, $shared);
149
            } elseif (is_callable($value)) {
150
                // Register as non-shared factories any other callable
151
                $this->registerFactory($key, $value, false);
152
            } else {
153
                $this->sm->setService($key, $value);
154
            }
155
        }
156
    }
157 1
158
    /**
159 1
     * Registers a factory wrapping a Slim factory into a ZF2 factory
160 1
     *
161
     * @param $key
162 1
     * @param callable $callable
163
     * @param bool $shared
164 1
     */
165 1
    protected function registerFactory($key, callable $callable, $shared = true)
166 1
    {
167
        $this->sm->setFactory($key, new CallbackWrapper($this, $callable));
168 1
        $this->sm->setShared($key, $shared);
169 1
    }
170
}
171