Issues (40)

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/Traits/Bookable.php (9 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
declare(strict_types=1);
4
5
namespace Rinvex\Bookings\Traits;
6
7
use Carbon\Carbon;
8
use Illuminate\Database\Eloquent\Model;
9
use Rinvex\Bookings\Models\BookableBooking;
10
use Illuminate\Database\Eloquent\Relations\MorphMany;
11
12
trait Bookable
13
{
14
    use BookingScopes;
15
16
    /**
17
     * Register a saved model event with the dispatcher.
18
     *
19
     * @param \Closure|string $callback
20
     *
21
     * @return void
22
     */
23
    abstract public static function saved($callback);
24
25
    /**
26
     * Register a deleted model event with the dispatcher.
27
     *
28
     * @param \Closure|string $callback
29
     *
30
     * @return void
31
     */
32
    abstract public static function deleted($callback);
33
34
    /**
35
     * Define a polymorphic one-to-many relationship.
36
     *
37
     * @param string $related
38
     * @param string $name
39
     * @param string $type
0 ignored issues
show
Should the type for parameter $type not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
40
     * @param string $id
0 ignored issues
show
Should the type for parameter $id not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
41
     * @param string $localKey
0 ignored issues
show
Should the type for parameter $localKey not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
42
     *
43
     * @return \Illuminate\Database\Eloquent\Relations\MorphMany
44
     */
45
    abstract public function morphMany($related, $name, $type = null, $id = null, $localKey = null);
46
47
    /**
48
     * Get the booking model name.
49
     *
50
     * @return string
51
     */
52
    abstract public static function getBookingModel(): string;
53
54
    /**
55
     * Get the rate model name.
56
     *
57
     * @return string
58
     */
59
    abstract public static function getRateModel(): string;
60
61
    /**
62
     * Get the availability model name.
63
     *
64
     * @return string
65
     */
66
    abstract public static function getAvailabilityModel(): string;
67
68
    /**
69
     * Boot the Bookable trait for the model.
70
     *
71
     * @return void
72
     */
73
    public static function bootBookable()
74
    {
75
        static::deleted(function (self $model) {
76
            $model->bookings()->delete();
77
        });
78
    }
79
80
    /**
81
     * Attach the given bookings to the model.
82
     *
83
     * @param \Illuminate\Database\Eloquent\Collection|\Illuminate\Support\Collection|array $ids
0 ignored issues
show
There is no parameter named $ids. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
84
     * @param mixed                                                                         $bookings
85
     *
86
     * @return void
87
     */
88
    public function setBookingsAttribute($bookings): void
89
    {
90
        static::saved(function (self $model) use ($bookings) {
0 ignored issues
show
The parameter $model is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
91
            $this->bookings()->sync($bookings);
92
        });
93
    }
94
95
    /**
96
     * Attach the given rates to the model.
97
     *
98
     * @param \Illuminate\Database\Eloquent\Collection|\Illuminate\Support\Collection|array $ids
0 ignored issues
show
There is no parameter named $ids. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
99
     * @param mixed                                                                         $rates
100
     *
101
     * @return void
102
     */
103
    public function setRatesAttribute($rates): void
104
    {
105
        static::saved(function (self $model) use ($rates) {
0 ignored issues
show
The parameter $model is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
106
            $this->rates()->sync($rates);
107
        });
108
    }
109
110
    /**
111
     * Attach the given availabilities to the model.
112
     *
113
     * @param \Illuminate\Database\Eloquent\Collection|\Illuminate\Support\Collection|array $ids
0 ignored issues
show
There is no parameter named $ids. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
114
     * @param mixed                                                                         $availabilities
115
     *
116
     * @return void
117
     */
118
    public function setAvailabilitiesAttribute($availabilities): void
119
    {
120
        static::saved(function (self $model) use ($availabilities) {
0 ignored issues
show
The parameter $model is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
121
            $this->availabilities()->sync($availabilities);
122
        });
123
    }
124
125
    /**
126
     * The resource may have many bookings.
127
     *
128
     * @return \Illuminate\Database\Eloquent\Relations\MorphMany
129
     */
130
    public function bookings(): MorphMany
131
    {
132
        return $this->morphMany(static::getBookingModel(), 'bookable');
133
    }
134
135
    /**
136
     * Get bookings by the given customer.
137
     *
138
     * @param \Illuminate\Database\Eloquent\Model $customer
139
     *
140
     * @return \Illuminate\Database\Eloquent\Relations\MorphMany
141
     */
142
    public function bookingsBy(Model $customer): MorphMany
143
    {
144
        return $this->bookings()->where('customer_type', $customer->getMorphClass())->where('customer_id', $customer->getKey());
145
    }
146
147
    /**
148
     * The resource may have many availabilities.
149
     *
150
     * @return \Illuminate\Database\Eloquent\Relations\MorphMany
151
     */
152
    public function availabilities(): MorphMany
153
    {
154
        return $this->morphMany(static::getAvailabilityModel(), 'bookable');
155
    }
156
157
    /**
158
     * The resource may have many rates.
159
     *
160
     * @return \Illuminate\Database\Eloquent\Relations\MorphMany
161
     */
162
    public function rates(): MorphMany
163
    {
164
        return $this->morphMany(static::getRateModel(), 'bookable');
165
    }
166
167
    /**
168
     * Book the model for the given customer at the given dates with the given price.
169
     *
170
     * @param \Illuminate\Database\Eloquent\Model $customer
171
     * @param string                              $startsAt
172
     * @param string                              $endsAt
173
     *
174
     * @return \Rinvex\Bookings\Models\BookableBooking
175
     */
176
    public function newBooking(Model $customer, string $startsAt, string $endsAt): BookableBooking
177
    {
178
        return $this->bookings()->create([
179
            'bookable_id' => static::getKey(),
180
            'bookable_type' => static::getMorphClass(),
181
            'customer_id' => $customer->getKey(),
182
            'customer_type' => $customer->getMorphClass(),
183
            'starts_at' => (new Carbon($startsAt))->toDateTimeString(),
184
            'ends_at' => (new Carbon($endsAt))->toDateTimeString(),
185
        ]);
186
    }
187
}
188