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/Ticketable.php (5 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 Illuminate\Database\Eloquent\Model;
8
use Rinvex\Bookings\Models\TicketableBooking;
9
use Illuminate\Database\Eloquent\Relations\MorphMany;
10
11
trait Ticketable
12
{
13
    /**
14
     * Register a saved model event with the dispatcher.
15
     *
16
     * @param \Closure|string $callback
17
     *
18
     * @return void
19
     */
20
    abstract public static function saved($callback);
21
22
    /**
23
     * Register a deleted model event with the dispatcher.
24
     *
25
     * @param \Closure|string $callback
26
     *
27
     * @return void
28
     */
29
    abstract public static function deleted($callback);
30
31
    /**
32
     * Define a polymorphic one-to-many relationship.
33
     *
34
     * @param string $related
35
     * @param string $name
36
     * @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...
37
     * @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...
38
     * @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...
39
     *
40
     * @return \Illuminate\Database\Eloquent\Relations\MorphMany
41
     */
42
    abstract public function morphMany($related, $name, $type = null, $id = null, $localKey = null);
43
44
    /**
45
     * Get the booking model name.
46
     *
47
     * @return string
48
     */
49
    abstract public function getBookingModel(): string;
50
51
    /**
52
     * Get the ticket model name.
53
     *
54
     * @return string
55
     */
56
    abstract public function getTicketModel(): string;
57
58
    /**
59
     * Boot the Ticketable trait for the model.
60
     *
61
     * @return void
62
     */
63
    public static function bootTicketable()
64
    {
65
        static::deleted(function (self $model) {
66
            $model->bookings()->delete();
67
        });
68
    }
69
70
    /**
71
     * Attach the given bookings to the model.
72
     *
73
     * @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...
74
     * @param mixed                                                                         $bookings
75
     *
76
     * @return void
77
     */
78
    public function setBookingsAttribute($bookings): void
79
    {
80
        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...
81
            $this->bookings()->sync($bookings);
82
        });
83
    }
84
85
    /**
86
     * The resource may have many tickets.
87
     *
88
     * @return \Illuminate\Database\Eloquent\Relations\MorphMany
89
     */
90
    public function tickets(): MorphMany
91
    {
92
        return $this->morphMany(static::getTicketModel(), 'ticketable');
93
    }
94
95
    /**
96
     * The resource may have many bookings.
97
     *
98
     * @return \Illuminate\Database\Eloquent\Relations\MorphMany
99
     */
100
    public function bookings(): MorphMany
101
    {
102
        return $this->morphMany(static::getBookingModel(), 'ticketable');
103
    }
104
105
    /**
106
     * Get bookings by the given customer.
107
     *
108
     * @param \Illuminate\Database\Eloquent\Model $customer
109
     *
110
     * @return \Illuminate\Database\Eloquent\Relations\MorphMany
111
     */
112
    public function bookingsBy(Model $customer): MorphMany
113
    {
114
        return $this->bookings()->where('customer_type', $customer->getMorphClass())->where('customer_id', $customer->getKey());
115
    }
116
117
    /**
118
     * Book the model for the given customer at the given dates with the given price.
119
     *
120
     * @param \Illuminate\Database\Eloquent\Model $customer
121
     * @param float                               $paid
122
     * @param string                              $currency
123
     *
124
     * @return \Rinvex\Bookings\Models\TicketableBooking
125
     */
126
    public function newBooking(Model $customer, float $paid, string $currency): TicketableBooking
127
    {
128
        return $this->bookings()->create([
129
            'ticketable_id' => static::getKey(),
130
            'ticketable_type' => static::getMorphClass(),
131
            'customer_id' => $customer->getKey(),
132
            'customer_type' => $customer->getMorphClass(),
133
            'paid' => $paid,
134
            'currency' => $currency,
135
        ]);
136
    }
137
}
138