Issues (85)

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/Offer/AgeRange.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 CultuurNet\UDB3\Offer;
4
5
use CultuurNet\UDB3\Model\ValueObject\Audience\AgeRange as Udb3ModelAgeRange;
6
use ValueObjects\Person\Age;
7
8
class AgeRange
9
{
10
    /**
11
     * @var null|Age
12
     */
13
    private $from;
14
15
    /**
16
     * @var null|Age
17
     */
18
    private $to;
19
20
    /**
21
     * AgeRange constructor.
22
     * @param null|Age $from
23
     * @param null|Age $to
24
     */
25
    public function __construct(Age $from = null, Age $to = null)
26
    {
27
        $from = $from ?: new Age(0);
28
29
        $this->guardValidAgeRange($from, $to);
30
31
        $this->from = $from;
32
        $this->to = $to;
33
    }
34
35
    /**
36
     * @param Age $from
37
     * @param null|Age $to
38
     *
39
     * @throws InvalidAgeRangeException
40
     */
41
    private function guardValidAgeRange(Age $from, Age $to = null)
42
    {
43
        if ($from && $to && $from > $to) {
44
            throw new InvalidAgeRangeException('"from" age should not exceed "to" age');
45
        }
46
    }
47
48
    /**
49
     * @return Age
50
     */
51
    public function getFrom()
52
    {
53
        return $this->from;
54
    }
55
56
    /**
57
     * @return null|Age
58
     */
59
    public function getTo()
60
    {
61
        return $this->to;
62
    }
63
64
    /**
65
     * @return string
66
     */
67
    public function __toString()
68
    {
69
        $from = $this->from ? (string) $this->from : '';
70
        $to = $this->to ? (string) $this->to : '';
71
72
        return $from . '-' . $to;
73
    }
74
75
    /**
76
     * @param string $ageRangeString
77
     * @return AgeRange
78
     *
79
     * @throws InvalidAgeRangeException
80
     */
81
    public static function fromString($ageRangeString)
82
    {
83
        if (!is_string($ageRangeString)) {
84
            throw new InvalidAgeRangeException(
85
                'Date-range should be of type string.'
86
            );
87
        }
88
89
        $stringValues = explode('-', $ageRangeString);
90
91
        if (empty($stringValues) || !isset($stringValues[1])) {
92
            throw new InvalidAgeRangeException(
93
                'Date-range string is not valid because it is missing a hyphen.'
94
            );
95
        }
96
97
        if (count($stringValues) !== 2) {
98
            throw new InvalidAgeRangeException(
99
                'Date-range string is not valid because it has too many hyphens.'
100
            );
101
        }
102
103
        $fromString = $stringValues[0];
104
        $toString = $stringValues[1];
105
106 View Code Duplication
        if (is_numeric($fromString) || empty($fromString)) {
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...
107
            $from = is_numeric($fromString) ? new Age($fromString) : null;
108
        } else {
109
            throw new InvalidAgeRangeException(
110
                'The "from" age should be a natural number or empty.'
111
            );
112
        }
113
114 View Code Duplication
        if (is_numeric($toString) || empty($toString)) {
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...
115
            $to = is_numeric($toString) ? new Age($toString) : null;
116
        } else {
117
            throw new InvalidAgeRangeException(
118
                'The "to" age should be a natural number or empty.'
119
            );
120
        }
121
122
        return new self($from, $to);
123
    }
124
125
    /**
126
     * @param AgeRange $otherAgeRange
127
     * @return bool
128
     */
129
    public function sameAs(AgeRange $otherAgeRange)
130
    {
131
        return "$this" === "$otherAgeRange";
132
    }
133
134
    /**
135
     * @param Udb3ModelAgeRange $udb3ModelAgeRange
136
     * @return AgeRange
137
     */
138
    public static function fromUbd3ModelAgeRange(Udb3ModelAgeRange $udb3ModelAgeRange)
139
    {
140
        $from = null;
0 ignored issues
show
$from is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
141
        if ($from = $udb3ModelAgeRange->getFrom()) {
142
            $from = new Age($from->toInteger());
143
        }
144
145
        $to = null;
0 ignored issues
show
$to is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
146
        if ($to = $udb3ModelAgeRange->getTo()) {
147
            $to = new Age($to->toInteger());
148
        }
149
150
        return new AgeRange($from, $to);
151
    }
152
}
153