Issues (32)

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/StorageMetadataFactory.php (10 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 As3\Modlr\Persister\MongoDb;
4
5
use As3\Modlr\Exception\MetadataException;
6
use As3\Modlr\Metadata\EntityMetadata;
7
use As3\Modlr\Metadata\Interfaces\StorageMetadataFactoryInterface;
8
use As3\Modlr\Util\EntityUtility;
9
10
/**
11
 * Creates MongoDb storage Metadata instances for use with metadata drivers.
12
 * Is also responsible for validating storage objects.
13
 *
14
 * @author Jacob Bare <[email protected]>
15
 */
16
final class StorageMetadataFactory implements StorageMetadataFactoryInterface
17
{
18
    /**
19
     * @var EntityUtility
20
     */
21
    private $entityUtil;
22
23
    /**
24
     * Constructor.
25
     *
26
     * @param   EntityUtility   $entityUtil
27
     */
28
    public function __construct(EntityUtility $entityUtil)
29
    {
30
        $this->entityUtil = $entityUtil;
31
    }
32
33
    /**
34
     * {@inheritDoc}
35
     */
36
    public function createInstance(array $mapping)
37
    {
38
        $persistence = new StorageMetadata();
39
40
        if (isset($mapping['db'])) {
41
            $persistence->db = $mapping['db'];
42
        }
43
44
        if (isset($mapping['collection'])) {
45
            $persistence->collection = $mapping['collection'];
46
        }
47
48
        if (isset($mapping['schemata'])) {
49
            $persistence->schemata = $this->rksort($mapping['schemata']);
50
        }
51
        return $persistence;
52
    }
53
54
    /**
55
     * {@inheritDoc}
56
     */
57
    public function handleLoad(EntityMetadata $metadata)
58
    {
59
        if (null === $metadata->persistence->collection) {
0 ignored issues
show
Accessing collection on the interface As3\Modlr\Metadata\Inter...s\StorageLayerInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
60
            $metadata->persistence->collection = $metadata->type;
0 ignored issues
show
Accessing collection on the interface As3\Modlr\Metadata\Inter...s\StorageLayerInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
61
        }
62
    }
63
64
    /**
65
     * {@inheritDoc}
66
     */
67
    public function handleValidate(EntityMetadata $metadata)
68
    {
69
        $this->validateIdStrategy($metadata);
70
        $this->validateDatabase($metadata);
71
        $this->validateCollectionNaming($metadata);
72
        $this->validateSchemata($metadata);
73
    }
74
75
    /**
76
     * Recursively ksorts an array
77
     * @param   array
78
     * @return  array
79
     */
80
    private function rksort(array $array)
81
    {
82
        ksort($array);
83
        foreach ($array as $k => $v) {
84
            if (is_array($v)) {
85
                $array[$k] = $this->rksort($v);
86
            }
87
        }
88
        return $array;
89
    }
90
91
    /**
92
     * Validates that the collection naming is correct, based on entity format config.
93
     *
94
     * @param   EntityMetadata  $metadata
95
     * @throws  MetadataException
96
     */
97
    private function validateCollectionNaming(EntityMetadata $metadata)
98
    {
99
        $persistence = $metadata->persistence;
100
        if (false === $this->entityUtil->isEntityTypeValid($persistence->collection)) {
0 ignored issues
show
Accessing collection on the interface As3\Modlr\Metadata\Inter...s\StorageLayerInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
101
            throw MetadataException::invalidMetadata(
102
                $metadata->type,
103
                sprintf('The entity persistence collection "%s" is invalid based on the configured name format "%s"',
104
                        $persistence->collection,
0 ignored issues
show
Accessing collection on the interface As3\Modlr\Metadata\Inter...s\StorageLayerInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
105
                        $this->entityUtil->getRestConfig()->getEntityFormat()
106
                )
107
            );
108
        }
109
    }
110
111
    /**
112
     * Validates that the proper database properties are set.
113
     *
114
     * @param   EntityMetadata  $metadata
115
     * @throws  MetadataException
116
     */
117
    private function validateDatabase(EntityMetadata $metadata)
118
    {
119
        $persistence = $metadata->persistence;
120
        if (false === $metadata->isChildEntity() && (empty($persistence->db) || empty($persistence->collection))) {
0 ignored issues
show
Accessing db on the interface As3\Modlr\Metadata\Inter...s\StorageLayerInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
Accessing collection on the interface As3\Modlr\Metadata\Inter...s\StorageLayerInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
121
            throw MetadataException::invalidMetadata($metadata->type, 'The persistence database and collection names cannot be empty.');
122
        }
123
    }
124
125
    /**
126
     * Validates the proper id strategy.
127
     *
128
     * @param   EntityMetadata  $metadata
129
     * @throws  MetadataException
130
     */
131
    private function validateIdStrategy(EntityMetadata $metadata)
132
    {
133
        $persistence = $metadata->persistence;
134
        $validIdStrategies = ['object'];
135
        if (!in_array($persistence->idStrategy, $validIdStrategies)) {
0 ignored issues
show
Accessing idStrategy on the interface As3\Modlr\Metadata\Inter...s\StorageLayerInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
136
            throw MetadataException::invalidMetadata($metadata->type, sprintf('The persistence id strategy "%s" is invalid. Valid types are "%s"', $persistence->idStrategy, implode('", "', $validIdStrategies)));
0 ignored issues
show
Accessing idStrategy on the interface As3\Modlr\Metadata\Inter...s\StorageLayerInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
137
        }
138
    }
139
140
    /**
141
     * Validates the schema definitions
142
     *
143
     * @param   EntityMetadata  $metadata
144
     * @throws  MetadataException
145
     */
146
    private function validateSchemata(EntityMetadata $metadata)
147
    {
148
        $persistence = $metadata->persistence;
149
        foreach ($persistence->schemata as $k => $schema) {
0 ignored issues
show
Accessing schemata on the interface As3\Modlr\Metadata\Inter...s\StorageLayerInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
150
            if (!isset($schema['keys']) || empty($schema['keys'])) {
151
                throw MetadataException::invalidMetadata($metadata->type, 'At least one key must be specified to define an index.');
152
            }
153
            $persistence->schemata[$k]['options']['name'] = sprintf('modlr_%s', md5(json_encode($schema)));
0 ignored issues
show
Accessing schemata on the interface As3\Modlr\Metadata\Inter...s\StorageLayerInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
154
        }
155
    }
156
}
157