Issues (51)

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/Test/AbstractPersistentDiscoveryTest.php (17 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
 * This file is part of the puli/discovery package.
5
 *
6
 * (c) Bernhard Schussek <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Puli\Discovery\Test;
13
14
use Puli\Discovery\Api\Type\BindingParameter;
15
use Puli\Discovery\Api\Type\BindingType;
16
use Puli\Discovery\Test\Fixtures\Foo;
17
use Puli\Discovery\Test\Fixtures\StringBinding;
18
use Webmozart\Expression\Expr;
19
20
/**
21
 * @since  1.0
22
 *
23
 * @author Bernhard Schussek <[email protected]>
24
 */
25
abstract class AbstractPersistentDiscoveryTest extends AbstractEditableDiscoveryTest
26
{
27 2
    public function testAddBindingKeepsStoredBindings()
28
    {
29 2
        $discovery = $this->createDiscovery();
30 2
        $discovery->addBindingType(new BindingType(Foo::clazz, self::STRING_BINDING));
31 2
        $discovery->addBinding($binding1 = new StringBinding('string1', Foo::clazz));
32
33 2
        $discovery = $this->loadDiscoveryFromStorage($discovery);
34 2
        $discovery->addBinding($binding2 = new StringBinding('string2', Foo::clazz));
35
36 2
        $this->assertEquals(array($binding1, $binding2), $discovery->getBindings());
37 2
    }
38
39 1
    public function testAddBindingInitializesLoadedBindings()
40
    {
41 1
        $binding1 = new StringBinding('string1', Foo::clazz);
42 1
        $binding2 = new StringBinding('string2', Foo::clazz);
43
44 1
        $this->initializer->expects($this->once())
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Puli\Discovery\Api\Bindi...izer\BindingInitializer.

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...
45 1
            ->method('acceptsBinding')
46 1
            ->willReturn(true);
47
48 1
        $this->initializer->expects($this->exactly(2))
49 1
            ->method('initializeBinding')
50 1
            ->withConsecutive(
51 1
                array($binding1),
52 1
                array($binding2)
53
            );
54
55 1
        $discovery = $this->createDiscovery();
56 1
        $discovery->addBindingType(new BindingType(Foo::clazz, self::STRING_BINDING));
57 1
        $discovery->addBinding($binding1);
58
59 1
        $discovery = $this->loadDiscoveryFromStorage($discovery, array($this->initializer));
0 ignored issues
show
array($this->initializer) is of type array<integer,object<PHP...\BindingInitializer>"}>, but the function expects a array<integer,object<Pul...er\BindingInitializer>>.

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...
60 1
        $discovery->addBinding($binding2);
61 1
    }
62
63 2 View Code Duplication
    public function testRemoveBindingsDoesNotInitializeLoadedBindings()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
    {
65 2
        $this->initializer->expects($this->never())
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Puli\Discovery\Api\Bindi...izer\BindingInitializer.

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...
66 2
            ->method('acceptsBinding');
67
68 2
        $this->initializer->expects($this->never())
69 2
            ->method('initializeBinding');
70
71 2
        $discovery = $this->createDiscovery();
72 2
        $discovery->addBindingType(new BindingType(Foo::clazz, self::STRING_BINDING));
73 2
        $discovery->addBinding(new StringBinding('string1', Foo::clazz));
74 2
        $discovery->addBinding(new StringBinding('string2', Foo::clazz));
75
76 2
        $discovery = $this->loadDiscoveryFromStorage($discovery, array($this->initializer));
0 ignored issues
show
array($this->initializer) is of type array<integer,object<PHP...\BindingInitializer>"}>, but the function expects a array<integer,object<Pul...er\BindingInitializer>>.

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...
77 2
        $discovery->removeBindings();
78 2
    }
79
80 2 View Code Duplication
    public function testRemoveBindingsWithTypeDoesNotInitializeLoadedBindings()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
81
    {
82 2
        $this->initializer->expects($this->never())
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Puli\Discovery\Api\Bindi...izer\BindingInitializer.

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...
83 2
            ->method('acceptsBinding');
84
85 2
        $this->initializer->expects($this->never())
86 2
            ->method('initializeBinding');
87
88 2
        $discovery = $this->createDiscovery();
89 2
        $discovery->addBindingType(new BindingType(Foo::clazz, self::STRING_BINDING));
90 2
        $discovery->addBinding(new StringBinding('string1', Foo::clazz));
91 2
        $discovery->addBinding(new StringBinding('string2', Foo::clazz));
92
93 2
        $discovery = $this->loadDiscoveryFromStorage($discovery, array($this->initializer));
0 ignored issues
show
array($this->initializer) is of type array<integer,object<PHP...\BindingInitializer>"}>, but the function expects a array<integer,object<Pul...er\BindingInitializer>>.

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...
94 2
        $discovery->removeBindings(Foo::clazz);
95 2
    }
96
97 2
    public function testRemoveBindingsWithTypeAndParameterWorksOnLoadedDiscovery()
98
    {
99 2
        $binding1 = new StringBinding('string1', Foo::clazz, array('param2' => 'bar'));
100 2
        $binding2 = new StringBinding('string2', Foo::clazz);
101 2
        $binding3 = new StringBinding('string3', Foo::clazz, array('param1' => 'bar'));
102
103 2
        $discovery = $this->createDiscovery();
104 2
        $discovery->addBindingType(new BindingType(Foo::clazz, self::STRING_BINDING, array(
105 2
            new BindingParameter('param1', BindingParameter::OPTIONAL, 'foo'),
106 2
            new BindingParameter('param2'),
107
        )));
108 2
        $discovery->addBinding($binding1);
109 2
        $discovery->addBinding($binding2);
110 2
        $discovery->addBinding($binding3);
111
112 2
        $discovery = $this->loadDiscoveryFromStorage($discovery);
113
114
        // Bindings need to be initialized for this to work
115 2
        $discovery->removeBindings(Foo::clazz, Expr::method('getParameterValue', 'param1', Expr::same('foo')));
116
117 2
        $this->assertEquals(array($binding3), $discovery->findBindings(Foo::clazz));
118 2
        $this->assertEquals(array($binding3), $discovery->getBindings());
119 2
    }
120
121 2 View Code Duplication
    public function testRemoveBindingTypeDoesNotInitializeLoadedBindings()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
122
    {
123 2
        $this->initializer->expects($this->never())
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Puli\Discovery\Api\Bindi...izer\BindingInitializer.

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...
124 2
            ->method('acceptsBinding');
125
126 2
        $this->initializer->expects($this->never())
127 2
            ->method('initializeBinding');
128
129 2
        $discovery = $this->createDiscovery();
130 2
        $discovery->addBindingType(new BindingType(Foo::clazz, self::STRING_BINDING));
131 2
        $discovery->addBinding(new StringBinding('string1', Foo::clazz));
132 2
        $discovery->addBinding(new StringBinding('string2', Foo::clazz));
133
134 2
        $discovery = $this->loadDiscoveryFromStorage($discovery, array($this->initializer));
0 ignored issues
show
array($this->initializer) is of type array<integer,object<PHP...\BindingInitializer>"}>, but the function expects a array<integer,object<Pul...er\BindingInitializer>>.

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...
135 2
        $discovery->removeBindingType(Foo::clazz);
136 2
    }
137
138 1 View Code Duplication
    public function testFindBindingsInitializesLoadedBindings()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
139
    {
140 1
        $binding1 = new StringBinding('string1', Foo::clazz);
141 1
        $binding2 = new StringBinding('string2', Foo::clazz);
142
143 1
        $this->initializer->expects($this->once())
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Puli\Discovery\Api\Bindi...izer\BindingInitializer.

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...
144 1
            ->method('acceptsBinding')
145 1
            ->willReturn(true);
146
147 1
        $this->initializer->expects($this->exactly(2))
148 1
            ->method('initializeBinding')
149 1
            ->withConsecutive(
150 1
                array($binding1),
151 1
                array($binding2)
152
            );
153
154 1
        $discovery = $this->createDiscovery();
155 1
        $discovery->addBindingType(new BindingType(Foo::clazz, self::STRING_BINDING));
156 1
        $discovery->addBinding($binding1);
157 1
        $discovery->addBinding($binding2);
158
159 1
        $discovery = $this->loadDiscoveryFromStorage($discovery, array($this->initializer));
0 ignored issues
show
array($this->initializer) is of type array<integer,object<PHP...\BindingInitializer>"}>, but the function expects a array<integer,object<Pul...er\BindingInitializer>>.

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...
160 1
        $discovery->findBindings(Foo::clazz);
161 1
    }
162
163 1 View Code Duplication
    public function testGetBindingsInitializesLoadedBindings()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
164
    {
165 1
        $binding1 = new StringBinding('string1', Foo::clazz);
166 1
        $binding2 = new StringBinding('string2', Foo::clazz);
167
168 1
        $this->initializer->expects($this->once())
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Puli\Discovery\Api\Bindi...izer\BindingInitializer.

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...
169 1
            ->method('acceptsBinding')
170 1
            ->willReturn(true);
171
172 1
        $this->initializer->expects($this->exactly(2))
173 1
            ->method('initializeBinding')
174 1
            ->withConsecutive(
175 1
                array($binding1),
176 1
                array($binding2)
177
            );
178
179 1
        $discovery = $this->createDiscovery();
180 1
        $discovery->addBindingType(new BindingType(Foo::clazz, self::STRING_BINDING));
181 1
        $discovery->addBinding($binding1);
182 1
        $discovery->addBinding($binding2);
183
184 1
        $discovery = $this->loadDiscoveryFromStorage($discovery, array($this->initializer));
0 ignored issues
show
array($this->initializer) is of type array<integer,object<PHP...\BindingInitializer>"}>, but the function expects a array<integer,object<Pul...er\BindingInitializer>>.

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...
185 1
        $discovery->getBindings();
186 1
    }
187
}
188