Issues (4)

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/Type/JsonDocumentType.php (2 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
/*
4
 * (c) Kévin Dunglas <[email protected]>
5
 *
6
 * This source file is subject to the MIT license that is bundled
7
 * with this source code in the file LICENSE.
8
 */
9
10
namespace Dunglas\DoctrineJsonOdm\Type;
11
12
use Doctrine\DBAL\Platforms\AbstractPlatform;
13
use Doctrine\DBAL\Types\JsonArrayType;
14
use Doctrine\DBAL\Types\JsonType;
15
use Symfony\Component\Serializer\SerializerInterface;
16
17
if (class_exists(JsonType::class)) {
18
    /**
19
     * @internal
20
     */
21
    class InternalParentClass extends JsonType
22
    {
23
    }
24
} else {
25
    /**
26
     * @internal
27
     */
28
    class InternalParentClass extends JsonArrayType
0 ignored issues
show
Comprehensibility Best Practice introduced by
The type Dunglas\DoctrineJsonOdm\Type\InternalParentClass has been defined more than once; this definition is ignored, only the first definition in this file (L21-23) is considered.

This check looks for classes that have been defined more than once in the same file.

If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.

This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.

Loading history...
Deprecated Code introduced by
The class Doctrine\DBAL\Types\JsonArrayType has been deprecated with message: Use JsonType instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
29
    {
30
    }
31
}
32
33
/**
34
 * The JSON document type.
35
 *
36
 * @author Kévin Dunglas <[email protected]>
37
 */
38
final class JsonDocumentType extends InternalParentClass
39
{
40
    /**
41
     * @var SerializerInterface
42
     */
43
    private $serializer;
44
45
    /**
46
     * @var string
47
     */
48
    private $format = 'json';
49
50
    /**
51
     * @var array
52
     */
53
    private $serializationContext = [];
54
55
    /**
56
     * @var array
57
     */
58
    private $deserializationContext = [];
59
60
    /**
61
     * Sets the serializer to use.
62
     *
63
     * @param SerializerInterface $serializer
64
     */
65
    public function setSerializer(SerializerInterface $serializer)
66
    {
67
        $this->serializer = $serializer;
68
    }
69
70
    /**
71
     * Gets the serializer or throw an exception if it isn't available.
72
     *
73
     * @throws \RuntimeException
74
     *
75
     * @return SerializerInterface
76
     */
77
    private function getSerializer()
78
    {
79
        if (null === $this->serializer) {
80
            throw new \RuntimeException(sprintf('An instance of "%s" must be available. Call the "setSerializer" method.', SerializerInterface::class));
81
        }
82
83
        return $this->serializer;
84
    }
85
86
    /**
87
     * Sets the serialization format (default to "json").
88
     *
89
     * @param string $format
90
     */
91
    public function setFormat($format)
92
    {
93
        $this->format = $format;
94
    }
95
96
    /**
97
     * Sets the serialization context (default to an empty array).
98
     *
99
     * @param array $serializationContext
100
     */
101
    public function setSerializationContext(array $serializationContext)
102
    {
103
        $this->serializationContext = $serializationContext;
104
    }
105
106
    /**
107
     * Sets the deserialization context (default to an empty array).
108
     *
109
     * @param array $deserializationContext
110
     */
111
    public function setDeserializationContext(array $deserializationContext)
112
    {
113
        $this->deserializationContext = $deserializationContext;
114
    }
115
116
    /**
117
     * {@inheritdoc}
118
     */
119
    public function convertToDatabaseValue($value, AbstractPlatform $platform)
120
    {
121
        if (null === $value) {
122
            return;
123
        }
124
125
        return $this->getSerializer()->serialize($value, $this->format, $this->serializationContext);
126
    }
127
128
    /**
129
     * {@inheritdoc}
130
     */
131
    public function convertToPHPValue($value, AbstractPlatform $platform)
132
    {
133
        if (null === $value || $value === '') {
134
            return;
135
        }
136
137
        return $this->getSerializer()->deserialize($value, '', $this->format, $this->deserializationContext);
138
    }
139
140
    /**
141
     * {@inheritdoc}
142
     */
143
    public function requiresSQLCommentHint(AbstractPlatform $platform)
144
    {
145
        return true;
146
    }
147
148
    /**
149
     * {@inheritdoc}
150
     */
151
    public function getName()
152
    {
153
        return 'json_document';
154
    }
155
}
156