Issues (19)

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/Collection/ModelCollection.php (6 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 Chubbyphp\Model\Collection;
6
7
use Chubbyphp\Model\ModelInterface;
8
use Chubbyphp\Model\ModelSortTrait;
9
10
final class ModelCollection implements ModelCollectionInterface
11
{
12
    use ModelSortTrait;
13
14
    /**
15
     * @var string
16
     */
17
    private $modelClass;
18
19
    /**
20
     * @var string
21
     */
22
    private $foreignField;
23
24
    /**
25
     * @var string
26
     */
27
    private $foreignId;
28
29
    /**
30
     * @var array|null
31
     */
32
    private $orderBy;
33
34
    /**
35
     * @var ModelInterface[]|array
36
     */
37
    private $models;
38
39
    /**
40
     * @var \ReflectionProperty
41
     */
42
    private $propertyReflection;
43
44
    /**
45
     * @param string     $modelClass
46
     * @param string     $foreignField
47
     * @param string     $foreignId
48
     * @param array|null $orderBy
49
     */
50 13 View Code Duplication
    public function __construct(
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...
51
        string $modelClass,
52
        string $foreignField,
53
        string $foreignId,
54
        array $orderBy = null
55
    ) {
56 13
        $this->modelClass = $modelClass;
57 13
        $this->foreignField = $foreignField;
58 13
        $this->foreignId = $foreignId;
59 13
        $this->orderBy = $orderBy;
60
61 13
        $this->models = [];
62
63 13
        $this->propertyReflection = new \ReflectionProperty($this->modelClass, $this->foreignField);
64 13
        $this->propertyReflection->setAccessible(true);
65 13
    }
66
67
    /**
68
     * @param ModelInterface $model
69
     *
70
     * @return ModelCollectionInterface
71
     */
72 1 View Code Duplication
    public function addModel(ModelInterface $model): ModelCollectionInterface
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...
73
    {
74 1
        $this->propertyReflection->setValue($model, $this->foreignId);
75
76 1
        $this->models[$model->getId()] = $model;
77
78 1
        return $this;
79
    }
80
81
    /**
82
     * @param ModelInterface $model
83
     *
84
     * @return ModelCollectionInterface
85
     */
86 1 View Code Duplication
    public function removeModel(ModelInterface $model): ModelCollectionInterface
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...
87
    {
88 1
        if (isset($this->models[$model->getId()])) {
89 1
            $this->propertyReflection->setValue($model, null);
90
91 1
            unset($this->models[$model->getId()]);
92
        }
93
94 1
        return $this;
95
    }
96
97
    /**
98
     * @param ModelInterface[]|array $models
99
     *
100
     * @return ModelCollectionInterface
101
     */
102 1 View Code Duplication
    public function setModels(array $models): ModelCollectionInterface
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...
103
    {
104 1
        foreach ($this->models as $model) {
105 1
            $this->removeModel($model);
106
        }
107 1
        foreach ($models as $model) {
108 1
            $this->addModel($model);
109
        }
110
111 1
        return $this;
112
    }
113
114
    /**
115
     * @return ModelInterface[]|array
116
     */
117 3
    public function getModels(): array
118
    {
119 3
        return $this->sort($this->modelClass, array_values($this->models), $this->orderBy);
120
    }
121
122
    /**
123
     * @return ModelInterface[]|array
124
     */
125 1
    public function getInitialModels(): array
126
    {
127 1
        return [];
128
    }
129
130
    /**
131
     * @return \ArrayIterator
132
     */
133 1
    public function getIterator()
134
    {
135 1
        return new \ArrayIterator($this->getModels());
136
    }
137
138
    /**
139
     * @return int
140
     */
141 1
    public function count()
142
    {
143 1
        return count($this->getModels());
144
    }
145
146
    /**
147
     * @return array
148
     */
149 2 View Code Duplication
    public function jsonSerialize(): array
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...
150
    {
151 2
        $this->jsonSerializableOrException();
152
153 1
        $serializedModels = [];
154 1
        foreach ($this->getModels() as $model) {
155 1
            $serializedModels[] = $model->jsonSerialize();
156
        }
157
158 1
        return $serializedModels;
159
    }
160
161
    /**
162
     * @throws \LogicException
163
     */
164 2 View Code Duplication
    private function jsonSerializableOrException()
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...
165
    {
166 2
        $reflectionClass = new \ReflectionClass($this->modelClass);
167 2
        if (!$reflectionClass->implementsInterface(\JsonSerializable::class)) {
168 1
            throw new \LogicException(
169 1
                sprintf('Model %s does not implement %s', $this->modelClass, \JsonSerializable::class)
170
            );
171
        }
172 1
    }
173
174
    /**
175
     * @return string
176
     */
177 1
    public function getForeignField(): string
178
    {
179 1
        return $this->foreignField;
180
    }
181
182
    /**
183
     * @return string
184
     */
185 1
    public function getForeignId(): string
186
    {
187 1
        return $this->foreignId;
188
    }
189
}
190