Issues (115)

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/Structure/Collection.php (4 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
namespace ValueObjects\Structure;
4
5
use ValueObjects\Util\Util;
6
use ValueObjects\Number\Natural;
7
use ValueObjects\StringLiteral\StringLiteral;
8
use ValueObjects\ValueObjectInterface;
9
10
class Collection implements ValueObjectInterface
11
{
12
    /** @var \SplFixedArray */
13
    protected $items;
14
15
    /**
16
     * Returns a new Collection object
17
     *
18
     * @param  \SplFixedArray $array
0 ignored issues
show
There is no parameter named $array. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

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

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

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

Loading history...
19
     * @return self
20
     */
21 3
    public static function fromNative()
22
    {
23 3
        $array = \func_get_arg(0);
24 3
        $items = array();
25
26 3
        foreach ($array as $item) {
27 3
            if ($item instanceof \Traversable || \is_array($item)) {
28 2
                $items[] = static::fromNative($item);
29 2
            } else {
30 3
                $items[] = new StringLiteral(\strval($item));
31
            }
32 3
        }
33
34 3
        $fixedArray = \SplFixedArray::fromArray($items);
35
36 3
        return new static($fixedArray);
37
    }
38
39
    /**
40
     * Returns a new Collection object
41
     *
42
     * @return self
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
43
     */
44 12
    public function __construct(\SplFixedArray $items)
45
    {
46 12
        foreach ($items as $item) {
47 12
            if (false === $item instanceof ValueObjectInterface) {
48 1
                $type = \is_object($item) ? \get_class($item) : \gettype($item);
49 1
                throw new \InvalidArgumentException(\sprintf('Passed SplFixedArray object must contains "ValueObjectInterface" objects only. "%s" given.', $type));
50
            }
51 12
        }
52
53 12
        $this->items = $items;
54 12
    }
55
56
    /**
57
     * Tells whether two Collection are equal by comparing their size and items (item order matters)
58
     *
59
     * @param  ValueObjectInterface $collection
60
     * @return bool
61
     */
62 6
    public function sameValueAs(ValueObjectInterface $collection)
63
    {
64 6
        if (false === Util::classEquals($this, $collection) || false === $this->count()->sameValueAs($collection->count())) {
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface ValueObjects\ValueObjectInterface as the method count() does only exist in the following implementations of said interface: ValueObjects\Structure\Collection, ValueObjects\Structure\Dictionary.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
65 1
            return false;
66
        }
67
68 6
        $arrayCollection = $collection->toArray();
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface ValueObjects\ValueObjectInterface as the method toArray() does only exist in the following implementations of said interface: ValueObjects\Structure\Collection, ValueObjects\Structure\Dictionary.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
69
70 6
        foreach ($this->items as $index => $item) {
71 6
            if (!isset($arrayCollection[$index]) || false === $item->sameValueAs($arrayCollection[$index])) {
72 1
                return false;
73
            }
74 6
        }
75
76 6
        return true;
77
    }
78
79
    /**
80
     * Returns the number of objects in the collection
81
     *
82
     * @return Natural
83
     */
84 10
    public function count()
85
    {
86 10
        return new Natural($this->items->count());
87
    }
88
89
    /**
90
     * Tells whether the Collection contains an object
91
     *
92
     * @param  ValueObjectInterface $object
93
     * @return bool
94
     */
95 3
    public function contains(ValueObjectInterface $object)
96
    {
97 3
        foreach ($this->items as $item) {
98 3
            if ($item->sameValueAs($object)) {
99 3
                return true;
100
            }
101 3
        }
102
103 3
        return false;
104
    }
105
106
    /**
107
     * Returns a native array representation of the Collection
108
     *
109
     * @return array
110
     */
111 7
    public function toArray()
112
    {
113 7
        return $this->items->toArray();
114
    }
115
116
    /**
117
     * Returns a native string representation of the Collection object
118
     *
119
     * @return string
120
     */
121 1
    public function __toString()
122
    {
123 1
        $string = \sprintf('%s(%d)', \get_class($this), $this->count()->toNative());
124
125 1
        return $string;
126
    }
127
}
128