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/Utils/EntityMapCache.php (3 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
 * @link    https://github.com/nnx-framework/doctrine
4
 * @author  Malofeykin Andrey  <[email protected]>
5
 */
6
namespace Nnx\Doctrine\Utils;
7
8
use Doctrine\Common\Cache\Cache;
9
use Nnx\Doctrine\Options\ModuleOptionsInterface;
10
11
/**
12
 * Class EntityMapCache
13
 *
14
 * @package Nnx\Doctrine\Utils
15
 */
16
class EntityMapCache implements EntityMapCacheInterface
17
{
18
    /**
19
     * Сервис для построения карты сущностей Doctrine2
20
     *
21
     * @var EntityMapBuilderInterface
22
     */
23
    protected $entityMapBuilder;
24
25
    /**
26
     * Кеш в который сохрянется карта сущностей Doctrine2
27
     *
28
     * @var Cache
29
     */
30
    protected $cache;
31
32
    /**
33
     * Объект с настройками модуля
34
     *
35
     * @var ModuleOptionsInterface
36
     */
37
    protected $moduleOptions;
38
39
    /**
40
     * Ключ кеширования
41
     *
42
     * @var array
43
     */
44
    protected $cacheKeys = [];
45
46
    /**
47
     * EntityMapCache constructor.
48
     *
49
     * @param EntityMapBuilderInterface $entityMapBuilder
50
     * @param Cache                     $cache
51
     * @param ModuleOptionsInterface    $moduleOptions
52
     */
53
    public function __construct(
54
        EntityMapBuilderInterface $entityMapBuilder,
55
        Cache $cache,
56
        ModuleOptionsInterface $moduleOptions
57
    ) {
58
        $this->setEntityMapBuilder($entityMapBuilder);
59
        $this->setCache($cache);
60
        $this->setModuleOptions($moduleOptions);
61
    }
62
63
    /**
64
     * @inheritdoc
65
     *
66
     * @param $objectManagerName
67
     *
68
     * @return boolean
69
     */
70
    public function saveEntityMap($objectManagerName)
71
    {
72
        $moduleOptions =  $this->getModuleOptions();
73
        $originalFlag = $this->getModuleOptions()->getFlagDisableUseEntityMapDoctrineCache();
74
        $moduleOptions->setFlagDisableUseEntityMapDoctrineCache(true);
75
76
        $map = $this->getEntityMapBuilder()->buildEntityMapByObjectManagerName($objectManagerName);
77
78
        $key = $this->getCacheKeyForObjectManagerName($objectManagerName);
79
        $resultSaveCache = $this->getCache()->save($key, $map);
80
        $moduleOptions->setFlagDisableUseEntityMapDoctrineCache($originalFlag);
81
82
        return $resultSaveCache;
83
    }
84
85
    /**
86
     * Загружает карту сущностей
87
     *
88
     * @param $objectManagerName
89
     *
90
     * @return array|null
91
     */
92 View Code Duplication
    public function loadEntityMap($objectManagerName)
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...
93
    {
94
        $key = $this->getCacheKeyForObjectManagerName($objectManagerName);
95
96
        $cache = $this->getCache();
97
98
        if (false === $cache->contains($key)) {
99
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type declared by the interface Nnx\Doctrine\Utils\Entit...nterface::loadEntityMap of type array|null.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
100
        }
101
102
        return $cache->fetch($key);
103
    }
104
105
    /**
106
     * Удаляет карту сущностей
107
     *
108
     * @param $objectManagerName
109
     *
110
     * @return void
111
     */
112 View Code Duplication
    public function deleteEntityMap($objectManagerName)
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...
113
    {
114
        $key = $this->getCacheKeyForObjectManagerName($objectManagerName);
115
116
        $cache = $this->getCache();
117
118
        if (true === $cache->contains($key)) {
119
            $cache->delete($key);
120
        }
121
    }
122
123
    /**
124
     * Проверяет есть ли в кеше карта сущностей для заданного ObjectManager
125
     *
126
     * @param $objectManagerName
127
     *
128
     * @return bool
129
     */
130
    public function hasEntityMap($objectManagerName)
131
    {
132
        $key = $this->getCacheKeyForObjectManagerName($objectManagerName);
133
134
        return $this->getCache()->contains($key);
135
    }
136
137
    /**
138
     * Получает ключ для кеширования карты сущностей
139
     *
140
     * @param $objectManagerName
141
     *
142
     * @return string
143
     */
144
    public function getCacheKeyForObjectManagerName($objectManagerName)
145
    {
146
        if (array_key_exists($objectManagerName, $this->cacheKeys)) {
147
            return $this->cacheKeys[$objectManagerName];
148
        }
149
150
        $preffix = $this->getModuleOptions()->getEntityMapDoctrineCachePrefix();
151
        $key = $preffix . '_' . $objectManagerName;
152
153
        $this->cacheKeys[$objectManagerName] = $key;
154
155
        return $this->cacheKeys[$objectManagerName];
156
    }
157
158
    /**
159
     * @return EntityMapBuilderInterface
160
     */
161
    public function getEntityMapBuilder()
162
    {
163
        return $this->entityMapBuilder;
164
    }
165
166
    /**
167
     * @param EntityMapBuilderInterface $entityMapBuilder
168
     *
169
     * @return $this
170
     */
171
    public function setEntityMapBuilder(EntityMapBuilderInterface $entityMapBuilder)
172
    {
173
        $this->entityMapBuilder = $entityMapBuilder;
174
175
        return $this;
176
    }
177
178
    /**
179
     * @return Cache
180
     */
181
    public function getCache()
182
    {
183
        return $this->cache;
184
    }
185
186
    /**
187
     * @param Cache $cache
188
     *
189
     * @return $this
190
     */
191
    public function setCache(Cache $cache)
192
    {
193
        $this->cache = $cache;
194
195
        return $this;
196
    }
197
198
    /**
199
     * Возвращает объект с настройками модуля
200
     *
201
     * @return ModuleOptionsInterface
202
     */
203
    public function getModuleOptions()
204
    {
205
        return $this->moduleOptions;
206
    }
207
208
    /**
209
     * Устанавливает  объект с настройками модуля
210
     *
211
     * @param ModuleOptionsInterface $moduleOptions
212
     *
213
     * @return $this
214
     */
215
    public function setModuleOptions(ModuleOptionsInterface $moduleOptions)
216
    {
217
        $this->moduleOptions = $moduleOptions;
218
219
        return $this;
220
    }
221
}
222