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 (13)

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/DataTransferObject.php (1 issue)

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
declare(strict_types=1);
4
5
namespace Spatie\DataTransferObject;
6
7
use ReflectionClass;
8
use ReflectionProperty;
9
10
abstract class DataTransferObject
11
{
12
    protected bool $ignoreMissing = false;
0 ignored issues
show
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
13
14
    protected array $exceptKeys = [];
15
16
    protected array $onlyKeys = [];
17
18
    /**
19
     * @param array $parameters
20
     *
21
     * @return \Spatie\DataTransferObject\ImmutableDataTransferObject|static
22
     */
23
    public static function immutable(array $parameters = []): ImmutableDataTransferObject
24
    {
25
        return new ImmutableDataTransferObject(new static($parameters));
26
    }
27
28
    /**
29
     * @param array $arrayOfParameters
30
     *
31
     * @return \Spatie\DataTransferObject\ImmutableDataTransferObject[]|static[]
32
     */
33
    public static function arrayOf(array $arrayOfParameters): array
34
    {
35
        return array_map(
36
            function ($parameters) {
37
                return new static($parameters);
38
            },
39
            $arrayOfParameters
40
        );
41
    }
42
43
    public function __construct(array $parameters = [])
44
    {
45
        $validators = $this->getFieldValidators();
46
47
        $valueCaster = $this->getValueCaster();
48
49
        /** string[] */
50
        $invalidTypes = [];
51
52
        foreach ($validators as $field => $validator) {
53
            if (
54
                ! isset($parameters[$field])
55
                && ! $validator->hasDefaultValue
56
                && ! $validator->isNullable
57
            ) {
58
                throw DataTransferObjectError::uninitialized(
59
                    static::class,
60
                    $field
61
                );
62
            }
63
64
            $value = $parameters[$field] ?? $this->{$field} ?? null;
65
66
            $value = $this->castValue($valueCaster, $validator, $value);
67
68
            if (! $validator->isValidType($value)) {
69
                $invalidTypes[] = DataTransferObjectError::invalidTypeMessage(
70
                    static::class,
71
                    $field,
72
                    $validator->allowedTypes,
73
                    $value
74
                );
75
76
                continue;
77
            }
78
79
            $this->{$field} = $value;
80
81
            unset($parameters[$field]);
82
        }
83
84
        if ($invalidTypes) {
85
            DataTransferObjectError::invalidTypes($invalidTypes);
86
        }
87
88
        if (! $this->ignoreMissing && count($parameters)) {
89
            throw DataTransferObjectError::unknownProperties(array_keys($parameters), static::class);
90
        }
91
    }
92
93
    public function all(): array
94
    {
95
        $data = [];
96
97
        $class = new ReflectionClass(static::class);
98
99
        $properties = $class->getProperties(ReflectionProperty::IS_PUBLIC);
100
101
        foreach ($properties as $reflectionProperty) {
102
            // Skip static properties
103
            if ($reflectionProperty->isStatic()) {
104
                continue;
105
            }
106
107
            $data[$reflectionProperty->getName()] = $reflectionProperty->getValue($this);
108
        }
109
110
        return $data;
111
    }
112
113
    /**
114
     * @param string ...$keys
115
     *
116
     * @return static
117
     */
118
    public function only(string ...$keys): DataTransferObject
119
    {
120
        $dataTransferObject = clone $this;
121
122
        $dataTransferObject->onlyKeys = [...$this->onlyKeys, ...$keys];
123
124
        return $dataTransferObject;
125
    }
126
127
    /**
128
     * @param string ...$keys
129
     *
130
     * @return static
131
     */
132
    public function except(string ...$keys): DataTransferObject
133
    {
134
        $dataTransferObject = clone $this;
135
136
        $dataTransferObject->exceptKeys = [...$this->exceptKeys, ...$keys];
137
138
        return $dataTransferObject;
139
    }
140
141
    public function toArray(): array
142
    {
143
        if (count($this->onlyKeys)) {
144
            $array = Arr::only($this->all(), $this->onlyKeys);
145
        } else {
146
            $array = Arr::except($this->all(), $this->exceptKeys);
147
        }
148
149
        $array = $this->parseArray($array);
150
151
        return $array;
152
    }
153
154
    protected function parseArray(array $array): array
155
    {
156
        foreach ($array as $key => $value) {
157
            if (
158
                $value instanceof DataTransferObject
159
                || $value instanceof DataTransferObjectCollection
160
            ) {
161
                $array[$key] = $value->toArray();
162
163
                continue;
164
            }
165
166
            if (! is_array($value)) {
167
                continue;
168
            }
169
170
            $array[$key] = $this->parseArray($value);
171
        }
172
173
        return $array;
174
    }
175
176
    /**
177
     * @param \ReflectionClass $class
178
     *
179
     * @return \Spatie\DataTransferObject\FieldValidator[]
180
     */
181
    protected function getFieldValidators(): array
182
    {
183
        return DTOCache::resolve(static::class, function () {
184
            $class = new ReflectionClass(static::class);
185
186
            $properties = [];
187
188
            foreach ($class->getProperties(ReflectionProperty::IS_PUBLIC) as $reflectionProperty) {
189
                // Skip static properties
190
                if ($reflectionProperty->isStatic()) {
191
                    continue;
192
                }
193
194
                $field = $reflectionProperty->getName();
195
196
                $properties[$field] = FieldValidator::fromReflection($reflectionProperty);
197
            }
198
199
            return $properties;
200
        });
201
    }
202
203
    /**
204
     * @param \Spatie\DataTransferObject\ValueCaster $valueCaster
205
     * @param \Spatie\DataTransferObject\FieldValidator $fieldValidator
206
     * @param mixed $value
207
     *
208
     * @return mixed
209
     */
210
    protected function castValue(ValueCaster $valueCaster, FieldValidator $fieldValidator, $value)
211
    {
212
        if (is_array($value)) {
213
            return $valueCaster->cast($value, $fieldValidator);
214
        }
215
216
        return $value;
217
    }
218
219
    protected function getValueCaster(): ValueCaster
220
    {
221
        return new ValueCaster();
222
    }
223
}
224