Issues (2)

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/DateIntervalComparator.php (2 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
 * Copyright (c) Andreas Heigl<[email protected]>
4
 * Permission is hereby granted, free of charge, to any person obtaining a copy
5
 * of this software and associated documentation files (the "Software"), to deal
6
 * in the Software without restriction, including without limitation the rights
7
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
 * copies of the Software, and to permit persons to whom the Software is
9
 * furnished to do so, subject to the following conditions:
10
 * The above copyright notice and this permission notice shall be included in
11
 * all copies or substantial portions of the Software.
12
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
18
 * THE SOFTWARE.
19
 *
20
 * @author    Andreas Heigl<[email protected]>
21
 * @copyright Andreas Heigl
22
 * @license   http://www.opensource.org/licenses/mit-license.php MIT-License
23
 * @since     11.10.2016
24
 * @link      http://github.com/heiglandreas/org.heigl.DateIntervalComparator
25
 */
26
27
namespace Org_Heigl\DateIntervalComparator;
28
29
use DateInterval;
30
use UnexpectedValueException;
31
32
class DateIntervalComparator
33
{
34
    private $safe = false;
35
36
    public function __construct(bool $safe = false)
37
    {
38
        $this->safe = $safe;
39
    }
40
41
    /** @deprecated Use the constructor injected safety flag */
42
    public function safe($safe = true): void
43
    {
44
        $this->safe = $safe;
45
    }
46
47
    /**
48
     * COmpare the two date intervals.
49
     *
50
     * If the first contains a larger timespan we return 1, if the second contains more
51
     * we return -1 and when they are equals we return 0.
52
     *
53
     * @param DateInterval $first
54
     * @param DateInterval $second
55
     *
56
     * @return int
57
     */
58
    public function compare(DateInterval $first, DateInterval $second): int
59
    {
60
        if ($this->safe) {
61
            $this->safecheck($first);
62
            $this->safecheck($second);
63
        }
64
65
        if (0 !== $datePart = $this->compareDatePart($first, $second)) {
66
            return $datePart;
67
        }
68
69
        return $this->compareTimePart($first, $second);
70
    }
71
72 View Code Duplication
    private function compareDatePart(DateInterval $first, DateInterval $second): int
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...
73
    {
74
        if (0 !== $year = $this->compareValue($first->y, $second->y)) {
75
            return $year;
76
        }
77
78
        if (0 !== $month = $this->compareValue($first->m, $second->m)) {
79
            return $month;
80
        }
81
82
        if (0 !== $day = $this->compareValue($first->d, $second->d)) {
83
            return $day;
84
        }
85
86
        return 0;
87
    }
88
89 View Code Duplication
    private function compareTimePart(DateInterval $first, DateInterval $second): int
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...
90
    {
91
        if (0 !== $hour = $this->compareValue($first->h, $second->h)) {
92
            return $hour;
93
        }
94
95
        if (0 !== $minute = $this->compareValue($first->i, $second->i)) {
96
            return $minute;
97
        }
98
99
        if (0 !== $second = $this->compareValue($first->s, $second->s)) {
100
            return $second;
101
        }
102
103
        return 0;
104
    }
105
106
    private function compareValue(int $a, int $b): int
107
    {
108
        if ($a < $b) {
109
            return -1;
110
        }
111
112
        if ($a > $b) {
113
            return 1;
114
        }
115
116
        return 0;
117
    }
118
119
    private function safecheck(DateInterval $interval): void
120
    {
121
        if ($interval->m > 12) {
122
            throw new UnexpectedValueException('Month exceeds value 12');
123
        }
124
125
        if ($interval->d > 31) {
126
            throw new UnexpectedValueException('Day exceeds value 31');
127
        }
128
129
        // 25 due to DST-Transitions
130
        if ($interval->h > 25) {
131
            throw new UnexpectedValueException('Hour exceeds value 25');
132
        }
133
134
        if ($interval->i > 60) {
135
            throw new UnexpectedValueException('Minute exceeds value 60');
136
        }
137
138
        // 61 due to leap-seconds
139
        if ($interval->s > 61) {
140
            throw new UnexpectedValueException('Second exceeds value 61');
141
        }
142
    }
143
}
144