GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Issues (5)

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/HasRelatedContent.php (5 issues)

Labels
Severity

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 Spatie\Relatable;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Support\Collection;
7
use Illuminate\Database\Eloquent\Relations\MorphMany;
8
9
/**
10
 * @mixin \Illuminate\Database\Eloquent\Model
11
 *
12
 * @property \Illuminate\Support\Collection $related
13
 * @property \Illuminate\Support\Collection $relatables
14
 */
15
trait HasRelatedContent
16
{
17
    /** @var \Illuminate\Support\Collection|null */
18
    protected $relatableCache;
19
20
    public function relatables() : MorphMany
21
    {
22
        return $this->morphMany(Relatable::class, 'source');
0 ignored issues
show
It seems like morphMany() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
23
    }
24
25
    /**
26
     * Returns a Collection of all related models. The results are cached as a property on the
27
     * model, you reload them using the `loadRelated` method.
28
     *
29
     * @return \Illuminate\Support\Collection
30
     */
31
    public function getRelatedAttribute() : Collection
32
    {
33
        if ($this->relatableCache === null) {
34
            $this->loadRelated();
35
        }
36
37
        return $this->relatableCache;
38
    }
39
40
    public function loadRelated($reloadRelatables = true) : Collection
41
    {
42
        if ($reloadRelatables) {
43
            $this->load('relatables');
0 ignored issues
show
It seems like load() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
44
        }
45
46
        return $this->relatableCache = $this->relatables
47
            ->groupBy(function (Relatable $relatable) {
48
                return $this->getActualClassNameForMorph($relatable->related_type);
0 ignored issues
show
It seems like getActualClassNameForMorph() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
49
            })
50
            ->flatMap(function (Collection $typeGroup, string $type) {
51
                return $type::whereIn('id', $typeGroup->pluck('related_id'))->get();
52
            });
53
    }
54
55
    public function hasRelated() : bool
56
    {
57
        return ! $this->related->isEmpty();
58
    }
59
60
    /**
61
     * The `$item` parameter must be an Eloquent model or an ID. If you provide an ID, the model's
62
     * morph type must be specified as a second parameter.
63
     *
64
     * @param \Illuminate\Database\Eloquent\Model|int $item
65
     * @param string|null $type
66
     *
67
     * @return \Spatie\Relatable\Relatable
68
     */
69
    public function relate($item, string $type = '') : Relatable
70
    {
71
        return Relatable::firstOrCreate(
72
            $this->getRelatableValues($item, $type)
73
        );
74
    }
75
76
    /**
77
     * The `$item` parameter must be an Eloquent model or an ID. If you provide an ID, the model's
78
     * morph type must be specified as a second parameter.
79
     *
80
     * @param \Illuminate\Database\Eloquent\Model|int $item
81
     * @param string|null $type
82
     *
83
     * @return int
84
     */
85
    public function unrelate($item, string $type = '') : int
86
    {
87
        return Relatable::where($this->getRelatableValues($item, $type))->delete();
88
    }
89
90
    /**
91
     * The `$items` parameter can either contain an Eloquent collection of models, or an array
92
     * with the shape of [['id' => int, 'type' => string], ...].
93
     *
94
     * @param \Illuminate\Database\Eloquent\Collection|array $items
95
     * @param bool $detaching
96
     */
97
    public function syncRelated($items, $detaching = true)
98
    {
99
        $items = $this->getSyncRelatedValues($items);
100
101
        $current = $this->relatables->map(function (Relatable $relatable) {
102
            return $relatable->getRelatedValues();
103
        });
104
105
        $items->each(function (array $values) {
106
            $this->relate($values['id'], $values['type']);
107
        });
108
109
        if (!$detaching) {
110
            return;
111
        }
112
113
        $current
114
            ->filter(function (array $values) use ($items) {
115
                return ! $items->contains($values);
116
            })
117
            ->each(function (array $values) {
118
                $this->unrelate($values['id'], $values['type']);
119
            });
120
    }
121
122
    protected function getSyncRelatedValues($items) : Collection
123
    {
124
        if ($items instanceof Collection) {
125
            return $items->map(function (Model $item) : array {
126
                return [
127
                    'type' => $item->getMorphClass(),
128
                    'id' => $item->getKey(),
129
                ];
130
            });
131
        }
132
133
        return collect($items);
134
    }
135
136
    /**
137
     * @param \Illuminate\Database\Eloquent\Model|int $item
138
     * @param string|null $type
139
     *
140
     * @return array
141
     */
142
    protected function getRelatableValues($item, string $type = '') : array
143
    {
144
        if (! $item instanceof Model && empty($type)) {
145
            throw new \InvalidArgumentException(
146
                'If an id is specified as an item, the type isn\'t allowed to be empty.'
147
            );
148
        }
149
150
        return [
151
            'source_id' => $this->getKey(),
0 ignored issues
show
It seems like getKey() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
152
            'source_type' => $this->getMorphClass(),
0 ignored issues
show
It seems like getMorphClass() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
153
            'related_id' => $item instanceof Model ? $item->getKey() : $item,
154
            'related_type' => $item instanceof Model ? $item->getMorphClass() : $type,
155
        ];
156
    }
157
}
158