Issues (3)

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/Date/FlexDate.php (1 issue)

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 Dontdrinkandroot\Date;
4
5
use DateTime;
6
use Exception;
7
8
/**
9
 * @author Philip Washington Sorst <[email protected]>
10
 */
11
class FlexDate
12
{
13
    const PRECISION_YEAR = 'year';
14
    const PRECISION_MONTH = 'month';
15
    const PRECISION_DAY = 'day';
16
    const PRECISION_NONE = 'none';
17
18
    protected ?int $year;
0 ignored issues
show
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected '?', expecting T_FUNCTION or T_CONST
Loading history...
19
20
    protected ?int $month;
21
22
    protected ?int $day;
23
24
    public function __construct(?int $year = null, ?int $month = null, ?int $day = null)
25
    {
26
        $this->year = $year;
27
        $this->month = $month;
28
        $this->day = $day;
29
    }
30
31
    public function getYear(): ?int
32
    {
33
        return $this->year;
34
    }
35
36
    public function setYear(?int $year): void
37
    {
38
        $this->year = $year;
39
    }
40
41
    public function getMonth(): ?int
42
    {
43
        return $this->month;
44
    }
45
46
    public function setMonth(?int $month): void
47
    {
48
        $this->month = $month;
49
    }
50
51
    public function getDay(): ?int
52
    {
53
        return $this->day;
54
    }
55
56
    public function setDay(?int $day): void
57
    {
58
        $this->day = $day;
59
    }
60
61
    public function hasValue(): bool
62
    {
63
        return null !== $this->year || null !== $this->month || null !== $this->day;
64
    }
65
66
    public function isCompleteDate(): bool
67
    {
68
        return null !== $this->year && null !== $this->month && null !== $this->day;
69
    }
70
71
    public function isValid(): bool
72
    {
73
        try {
74
            $this->assertValid();
75
76
            return true;
77
        } catch (Exception $e) {
78
            return false;
79
        }
80
    }
81
82
    public function assertValid(): bool
83
    {
84
        if (null !== $this->day && null === $this->month) {
85
            throw new Exception('Day set, but no month');
86
        }
87
88
        if (null !== $this->month && null === $this->year) {
89
            throw new Exception('Month, but no year');
90
        }
91
92
        return true;
93
    }
94
95
    public function isValidDate(): bool
96
    {
97
        return checkdate($this->month, $this->day, $this->year);
98
    }
99
100
    public function toDateTime(): DateTime
101
    {
102
        $dateTime = new DateTime();
103
        $inferredYear = $this->year !== null ? $this->year : 0;
104
        $inferredMonth = $this->month !== null ? $this->month : 1;
105
        $inferredDay = $this->day !== null ? $this->day : 1;
106
        $dateTime->setDate($inferredYear, $inferredMonth, $inferredDay);
107
108
        return $dateTime;
109
    }
110
111
    public function __toString(): string
112
    {
113
        $string = '';
114
        if (null !== $this->year) {
115
            $string .= $this->year;
116
        }
117
        if (null !== $this->month) {
118
            $string .= '-';
119
            $string .= str_pad($this->month, 2, '0', STR_PAD_LEFT);
120
        }
121
        if (null !== $this->day) {
122
            $string .= '-';
123
            $string .= str_pad($this->day, 2, '0', STR_PAD_LEFT);
124
        }
125
126
        return $string;
127
    }
128
129
    public static function fromString(string $dateString): FlexDate
130
    {
131
        $flexDate = new FlexDate();
132
        if (empty($dateString)) {
133
            return $flexDate;
134
        }
135
136
        $parts = explode('-', $dateString);
137
        $numParts = count($parts);
138
        if ($numParts > 0) {
139
            $flexDate->setYear((int)$parts[0]);
140
        }
141
        if ($numParts > 1) {
142
            $flexDate->setMonth((int)$parts[1]);
143
        }
144
        if ($numParts > 2) {
145
            $flexDate->setDay((int)$parts[2]);
146
        }
147
148
        return $flexDate;
149
    }
150
151
    public function getPrecision(): string
152
    {
153
        if (null !== $this->day) {
154
            return self::PRECISION_DAY;
155
        }
156
157
        if (null !== $this->month) {
158
            return self::PRECISION_MONTH;
159
        }
160
161
        if (null !== $this->year) {
162
            return self::PRECISION_YEAR;
163
        }
164
165
        return self::PRECISION_NONE;
166
    }
167
}
168