Issues (35)

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/Traits/OpeningHoursScopes.php (10 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 Webfactor\Laravel\OpeningHours\Traits;
4
5
use Carbon\Carbon;
6
use DateTimeInterface;
7
use Illuminate\Database\Eloquent\Builder;
8
use Webfactor\Laravel\OpeningHours\Entities\Day;
9
use Webfactor\Laravel\OpeningHours\Entities\Time;
10
use Webfactor\Laravel\OpeningHours\Exceptions\InvalidDayName;
11
use Webfactor\Laravel\OpeningHours\Exceptions\InvalidTimeString;
12
13
trait OpeningHoursScopes
14
{
15
    protected $openingHoursRelationName = 'dayOpenTimeRanges';
16
17
    public function scopeWithOpeningHours(Builder $query)
18
    {
19
        return $query->with($this->openingHoursRelationName);
20
    }
21
22
    /**
23
     * Get only open models.
24
     * If no time and day are provided current time and day are used.
25
     * If only time is provided current day is used.
26
     *
27
     * @param Builder $query
28
     * @param Time|string|null $time defaults to current time
29
     * @param string|null $day defaults to current day
30
     * @return Builder|static
0 ignored issues
show
Should the return type not be Builder|\Illuminate\Data...ns\QueriesRelationships?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
31
     * @throws InvalidDayName
32
     * @throws InvalidTimeString
33
     */
34 4
    public function scopeOpen(Builder $query, $time = null, string $day = null)
35
    {
36 4
        $now = Carbon::now();
37 4
        if ($time == null) {
0 ignored issues
show
It seems like you are loosely comparing $time of type Webfactor\Laravel\Openin...tities\Time|string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
38 1
            $time = Time::fromDateTime($now);
39 3
        } elseif (is_string($time)) {
40 2
            $time = Time::fromString($time);
41
        }
42
43 4
        if ($day == null) {
0 ignored issues
show
It seems like you are loosely comparing $day of type null|string against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
44 2
            $day = Day::onDateTime($now);
45
        } else {
46 2
            if (! Day::isValid($day)) {
47
                throw new InvalidDayName();
48
            }
49
        }
50
51 4
        return $query->whereHas($this->openingHoursRelationName, function (Builder $subquery) use ($day, $time) {
52
            $subquery
53 4
                ->where('day', $day)
54 4
                ->where('start', '<=', $time)
55 4
                ->where('end', '>=', $time);
56 4
        });
57
    }
58
59
    /**
60
     * Get only closed models.
61
     * If no time and day are provided current time and day are used.
62
     * If only time is provided current day is used.
63
     *
64
     * @param Builder $query
65
     * @param Time|string|null $time defaults to current time
66
     * @param string|null $day defaults to current day
67
     * @return Builder|static
0 ignored issues
show
Should the return type not be Builder|\Illuminate\Data...ns\QueriesRelationships?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
68
     * @throws InvalidDayName
69
     * @throws InvalidTimeString
70
     */
71 4
    public function scopeClosed(Builder $query, $time = null, string $day = null)
72
    {
73 4
        $now = Carbon::now();
74 4
        if ($time == null) {
0 ignored issues
show
It seems like you are loosely comparing $time of type Webfactor\Laravel\Openin...tities\Time|string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
75 1
            $time = Time::fromDateTime($now);
76 3
        } elseif (is_string($time)) {
77 2
            $time = Time::fromString($time);
78
        }
79
80 4
        if ($day == null) {
0 ignored issues
show
It seems like you are loosely comparing $day of type null|string against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
81 2
            $day = Day::onDateTime($now);
82
        } else {
83 2
            if (! Day::isValid($day)) {
84
                throw new InvalidDayName();
85
            }
86
        }
87
88 4
        return $query->whereDoesntHave($this->openingHoursRelationName, function (Builder $subquery) use ($day, $time) {
89
            $subquery
90 4
                ->where('day', $day)
91 4
                ->where('start', '<=', $time)
92 4
                ->where('end', '>=', $time);
93 4
        });
94
    }
95
96
    /**
97
     * Get all models open at the specified day at random time
98
     *
99
     * @param Builder $query
100
     * @param string $day
101
     * @return Builder|static
0 ignored issues
show
Should the return type not be Builder|\Illuminate\Data...ns\QueriesRelationships?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
102
     * @throws InvalidDayName
103
     */
104 1 View Code Duplication
    public function scopeOpenOn(Builder $query, string $day)
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...
105
    {
106 1
        if (! Day::isValid($day)) {
107
            throw new InvalidDayName();
108
        }
109
110 1
        return $query->whereHas($this->openingHoursRelationName, function (Builder $subquery) use ($day) {
111 1
            $subquery->where('day', $day);
112 1
        });
113
    }
114
115
    /**
116
     * Get all models closed at the specified day
117
     *
118
     * @param Builder $query
119
     * @param string $day
120
     * @return Builder|static
0 ignored issues
show
Should the return type not be Builder|\Illuminate\Data...ns\QueriesRelationships?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
121
     * @throws InvalidDayName
122
     */
123 1 View Code Duplication
    public function scopeClosedOn(Builder $query, string $day)
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...
124
    {
125 1
        if (! Day::isValid($day)) {
126
            throw new InvalidDayName();
127
        }
128
129 1
        return $query->whereDoesntHave($this->openingHoursRelationName, function (Builder $subquery) use ($day) {
130 1
            $subquery->where('day', $day);
131 1
        });
132
    }
133
134
    /**
135
     * Get all models open at the specified DateTime
136
     *
137
     * @param Builder $query
138
     * @param DateTimeInterface $date
139
     * @return mixed
140
     */
141 1
    public function scopeOpenAt(Builder $query, DateTimeInterface $date)
142
    {
143 1
        return $query->open(Time::fromDateTime($date), Day::onDateTime($date));
144
    }
145
146
    /**
147
     * Get all models closed at the specified DateTime
148
     *
149
     * @param Builder $query
150
     * @param DateTimeInterface $date
151
     * @return mixed
152
     */
153 1
    public function scopeClosedAt(Builder $query, DateTimeInterface $date)
154
    {
155 1
        return $query->closed(Time::fromDateTime($date), Day::onDateTime($date));
156
    }
157
}
158