Issues (3)

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.

DecoupageAdministratifResponseDeserializer.php (2 issues)

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
/*
4
 * This file is part of the geo-api-library package.
5
 *
6
 * (c) 2020 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Library\GeoAPI\Serializer;
13
14
use WBW\Library\Core\Argument\Helper\ArrayHelper;
15
use WBW\Library\GeoAPI\Model\Commune;
16
use WBW\Library\GeoAPI\Model\Departement;
17
use WBW\Library\GeoAPI\Model\Region;
18
use WBW\Library\GeoAPI\Response\CommunesResponse;
19
use WBW\Library\GeoAPI\Response\DepartementsResponse;
20
use WBW\Library\GeoAPI\Response\RegionsResponse;
21
use WBW\Library\GeoJSON\Serializer\JsonDeserializer;
22
23
/**
24
 * Découpage administratif response deserializer.
25
 *
26
 * @author webeweb <https://github.com/webeweb/>
27
 * @package WBW\Library\GeoAPI\Serializer
28
 */
29
class DecoupageAdministratifResponseDeserializer extends JsonDeserializer {
30
31
    /**
32
     * Deserializes a commune.
33
     *
34
     * @param array $response The response.
35
     * @return Commune Returns the commune.
36 15
     */
37
    protected static function deserializeCommune(array $response): Commune {
38 15
39 15
        $model = new Commune();
40 15
        $model->setNom(ArrayHelper::get($response, "nom"));
41 15
        $model->setCode(ArrayHelper::get($response, "code"));
42 15
        $model->setCodeDepartement(ArrayHelper::get($response, "codeDepartement"));
43 15
        $model->setCodeRegion(ArrayHelper::get($response, "codeRegion"));
44 15
        $model->setCentre(static::deserializeGeometry(ArrayHelper::get($response, "centre", [])));
45 15
        $model->setContour(static::deserializeGeometry(ArrayHelper::get($response, "contour", [])));
46
        $model->setSurface(ArrayHelper::get($response, "surface"));
47 15
        $model->setPopulation(ArrayHelper::get($response, "population"));
48
        $model->setCodesPostaux(ArrayHelper::get($response, "codesPostaux", []));
49
        $model->setScore(ArrayHelper::get($response, "_score"));
50
        $model->setDepartement(static::deserializeDepartement(ArrayHelper::get($response, "departement", [])));
51
        $model->setRegion(static::deserializeRegion(ArrayHelper::get($response, "region", [])));
52
53
        return $model;
54
    }
55
56 15
    /**
57
     * Deserializes a communes response.
58 15
     *
59 15
     * @param string $rawResponse The raw response.
60
     * @return CommunesResponse Returns the communes response.
61 15
     */
62 15
    public static function deserializeCommunesResponse(string $rawResponse): CommunesResponse {
63
64
        $model = new CommunesResponse();
65
        $model->setRawResponse($rawResponse);
66 15
67 15
        $response = json_decode($rawResponse, true);
68
        if (null === $response) {
69
            return $model;
70 15
        }
71
72
        $response = static::toArray($response);
73
        foreach ($response as $current) {
74
            $model->addCommune(static::deserializeCommune($current));
75
        }
76
77
        return $model;
78
    }
79 15
80
    /**
81 15
     * Deserializes a département.
82 15
     *
83 15
     * @param array $response The response.
84 15
     * @return Departement|null Returns the département.
85 15
     */
86
    protected static function deserializeDepartement(array $response): ?Departement {
87 15
88
        if (0 === count($response)) {
89
            return null;
90
        }
91
92
        $model = new Departement();
93
        $model->setNom(ArrayHelper::get($response, "nom"));
94
        $model->setCode(ArrayHelper::get($response, "code"));
95
        $model->setCodeRegion(ArrayHelper::get($response, "codeRegion"));
96 15
        $model->setScore(ArrayHelper::get($response, "_score"));
97
98 15
        return $model;
99 15
    }
100
101 15
    /**
102 15
     * Deserializes a départements response.
103
     *
104
     * @param string $rawResponse The raw response.
105
     * @return DepartementsResponse Returns the départements response.
106 15
     */
107 15
    public static function deserializeDepartementsResponse(string $rawResponse): DepartementsResponse {
108
109
        $model = new DepartementsResponse();
110 15
        $model->setRawResponse($rawResponse);
111
112
        $response = json_decode($rawResponse, true);
113
        if (null === $response) {
114
            return $model;
115
        }
116
117
        $response = static::toArray($response);
118
        foreach ($response as $current) {
119 10
            $model->addDepartement(static::deserializeDepartement($current));
0 ignored issues
show
It seems like static::deserializeDepartement($current) can be null; however, addDepartement() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
120
        }
121 10
122 10
        return $model;
123 10
    }
124 10
125
    /**
126 10
     * Deserializes a région.
127
     *
128
     * @param array $response The response.
129
     * @return Region|null Returns the région.
130
     */
131
    protected static function deserializeRegion(array $response): ?Region {
132
133
        if (0 === count($response)) {
134
            return null;
135 10
        }
136
137 10
        $model = new Region();
138 10
        $model->setCode(ArrayHelper::get($response, "code"));
139
        $model->setNom(ArrayHelper::get($response, "nom"));
140 10
        $model->setScore(ArrayHelper::get($response, "_score"));
141 10
142
        return $model;
143
    }
144
145 10
    /**
146 10
     * Deserializes a régions response.
147
     *
148
     * @param string $rawResponse The raw response.
149 10
     * @return RegionsResponse Returns the régions response.
150
     */
151 3
    public static function deserializeRegionsResponse(string $rawResponse): RegionsResponse {
152
153
        $model = new RegionsResponse();
154
        $model->setRawResponse($rawResponse);
155
156
        $response = json_decode($rawResponse, true);
157
        if (null === $response) {
158
            return $model;
159
        }
160
161
        $response = static::toArray($response);
162
        foreach ($response as $current) {
163
            $model->addRegion(static::deserializeRegion($current));
0 ignored issues
show
It seems like static::deserializeRegion($current) can be null; however, addRegion() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
164
        }
165
166
        return $model;
167
    }
168
169
    /**
170
     * Convert an object into an array of object.
171
     *
172
     * @param array $response The response.
173
     * @return array Returns the converted array.
174
     */
175
    protected static function toArray(array $response): array {
176
        if (true === ArrayHelper::isObject($response)) {
177
            return [$response];
178
        }
179
        return $response;
180
    }
181
}