Issues (5)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  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.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  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.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  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.
  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.
  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.
  Header Injection
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/Tuple.php (2 issues)

1
<?php
2
declare(strict_types=1);
3
/**
4
 * This file is part of the Tuple package.
5
 * For the full copyright information please view the LICENCE file that was
6
 * distributed with this package.
7
 *
8
 * @copyright Simon Deeley 2017
9
 */
10
11
namespace simondeeley;
12
13
use SplFixedArray;
14
use InvalidArgumentException;
15
use LengthException;
16
use simondeeley\Type\Type;
17
use simondeeley\Type\TupleType;
18
use simondeeley\Type\TypeEquality;
19
use simondeeley\ImmutableArrayTypeObject;
20
use simondeeley\Helpers\TypeEqualityHelperMethods;
21
22
/**
23
 * Tuple base object
24
 *
25
 * @author Simon Deeley <[email protected]>
26
 * @abstract
27
 * @uses ImmutableArrayTypeObject
28
 */
29
abstract class Tuple extends ImmutableArrayTypeObject implements TupleType, TypeEquality
30
{
31
    use TypeEqualityHelperMethods;
32
33
    const MAX_LENGTH = PHP_INT_MAX;
34
    const MIN_LENGTH = 0;
35
36
    /**
37
     * @var SplFixedArray $data
38
     */
39
    protected $data;
40
41
    /**
42
     * Create a new tuple object
43
     *
44
     * Instantiates a new tuple object of fixed length with the provided data
45
     * set. Once the object is created, it's contents cannot be mutated.
46
     *
47
     * @param mixed ...$items - Variadic number of arguments
48
     * @return void
49
     * @throws LengthException - Thrown if number of arguments passed exceeds
50
     *                           the maximum or is less than the minimum allowed
51
     *                           values.
52
     */
53 24
    final public function __construct(...$items)
54
    {
55 24 View Code Duplication
        if (count($items) < static::MIN_LENGTH) {
0 ignored issues
show
This code seems to be duplicated across 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...
56 6
            throw new LengthException(sprintf(
57 6
                '%s expects a minimum of %d arguments but only got %d',
58 6
                $this::getType(),
59 6
                static::MIN_LENGTH,
60 6
                count($items)
61
            ));
62
        }
63
64 18 View Code Duplication
        if (count($items) > static::MAX_LENGTH) {
0 ignored issues
show
This code seems to be duplicated across 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...
65
            throw new LengthException(sprintf(
66
                '%s expects a maximum of %d arguments but instead got %d',
67
                $this::getType(),
68
                static::MAX_LENGTH,
69
                count($items)
70
            ));
71
        }
72
73 18
        $this->data = SplFixedArray::fromArray($items);
74 18
    }
75
76
    /**
77
     * Check two Tuples are equal
78
     *
79
     * Compares the internal data of the two tuple objects ($tuple & $this). It
80
     * runs each through a comparitor which serializes each value, if one is
81
     * not equal to the other then the result will be considered false.
82
     *
83
     * @param Type $tuple - The tuple to compare
84
     * @param int $flags - optional bitwise flags to change method behaviour
85
     * @throws InvalidArgumentException - thrown if $tuple is not an instance of
86
     *                                    TupleType
87
     * @return bool - Returns true if $tuple is equal to $this
88
     */
89 6
    final public function equals(Type $tuple, int $flags = TypeEquality::IGNORE_OBJECT_IDENTITY): bool
90
    {
91 6
        if (false === $tuple instanceof TupleType)
92
        {
93
            throw new InvalidArgumentException(sprintf(
94
                'Cannot compare %s with %s as they are not of the same type',
95
                get_class($this),
96
                get_class($tuple)
97
            ));
98
        }
99
100 6
        if (0 === strcmp(
101 6
                md5(serialize($this->data->toArray())),
102 6
                md5(serialize($tuple->data->toArray())))
103 6
            && $this->isSameTypeAs($tuple, $flags)
104 6
            && $this->isSameObjectAs($tuple, $flags)
105
        ) {
106 6
            return true;
107
        }
108
109
        return false;
110
    }
111
112
    /**
113
     * Check that a property exists
114
     *
115
     * @see http://php.net/manual/en/arrayaccess.offsetexists.php
116
     *
117
     * @param mixed $offset - Name of the property to check
118
     * @return bool - Returns true if property exists
119
     * @throws InvalidArgumentException - Thrown if $property is not an integer
120
     */
121 18
    final public function offsetExists($offset): bool
122
    {
123 18
        if (false === is_int($offset)) {
124 6
            throw new InvalidArgumentException(sprintf(
125 6
                'Offset must be of type integer, "%s" passed',
126 6
                 gettype($offset)
127
            ));
128
        }
129
130 12
        return isset($this->data[$offset]);
131
    }
132
133
    /**
134
     * ArrayAccess get offset
135
     *
136
     * @param mixed $offset
137
     * @return mixed
138
     */
139 18
    final public function offsetGet($offset)
140
    {
141 18
        return $this->offsetExists($offset) ? $this->data[$offset] : null;
142
    }
143
144
    /**
145
     * Implement a basic getType
146
     *
147
     * @return string
148
     */
149
    public static function getType(): string
150
    {
151
        return 'TUPLE';
152
    }
153
}
154