Issues (74)

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.

Extension/BuiltInFunctionsExtension.php (7 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 Netdudes\DataSourceryBundle\Extension;
4
5
use Netdudes\DataSourceryBundle\Util\CurrentDateTimeProvider;
6
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
7
8
class BuiltInFunctionsExtension implements UqlExtensionInterface
9
{
10
    /**
11
     * @var TokenStorageInterface
12
     */
13
    private $tokenStorage;
14
15
    /**
16
     * @var CurrentDateTimeProvider
17
     */
18
    private $dateTimeProvider;
19
20
    /**
21
     * @param TokenStorageInterface   $tokenStorage
22
     * @param CurrentDateTimeProvider $dateTimeProvider
23
     */
24
    public function __construct(TokenStorageInterface $tokenStorage, CurrentDateTimeProvider $dateTimeProvider)
25
    {
26
        $this->tokenStorage = $tokenStorage;
27
        $this->dateTimeProvider = $dateTimeProvider;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function getFunctions()
34
    {
35
        return [
36
            new UqlFunction('now', $this, 'now'),
37
            new UqlFunction('startOfDay', $this, 'startOfDay'),
38
            new UqlFunction('startOfWeek', $this, 'startOfWeek'),
39
            new UqlFunction('startOfMonth', $this, 'startOfMonth'),
40
            new UqlFunction('startOfYear', $this, 'startOfYear'),
41
            new UqlFunction('currentUser', $this, 'currentUser'),
42
            new UqlFunction('random', $this, 'random')
43
        ];
44
    }
45
46
    /**
47
     * Gets the current timestamp, with an offset string
48
     *
49
     * @param string $offset
50
     *
51
     * @return string
52
     * @throws \Exception
53
     */
54
    public function now($offset = null)
55
    {
56
        $now = clone $this->dateTimeProvider->get();
57
58
        if ($offset) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $offset of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
59
            $interval = \DateInterval::createFromDateString($offset);
60
            $now->add($interval);
61
62
            if ($now == $this->dateTimeProvider->get()) {
63
                // The date didn't change therefore we assume the given offset is not valid
64
                throw new \Exception($offset . ' is not a valid date/time interval.');
65
            }
66
        }
67
68
        return $now->format(\DateTime::ISO8601);
69
    }
70
71
    /**
72
     * Gets a date with the hour 00:00:00
73
     *
74
     * @param string $date
75
     *
76
     * @return string
77
     * @throws \Exception
78
     */
79
    public function startOfDay($date = null)
80
    {
81
        $now = clone $this->dateTimeProvider->get();
82
83
        if ($date) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $date of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
84
            $now = $this->modifyDate($now, $date);
85
        }
86
87
        $now->setTime(0, 0, 0);
88
89
        return $now->format(\DateTime::ISO8601);
90
    }
91
92
    /**
93
     * Gets the Monday of the week for the specified date with the hour 00:00:00
94
     *
95
     * @param string $date
96
     *
97
     * @return string
98
     * @throws \Exception
99
     */
100 View Code Duplication
    public function startOfWeek($date = null)
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...
101
    {
102
        $now = clone $this->dateTimeProvider->get();
103
104
        if ($date) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $date of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
105
            $now = $this->modifyDate($now, $date);
106
        }
107
108
        $year = $now->format('o'); // o = ISO-8601 year number
109
        $week = $now->format('W'); // W = ISO-8601 week number of year, weeks starting on Monday
110
111
        $startOfWeek = $now->setISODate($year, $week);
112
        $startOfWeek->setTime(0, 0, 0);
113
114
        return $startOfWeek->format(\DateTime::ISO8601);
115
    }
116
117
    /**
118
     * Gets the first day of the month for the specified date with the hour 00:00:00
119
     *
120
     * @param string $date
121
     *
122
     * @return string
123
     * @throws \Exception
124
     */
125 View Code Duplication
    public function startOfMonth($date = null)
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...
126
    {
127
        $now = clone $this->dateTimeProvider->get();
128
129
        if ($date) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $date of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
130
            $now = $this->modifyDate($now, $date);
131
        }
132
133
        $year = $now->format('Y');
134
        $month = $now->format('m');
135
136
        $startOfMonth = $now->setDate($year, $month, 1);
137
        $startOfMonth->setTime(0, 0, 0);
138
139
        return $startOfMonth->format(\DateTime::ISO8601);
140
    }
141
142
    /**
143
     * Gets the first day of the year for the specified date with the hour 00:00:00
144
     *
145
     * @param string $date
146
     *
147
     * @return string
148
     * @throws \Exception
149
     */
150
    public function startOfYear($date = null)
151
    {
152
        $now = clone $this->dateTimeProvider->get();
153
154
        if ($date) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $date of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
155
            $now = $this->modifyDate($now, $date);
156
        }
157
158
        $year = $now->format('Y');
159
160
        $startOfYear = $now->setDate($year, 1, 1);
161
        $startOfYear->setTime(0, 0, 0);
162
163
        return $startOfYear->format(\DateTime::ISO8601);
164
    }
165
166
    /**
167
     * Gets the current users' username
168
     *
169
     * @return string
170
     */
171
    public function currentUser()
172
    {
173
        return $this->tokenStorage->getToken()->getUsername();
174
    }
175
176
    /**
177
     * Gets a random value between $min and $max
178
     *
179
     * @param int $min
180
     * @param int $max
181
     *
182
     * @return int
183
     */
184
    public function random($min = 0, $max = 10)
185
    {
186
        return rand($min, $max);
187
    }
188
189
    /**
190
     * @param \DateTime $date
191
     * @param string    $change
192
     *
193
     * @return \DateTime
194
     * @throws \Exception
195
     */
196
    private function modifyDate(\DateTime $date, $change)
197
    {
198
        try {
199
            $date->modify($change);
200
        } catch (\Exception $e) {
201
            throw new \Exception($change . ' is not a valid date or date offset.');
202
        }
203
204
        return ($date);
205
    }
206
}
207