Issues (37)

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.

lib/Metadata/AbstractMetadataParser.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
namespace Flying\Struct\Metadata;
4
5
use Flying\Struct\ConfigurationManager;
6
use Flying\Struct\Exception;
7
use Flying\Struct\Property\PropertyInterface;
8
use Flying\Struct\StructInterface;
9
10
/**
11
 * Base implementation of structures metadata parser
12
 */
13
abstract class AbstractMetadataParser implements MetadataParserInterface
14
{
15
    /**
16
     * Namespaces for property classes
17
     *
18
     * @var array
19
     */
20
    private $nsProperty = [];
21
    /**
22
     * Namespaces for structure classes
23
     *
24
     * @var array
25
     */
26
    private $nsStruct = [];
27
    /**
28
     * @var MetadataManagerInterface
29
     */
30
    private $metadataManager;
31
32
    /**
33
     * Get structure metadata information for given class
34
     *
35
     * @param string $class Structure class name to parse metadata from
36
     *
37
     * @throws Exception
38
     * @return StructMetadata
39
     * @throws \InvalidArgumentException
40
     */
41 182
    public function getMetadata($class)
42
    {
43
        try {
44 182
            $reflection = new \ReflectionClass($class);
45 182
            $parent = $reflection->getParentClass();
46 182
            $metadata = null;
47 182
            if (($parent instanceof \ReflectionClass) && $parent->implementsInterface(StructInterface::class)) {
48 182
                $metadata = $this->getMetadataManager()->getMetadata($parent->getName());
0 ignored issues
show
Consider using $parent->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
49 182
            }
50 182
            if (!$metadata instanceof StructMetadata) {
51 182
                $metadata = new StructMetadata();
52 182
            }
53 182
            $metadata->setClass($class);
54 182
            $this->parseMetadata($reflection, $metadata);
55 181
            $reflection = new \ReflectionClass($class);
56 181
            if ($reflection->implementsInterface(MetadataModificationInterface::class)) {
57
                /** @var $class MetadataModificationInterface */
58 162
                $class::modifyMetadata($metadata);
59 162
            }
60 182
        } catch (\ReflectionException $e) {
61
            throw new \InvalidArgumentException('Failed to obtain exception for metadata class "' . $class . '"');
62
        }
63 181
        return $metadata;
64
    }
65
66
    /**
67
     * @return MetadataManagerInterface
68
     */
69 184
    public function getMetadataManager()
70
    {
71 184
        if (!$this->metadataManager) {
72 16
            $this->metadataManager = ConfigurationManager::getConfiguration()->getMetadataManager();
73 16
        }
74 184
        return $this->metadataManager;
75
    }
76
77
    /**
78
     * @param MetadataManagerInterface $metadataManager
79
     */
80 185
    public function setMetadataManager(MetadataManagerInterface $metadataManager)
81
    {
82 185
        $this->metadataManager = $metadataManager;
83 185
    }
84
85
    /**
86
     * Actual implementation of structure metadata parsing
87
     *
88
     * @param \ReflectionClass $reflection
89
     * @param StructMetadata $metadata
90
     * @return void
91
     */
92
    abstract protected function parseMetadata(\ReflectionClass $reflection, StructMetadata $metadata);
93
94
    /**
95
     * Resolve given property type into property FQCN
96
     *
97
     * @param string $class Structure property class
98
     * @return string|null
99
     * @throws \InvalidArgumentException
100
     */
101 179 View Code Duplication
    protected function resolvePropertyClass($class)
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...
102
    {
103 179
        if (empty($this->nsProperty)) {
104 179
            $ns = ConfigurationManager::getConfiguration()->getPropertyNamespacesMap()->getAll();
105 179
            $this->nsProperty = array_reverse($ns, true);
106 179
        }
107 179
        return $this->resolveClass($class, $this->nsProperty, PropertyInterface::class);
108
    }
109
110
    /**
111
     * Resolve given class into FQCN class and check if it supports given namespace
112
     *
113
     * @param string $class     Class name to resolve
114
     * @param array $namespaces List of namespace to use to expand given class name
115
     * @param string $interface OPTIONAL Interface, class must implement
116
     * @return string|null
117
     */
118 181
    protected function resolveClass($class, array $namespaces, $interface = null)
119
    {
120 181
        $class = ucfirst(trim($class, '\\'));
121 181 View Code Duplication
        if (class_exists($class) && (($interface === null) || in_array($interface, class_implements($class), true))) {
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...
122
            return $class;
123
        }
124 181
        foreach ($namespaces as $ns) {
125 181
            $fqcn = $ns . '\\' . $class;
126 181 View Code Duplication
            if (class_exists($fqcn) && (($interface === null) || in_array($interface, class_implements($fqcn), true))) {
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...
127 178
                return $fqcn;
128
            }
129 20
        }
130 3
        return null;
131
    }
132
133
    /**
134
     * Resolve given structure class into structure FQCN
135
     *
136
     * @param string $class Structure class
137
     * @return string|null
138
     * @throws \InvalidArgumentException
139
     */
140 67 View Code Duplication
    protected function resolveStructClass($class)
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...
141
    {
142 67
        if (empty($this->nsStruct)) {
143 67
            $ns = ConfigurationManager::getConfiguration()->getStructNamespacesMap()->getAll();
144 67
            $this->nsStruct = array_reverse($ns, true);
145 67
        }
146 67
        return $this->resolveClass($class, $this->nsStruct, StructInterface::class);
147
    }
148
}
149