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

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/Entity/Annotation/AnnotationBuilder.php (4 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
namespace Newage\Annotations\Entity\Annotation;
4
5
use Newage\Annotations\Config\AnnotationBuilderConfig;
6
use Newage\Annotations\Mapper\Annotation\EntityAnnotationListener;
7
use Newage\Annotations\Mapper\Annotation\PropertyAnnotationListener;
8
use Newage\Annotations\Mapper\MapperBuilder;
9
use Zend\Code\Annotation\AnnotationCollection;
10
use Zend\Code\Annotation\AnnotationManager;
11
use Zend\Code\Annotation\Parser;
12
use Zend\Code\Reflection\ClassReflection;
13
use Zend\Code\Reflection\PropertyReflection;
14
use Zend\EventManager\EventManager;
15
use Zend\EventManager\EventManagerAwareInterface;
16
use Zend\EventManager\EventManagerInterface;
17
use Zend\Stdlib\ArrayObject;
18
19
/**
20
 * @package Newage\Annotations\Mapper\Annotation
21
 */
22
class AnnotationBuilder implements EventManagerAwareInterface, AnnotationBuilderInterface
23
{
24
    /**
25
     * @var MapperBuilder
26
     */
27
    protected $mapperBuilder;
28
29
    /**
30
     * @var Parser\DoctrineAnnotationParser
31
     */
32
    protected $annotationParser;
33
34
    /**
35
     * @var AnnotationManager
36
     */
37
    protected $annotationManager;
38
39
    /**
40
     * @var EventManagerInterface
41
     */
42
    protected $events;
43
44
    /**
45
     * @var AnnotationBuilderConfig
46
     */
47
    private $config;
48
49
    /**
50
     * @var array Default annotations to register
51
     */
52
    protected $defaultAnnotations = [
53
        'Table',
54
        'Id',
55
        'Column',
56
        'OneToOne',
57
        'OneToMany',
58
        'ManyToOne',
59
        'ManyToMany',
60
    ];
61
62
    /**
63
     * AnnotationBuilder constructor.
64
     *
65
     * @param AnnotationBuilderConfig $config
66
     * @param MapperBuilder           $mapperBuilder
67
     */
68
    public function __construct(AnnotationBuilderConfig $config, MapperBuilder $mapperBuilder)
69
    {
70
        $this->mapperBuilder = $mapperBuilder;
71
        $this->config = $config;
72
    }
73
74
    /**
75
     * Create annotations from entity
76
     * @return ArrayObject
77
     */
78
    public function create()
79
    {
80
        $spec = new ArrayObject(['entities' => []]);
81
        $factory = $this->mapperBuilder;
82
        $modelsOptions = $this->config->getConfig('models');
83
        foreach ($modelsOptions as $modelOption) {
84
            foreach (new \FilesystemIterator($modelOption['path']) as $file) {
85
                $entityName = substr($file->getFileName(), 0, -4);
86
                $entityNamespace = '\\' . $modelOption['namespace'] . '\\' . $entityName;
87
88
                if (!class_exists($entityNamespace)) {
89
                    continue;
90
                }
91
                
92
                $entity = new $entityNamespace();
93
                $spec['entities'][] = $this->getSpecification($entity);
94
            }
95
        };
96
        $factory->create($spec);
97
    }
98
99
    /**
100
     * @param $entity
101
     * @return ArrayObject
102
     * @internal param $spec
103
     */
104
    protected function getSpecification($entity)
105
    {
106
        $annotationManager = $this->getAnnotationManager();
107
108
        $spec = new ArrayObject();
109
        $reflection  = new ClassReflection($entity);
110
        $annotations = $reflection->getAnnotations($annotationManager);
111
112
        if ($annotations instanceof AnnotationCollection) {
113
            $this->configureEntity($annotations, $reflection, $spec);
114
        }
115
116
        foreach ($reflection->getProperties() as $property) {
117
            $annotations = $property->getAnnotations($annotationManager);
118
119
            if ($annotations instanceof AnnotationCollection) {
120
                $this->configureProperty($annotations, $property, $spec);
121
            }
122
        }
123
124
        return $spec;
125
    }
126
127
    /**
128
     * @param AnnotationCollection $annotations
129
     * @param ClassReflection      $reflection
130
     * @param ArrayObject          $spec
131
     */
132
    protected function configureEntity($annotations, $reflection, $spec)
133
    {
134
        $name = $reflection->getName();
135
        $spec['entity'] = $name;
136
137
        $events = $this->getEventManager();
138 View Code Duplication
        foreach ($annotations as $annotation) {
0 ignored issues
show
This code seems to be duplicated across 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...
139
            $events->trigger(
140
                __FUNCTION__,
141
                $this,
142
                [
143
                    'annotation' => $annotation,
144
                    'spec'       => $spec,
145
                    'name'       => $name
146
                ]
147
            );
148
        }
149
    }
150
151
    /**
152
     * @param AnnotationCollection $annotations
153
     * @param PropertyReflection   $reflection
154
     * @param ArrayObject          $spec
155
     */
156
    protected function configureProperty($annotations, $reflection, $spec)
157
    {
158
        $name = $reflection->getName();
159
        $propertySpec = new ArrayObject([
160
            'property' => $name
161
        ]);
162
163
        $events = $this->getEventManager();
164 View Code Duplication
        foreach ($annotations as $annotation) {
0 ignored issues
show
This code seems to be duplicated across 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
            $events->trigger(
166
                __FUNCTION__,
167
                $this,
168
                [
169
                    'annotation' => $annotation,
170
                    'spec'       => $propertySpec,
171
                    'name'       => $name
172
                ]
173
            );
174
        }
175
176
        if (!isset($spec['properties'])) {
177
            $spec['properties'] = [];
178
        }
179
        $spec['properties'][] = $propertySpec;
180
    }
181
182
    /**
183
     * Set event manager instance
184
     *
185
     * @param  EventManagerInterface $events
186
     * @return AnnotationBuilder
187
     */
188
    public function setEventManager(EventManagerInterface $events)
189
    {
190
        $events->setIdentifiers([
191
            __CLASS__,
192
            get_class($this),
193
        ]);
194
        $events->attach(new EntityAnnotationListener());
0 ignored issues
show
new \Newage\Annotations\...ityAnnotationListener() is of type object<Newage\Annotation...tityAnnotationListener>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
195
        $events->attach(new PropertyAnnotationListener());
0 ignored issues
show
new \Newage\Annotations\...rtyAnnotationListener() is of type object<Newage\Annotation...ertyAnnotationListener>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
196
        $this->events = $events;
197
        return $this;
198
    }
199
200
    /**
201
     * Get event manager
202
     *
203
     * @return EventManagerInterface
204
     */
205
    public function getEventManager()
206
    {
207
        if (null === $this->events) {
208
            $this->setEventManager(new EventManager());
209
        }
210
        return $this->events;
211
    }
212
213
    /**
214
     * @return mixed
215
     */
216
    public function getAnnotationManager()
217
    {
218
        if (null === $this->annotationManager) {
219
            $this->setAnnotationManager(new AnnotationManager());
220
        }
221
222
        return $this->annotationManager;
223
    }
224
225
    /**
226
     * @param mixed $annotationManager
227
     */
228
    public function setAnnotationManager(AnnotationManager $annotationManager)
229
    {
230
        $parser = $this->getAnnotationParser();
231
        foreach ($this->defaultAnnotations as $annotationName) {
232
            $class = __NAMESPACE__ . '\\' . $annotationName;
233
            $parser->registerAnnotation($class);
234
        }
235
        $annotationManager->attach($parser);
236
        $this->annotationManager = $annotationManager;
237
    }
238
239
    /**
240
     * @return \Zend\Code\Annotation\Parser\DoctrineAnnotationParser
241
     */
242
    public function getAnnotationParser()
243
    {
244
        if (null === $this->annotationParser) {
245
            $this->annotationParser = new Parser\DoctrineAnnotationParser();
246
        }
247
248
        return $this->annotationParser;
249
    }
250
}
251