Issues (7)

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.

SettingsManager.php (1 issue)

Labels
Severity

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 SumoCoders\FrameworkSettingsBundle;
4
5
use Doctrine\ORM\EntityManager;
6
use SumoCoders\FrameworkSettingsBundle\Entity\Setting;
7
use SumoCoders\FrameworkSettingsBundle\Entity\SettingRepository;
8
use SumoCoders\FrameworkSettingsBundle\Exception\DontUseException;
9
use SumoCoders\FrameworkSettingsBundle\Exception\InvalidInstanceException;
10
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
11
12
class SettingsManager implements ParameterBagInterface
13
{
14
    /**
15
     * @var EntityManager
16
     */
17
    protected $entityManager;
18
19
    /**
20
     * @var SettingRepository
21
     */
22
    protected $repository;
23
24
    /**
25
     * Parameter storage.
26
     *
27
     * @var array
28
     */
29
    protected $settings;
30
31
    /**
32
     * Is the class initialized
33
     *
34
     * @var bool
35
     */
36
    protected $isInitialized = false;
37
38
    /**
39
     * @param EntityManager     $entityManager
40
     * @param SettingRepository $repository
41
     */
42 11
    public function __construct($entityManager, $repository)
0 ignored issues
show
You have injected the EntityManager via parameter $entityManager. This is generally not recommended as it might get closed and become unusable. Instead, it is recommended to inject the ManagerRegistry and retrieve the EntityManager via getManager() each time you need it.

The EntityManager might become unusable for example if a transaction is rolled back and it gets closed. Let’s assume that somewhere in your application, or in a third-party library, there is code such as the following:

function someFunction(ManagerRegistry $registry) {
    $em = $registry->getManager();
    $em->getConnection()->beginTransaction();
    try {
        // Do something.
        $em->getConnection()->commit();
    } catch (\Exception $ex) {
        $em->getConnection()->rollback();
        $em->close();

        throw $ex;
    }
}

If that code throws an exception and the EntityManager is closed. Any other code which depends on the same instance of the EntityManager during this request will fail.

On the other hand, if you instead inject the ManagerRegistry, the getManager() method guarantees that you will always get a usable manager instance.

Loading history...
43
    {
44 11
        $this->entityManager = $entityManager;
45 11
        $this->repository = $repository;
46 11
    }
47
48
    /**
49
     * Initialize the settings
50
     */
51 5
    protected function initialize()
52
    {
53 5
        if (!$this->isInitialized) {
54 5
            $this->all();
55 5
        }
56 5
        $this->isInitialized = true;
57 5
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62 1
    public function clear()
63
    {
64 1
        throw new DontUseException();
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70 3
    public function add(array $parameters)
71
    {
72 3
        $this->isInitialized = false;
73 3
        foreach ($parameters as $setting) {
74 3
            if (!($setting instanceof Setting)) {
75 1
                throw new InvalidInstanceException('This is not an instance of the Setting-class.');
76
            }
77
78 2
            $this->set(
79 2
                $setting->getName(),
80 2
                $setting->getValue(),
81 2
                $setting->isEditable()
82 2
            );
83 2
        }
84 2
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89 5
    public function all()
90
    {
91 5
        $settings = $this->repository->findAll();
92
93 5
        if (!empty($settings)) {
94
            foreach ($settings as $setting) {
95
                $this->settings[$setting->getName()] = $setting;
96
            }
97
        }
98
99 5
        return $this->settings;
100
    }
101
102
    /**
103
     * {@inheritdoc}
104
     */
105 2
    public function get($name, $defaultValue = null)
106
    {
107 2
        $this->initialize();
108 2
        if (!isset($this->settings[$name])) {
109
            return $defaultValue;
110
        }
111
112 2
        return $this->settings[$name]->getValue();
113
    }
114
115
    /**
116
     * Store a setting
117
     *
118
     * @param string $name
119
     * @param mixed  $value
120
     * @param bool   $isEditable
121
     * @return $this
122
     */
123 4
    public function set($name, $value, $isEditable = false)
124
    {
125 4
        $this->isInitialized = false;
126
127 4
        if ($this->has($name)) {
128
            $setting = $this->settings[$name];
129
        } else {
130 4
            $setting = new Setting();
131 4
            $setting->setName($name);
132
        }
133
134 4
        $setting->setValue($value);
135 4
        $setting->setEditable($isEditable);
136
137
        // store and flush
138 4
        $this->entityManager->persist($setting);
139 4
        $this->entityManager->flush();
140
141
        // reset it
142 4
        $this->settings[$name] = $setting;
143
144 4
        return $this;
145
    }
146
147
    /**
148
     * {@inheritdoc}
149
     */
150 5
    public function has($name)
151
    {
152 5
        $this->isInitialized = false;
153 5
        $this->initialize();
154
155 5
        return isset($this->settings[$name]);
156
    }
157
158
    /**
159
     * {@inheritdoc}
160
     */
161 1
    public function resolve()
162
    {
163 1
        throw new DontUseException();
164
    }
165
166
    /**
167
     * {@inheritdoc}
168
     */
169 1
    public function resolveValue($value)
170
    {
171 1
        throw new DontUseException();
172
    }
173
174
    /**
175
     * {@inheritdoc}
176
     */
177 1
    public function escapeValue($value)
178
    {
179 1
        throw new DontUseException();
180
    }
181
182
    /**
183
     * {@inheritdoc}
184
     */
185 1
    public function unescapeValue($value)
186
    {
187 1
        throw new DontUseException();
188
    }
189
190
    /**
191
     * {@inheritdoc}
192
     */
193
    public function remove($name)
194
    {
195
        throw new DontUseException();
196
    }
197
}
198