Issues (655)

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.

DataTransformer/ModelToIdPropertyTransformer.php (1 issue)

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
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\AdminBundle\Form\DataTransformer;
15
16
use Doctrine\Common\Util\ClassUtils;
17
use Sonata\AdminBundle\Model\ModelManagerInterface;
18
use Symfony\Component\Form\DataTransformerInterface;
19
20
/**
21
 * Transform object to ID and property label.
22
 *
23
 * @author Andrej Hudec <[email protected]>
24
 */
25
final class ModelToIdPropertyTransformer implements DataTransformerInterface
26
{
27
    /**
28
     * @var ModelManagerInterface
29
     */
30
    private $modelManager;
31
32
    /**
33
     * @var string
34
     */
35
    private $className;
36
37
    /**
38
     * @var string
39
     */
40
    private $property;
41
42
    /**
43
     * @var bool
44
     */
45
    private $multiple;
46
47
    /**
48
     * @var callable|null
49
     */
50
    private $toStringCallback;
51
52
    /**
53
     * @param string        $className
54
     * @param string        $property
55
     * @param bool          $multiple
56
     * @param callable|null $toStringCallback
57
     */
58
    public function __construct(
59
        ModelManagerInterface $modelManager,
60
        $className,
61
        $property,
62
        $multiple = false,
63
        $toStringCallback = null
64
    ) {
65
        $this->modelManager = $modelManager;
66
        $this->className = $className;
67
        $this->property = $property;
68
        $this->multiple = $multiple;
69
        $this->toStringCallback = $toStringCallback;
70
    }
71
72
    public function reverseTransform($value)
73
    {
74
        $collection = $this->modelManager->getModelCollectionInstance($this->className);
75
76
        if (empty($value)) {
77
            if ($this->multiple) {
78
                return $collection;
79
            }
80
81
            return null;
82
        }
83
84
        if (!$this->multiple) {
85
            return $this->modelManager->find($this->className, $value);
86
        }
87
88
        if (!\is_array($value)) {
89
            throw new \UnexpectedValueException(sprintf('Value should be array, %s given.', \gettype($value)));
90
        }
91
92
        foreach ($value as $key => $id) {
93
            if ('_labels' === $key) {
94
                continue;
95
            }
96
97
            $collection[] = $this->modelManager->find($this->className, $id);
98
        }
99
100
        return $collection;
101
    }
102
103
    public function transform($entityOrCollection)
104
    {
105
        $result = [];
106
107
        if (!$entityOrCollection) {
108
            return $result;
109
        }
110
111
        if ($this->multiple) {
112
            $isArray = \is_array($entityOrCollection);
113
            if (!$isArray && substr(\get_class($entityOrCollection), -1 * \strlen($this->className)) === $this->className) {
114
                throw new \InvalidArgumentException(
115
                    'A multiple selection must be passed a collection not a single value.'
116
                    .' Make sure that form option "multiple=false" is set for many-to-one relation and "multiple=true"'
117
                    .' is set for many-to-many or one-to-many relations.'
118
                );
119
            }
120
            if ($isArray || ($entityOrCollection instanceof \ArrayAccess)) {
121
                $collection = $entityOrCollection;
122
            } else {
123
                throw new \InvalidArgumentException(
124
                    'A multiple selection must be passed a collection not a single value.'
125
                    .' Make sure that form option "multiple=false" is set for many-to-one relation and "multiple=true"'
126
                    .' is set for many-to-many or one-to-many relations.'
127
                );
128
            }
129
        } else {
130
            if (substr(\get_class($entityOrCollection), -1 * \strlen($this->className)) === $this->className) {
131
                $collection = [$entityOrCollection];
132
            } elseif ($entityOrCollection instanceof \ArrayAccess) {
133
                throw new \InvalidArgumentException(
134
                    'A single selection must be passed a single value not a collection.'
135
                    .' Make sure that form option "multiple=false" is set for many-to-one relation and "multiple=true"'
136
                    .' is set for many-to-many or one-to-many relations.'
137
                );
138
            } else {
139
                $collection = [$entityOrCollection];
140
            }
141
        }
142
143
        if (empty($this->property)) {
144
            throw new \RuntimeException('Please define "property" parameter.');
145
        }
146
147
        foreach ($collection as $model) {
148
            $id = current($this->modelManager->getIdentifierValues($model));
149
150
            if (null !== $this->toStringCallback) {
151
                if (!\is_callable($this->toStringCallback)) {
152
                    throw new \RuntimeException(
153
                        'Callback in "to_string_callback" option doesn`t contain callable function.'
154
                    );
155
                }
156
157
                $label = ($this->toStringCallback)($model, $this->property);
158
            } else {
159
                try {
160
                    $label = (string) $model;
161
                } catch (\Exception $e) {
0 ignored issues
show
catch (\Exception $e) { ...ass($model)), 0, $e); } does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
162
                    throw new \RuntimeException(sprintf(
163
                        'Unable to convert the entity %s to String, entity must have a \'__toString()\' method defined',
164
                        ClassUtils::getClass($model)
165
                    ), 0, $e);
166
                }
167
            }
168
169
            $result[] = $id;
170
            $result['_labels'][] = $label;
171
        }
172
173
        return $result;
174
    }
175
}
176