Issues (38)

Security Analysis    not enabled

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/FeedIo/Rule/DateTimeBuilder.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 declare(strict_types=1);
2
/*
3
 * This file is part of the feed-io package.
4
 *
5
 * (c) Alexandre Debril <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace FeedIo\Rule;
12
13
use Psr\Log\LoggerInterface;
14
use Psr\Log\NullLogger;
15
16
class DateTimeBuilder implements DateTimeBuilderInterface
17
{
18
    /**
19
     * Supported date formats
20
     * @var array
21
     */
22
    protected $dateFormats = [
23
        \DateTime::RFC2822,
24
        \DateTime::ATOM,
25
        \DateTime::RFC3339,
26
        \DateTime::RFC3339_EXTENDED,
27
        \DateTime::RSS,
28
        \DateTime::W3C,
29
        'Y-m-d\TH:i:s.uP',
30
        'Y-m-d\TH:i:s.uvP',
31
        'Y-m-d\TH:i:s',
32
        'Y-m-d',
33
        'd/m/Y',
34
        'D, d M Y H:i O',
35
        'D, d M Y H:i:s O',
36
        'D M d Y H:i:s e',
37
        '*, m#d#Y - H:i',
38
        'D, d M Y H:i:s \U\T',
39
        '*, d M* Y H:i:s e',
40
        '*, d M Y',
41
    ];
42
43
    /**
44
     * @var \DateTimeZone
45
     */
46
    protected $feedTimezone;
47
48
    /**
49
     * @var \DateTimeZone
50
     */
51
    protected $serverTimezone;
52
53
    /**
54
     * @var LoggerInterface
55
     */
56
    protected $logger;
57
58
    /**
59
     * @var string
60
     */
61
    protected $lastGuessedFormat = \DateTime::RFC2822;
62
63
    /**
64
     * @param \Psr\Log\LoggerInterface        $logger
65
     */
66 78
    public function __construct(LoggerInterface $logger = null)
67
    {
68 78
        if (is_null($logger)) {
69 65
            $logger = new NullLogger;
70
        }
71 78
        $this->logger = $logger;
72 78
        $this->setTimezone(new \DateTimeZone(date_default_timezone_get()));
73 78
    }
74
75
    /**
76
     * @param $dateFormat
77
     * @return DateTimeBuilder
78
     */
79 22
    public function addDateFormat(string $dateFormat) : DateTimeBuilderInterface
80
    {
81 22
        $this->dateFormats[] = $dateFormat;
82
83 22
        return $this;
84
    }
85
86
    /**
87
     * @param  array $dateFormats
88
     * @return $this
89
     */
90 2
    public function setDateFormats(array $dateFormats) : DateTimeBuilderInterface
91
    {
92 2
        $this->dateFormats = $dateFormats;
93
94 2
        return $this;
95
    }
96
97
    /**
98
     * @return string
99
     */
100 15
    public function getLastGuessedFormat() : string
101
    {
102 15
        return $this->lastGuessedFormat;
103
    }
104
105
    /**
106
     * Tries to guess the date's format from the list
107
     * @param  string                   $date
108
     * @return string|null             date Format
109
     */
110 17
    public function guessDateFormat(string $date) : ? string
111
    {
112 17
        foreach ($this->dateFormats as $format) {
113 17
            $test = \DateTime::createFromFormat($format, $date);
114 17
            if ($test instanceof \DateTime) {
115 15
                $this->lastGuessedFormat = $format;
116
117 15
                return $format;
118
            }
119
        }
120
121 2
        return null;
122
    }
123
124
    /**
125
     * Creates a DateTime instance for the given string. Default format is RFC2822
126
     * @param  string                   $string
127
     * @return \DateTime
128
     */
129 15
    public function convertToDateTime(string $string) : \DateTime
130
    {
131 15
        $string = trim($string);
132 15
        foreach ([$this->getLastGuessedFormat(), $this->guessDateFormat($string) ] as $format) {
133 15
            $date = $this->newDate((string) $format, $string);
134 15
            if ($date instanceof \DateTime) {
135 14
                $date->setTimezone($this->getTimezone());
136
137 14
                return $date;
138
            }
139
        }
140
141 1
        return $this->stringToDateTime($string);
142
    }
143
144
    /**
145
     * Creates a DateTime instance for the given string if the format was not catch from the list
146
     * @param  string                   $string
147
     * @return \DateTime
148
     * @throws InvalidArgumentException
149
     */
150 2
    public function stringToDateTime(string $string) : \DateTime
151
    {
152 2
        $this->logger->notice("unsupported date format, use strtotime() to build the DateTime instance : {$string}");
153
154 2
        if (false === strtotime($string)) {
155 1
            throw new \InvalidArgumentException('Impossible to convert date : '.$string);
156
        }
157 1
        $date = new \DateTime($string, $this->getFeedTimezone());
158 1
        $date->setTimezone($this->getTimezone());
159
160 1
        return $date;
161
    }
162
163
    /**
164
     * @return \DateTimeZone
165
     */
166 16
    public function getFeedTimezone() : ? \DateTimeZone
167
    {
168 16
        return $this->feedTimezone;
169
    }
170
171
    /**
172
     * Specifies the feed's timezone. Do this it the timezone is missing
173
     *
174
     * @param \DateTimeZone $timezone
175
     */
176
    public function setFeedTimezone(\DateTimeZone $timezone) : void
177
    {
178
        $this->feedTimezone = $timezone;
179
    }
180
181
    /**
182
     * Resets feedTimezone to null.
183
     */
184
    public function resetFeedTimezone() : void
185
    {
186
        $this->feedTimezone = null;
187
    }
188
189
    /**
190
     * @return \DateTimeZone
191
     */
192 16
    public function getServerTimezone() : ? \DateTimeZone
193
    {
194 16
        return $this->serverTimezone;
195
    }
196
197
    /**
198
     * @param \DateTimeZone $timezone
199
     */
200 78
    public function setServerTimezone(\DateTimeZone $timezone) : void
201
    {
202 78
        $this->serverTimezone = $timezone;
203 78
    }
204
205
    /**
206
     * @return \DateTimeZone
207
     */
208 16
    public function getTimezone() : ? \DateTimeZone
209
    {
210 16
        return $this->getServerTimezone();
211
    }
212
213
    /**
214
     * @param \DateTimeZone $timezone
215
     */
216 78
    public function setTimezone(\DateTimeZone $timezone) : void
217
    {
218 78
        $this->setServerTimezone($timezone);
219 78
    }
220
221
    /**
222
     * @param $format
223
     * @param $string
224
     * @return \DateTime
225
     */
226 15
    protected function newDate(string $format, string $string)
227
    {
228 15
        if (!! $this->getFeedTimezone()) {
229
            return \DateTime::createFromFormat($format, $string, $this->getFeedTimezone());
0 ignored issues
show
Comprehensibility Best Practice introduced by
The expression \DateTime::createFromFor...is->getFeedTimezone()); of type DateTime|false adds false to the return on line 229 which is incompatible with the return type documented by FeedIo\Rule\DateTimeBuilder::newDate of type DateTime. It seems like you forgot to handle an error condition.
Loading history...
230
        }
231
232 15
        return \DateTime::createFromFormat($format, $string);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The expression \DateTime::createFromFormat($format, $string); of type DateTime|false adds false to the return on line 232 which is incompatible with the return type documented by FeedIo\Rule\DateTimeBuilder::newDate of type DateTime. It seems like you forgot to handle an error condition.
Loading history...
233
    }
234
}
235