Issues (29)

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.

bundle/Controller/WeatherController.php (6 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
namespace Netgen\Bundle\OpenWeatherMapBundle\Controller;
4
5
use Netgen\Bundle\OpenWeatherMapBundle\API\OpenWeatherMap\Weather\WeatherInterface;
6
use Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException;
7
use Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\HttpFoundation\Response;
10
11
/**
12
 * Class WeatherController.
13
 */
14
class WeatherController
15
{
16
    /**
17
     * @var \Netgen\Bundle\OpenWeatherMapBundle\API\OpenWeatherMap\Weather\WeatherInterface
18
     */
19
    protected $weather;
20
21
    /**
22
     * WeatherController constructor.
23
     *
24
     * @param \Netgen\Bundle\OpenWeatherMapBundle\API\OpenWeatherMap\Weather\WeatherInterface $weather
25
     */
26
    public function __construct(WeatherInterface $weather)
27
    {
28
        $this->weather = $weather;
29
    }
30
31
    /**
32
     * Returns weather data by geographic coordinates.
33
     *
34
     * @param float $latitude
35
     * @param float $longitude
36
     *
37
     * @return \Symfony\Component\HttpFoundation\Response
38
     */
39 View Code Duplication
    public function byGeographicCoordinates($latitude, $longitude)
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...
40
    {
41
        $response = new Response();
42
43
        try {
44
            $data = $this->weather->fetchWeatherDataByGeographicCoordinates($latitude, $longitude);
45
            $response->setContent($data);
46
        } catch (NotAuthorizedException $e) {
47
            $response->setContent($e->getMessage());
48
            $response->setStatusCode(Response::HTTP_UNAUTHORIZED);
49
        } catch (NotFoundException $e) {
50
            $response->setContent($e->getMessage());
51
            $response->setStatusCode(Response::HTTP_NOT_FOUND);
52
        }
53
54
        return $response;
55
    }
56
57
    /**
58
     * Returns weather data by city name.
59
     *
60
     * @param string $cityName
61
     * @param string $countryCode
62
     *
63
     * @return \Symfony\Component\HttpFoundation\Response
64
     */
65 View Code Duplication
    public function byCityName($cityName, $countryCode = '')
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...
66
    {
67
        $response = new Response();
68
69
        try {
70
            $data = $this->weather->fetchWeatherDataByCityName($cityName, $countryCode);
71
            $response->setContent($data);
72
        } catch (NotAuthorizedException $e) {
73
            $response->setContent($e->getMessage());
74
            $response->setStatusCode(Response::HTTP_UNAUTHORIZED);
75
        } catch (NotFoundException $e) {
76
            $response->setContent($e->getMessage());
77
            $response->setStatusCode(Response::HTTP_NOT_FOUND);
78
        }
79
80
        return $response;
81
    }
82
83
    /**
84
     * Returns weather data by city id.
85
     *
86
     * @param int $cityId
87
     *
88
     * @return \Symfony\Component\HttpFoundation\Response
89
     */
90 View Code Duplication
    public function byCityId($cityId)
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...
91
    {
92
        $response = new Response();
93
94
        try {
95
            $data = $this->weather->fetchWeatherDataByCityId($cityId);
96
            $response->setContent($data);
97
        } catch (NotAuthorizedException $e) {
98
            $response->setContent($e->getMessage());
99
            $response->setStatusCode(Response::HTTP_UNAUTHORIZED);
100
        } catch (NotFoundException $e) {
101
            $response->setContent($e->getMessage());
102
            $response->setStatusCode(Response::HTTP_NOT_FOUND);
103
        }
104
105
        return $response;
106
    }
107
108
    /**
109
     * Returns weather data by zip code.
110
     *
111
     * @param int $zipCode
112
     * @param string $countryCode
113
     *
114
     * @return \Symfony\Component\HttpFoundation\Response
115
     */
116 View Code Duplication
    public function byZipCode($zipCode, $countryCode = '')
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...
117
    {
118
        $response = new Response();
119
120
        try {
121
            $data = $this->weather->fetchWeatherDataByZipCode($zipCode, $countryCode);
122
            $response->setContent($data);
123
        } catch (NotAuthorizedException $e) {
124
            $response->setContent($e->getMessage());
125
            $response->setStatusCode(Response::HTTP_UNAUTHORIZED);
126
        } catch (NotFoundException $e) {
127
            $response->setContent($e->getMessage());
128
            $response->setStatusCode(Response::HTTP_NOT_FOUND);
129
        }
130
131
        return $response;
132
    }
133
134
    /**
135
     * Returns weather data for cities in rectangle zone.
136
     *
137
     * @param float $longitudeLeft
138
     * @param float $latitudeBottom
139
     * @param float $longitudeRight
140
     * @param float $latitudeTop
141
     * @param int $mapZoom
142
     * @param string $cluster
143
     *
144
     * @return \Symfony\Component\HttpFoundation\Response
145
     */
146 View Code Duplication
    public function byRectangleZone($longitudeLeft, $latitudeBottom, $longitudeRight, $latitudeTop, $mapZoom = 10, $cluster = 'yes')
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...
147
    {
148
        $boundingBox = array($longitudeLeft, $latitudeBottom, $longitudeRight, $latitudeTop, $mapZoom);
149
150
        $response = new Response();
151
152
        try {
153
            $data = $this->weather->fetchWeatherDataForCitiesWithinRectangleZone($boundingBox, $cluster);
154
            $response->setContent($data);
155
        } catch (NotAuthorizedException $e) {
156
            $response->setContent($e->getMessage());
157
            $response->setStatusCode(Response::HTTP_UNAUTHORIZED);
158
        } catch (NotFoundException $e) {
159
            $response->setContent($e->getMessage());
160
            $response->setStatusCode(Response::HTTP_NOT_FOUND);
161
        }
162
163
        return $response;
164
    }
165
166
    /**
167
     * Returns weather data for cities in circle.
168
     *
169
     * @param float $latitude
170
     * @param float $longitude
171
     * @param string $cluster
172
     * @param int $numberOfCities
173
     *
174
     * @return \Symfony\Component\HttpFoundation\Response
175
     */
176 View Code Duplication
    public function byCircle($latitude, $longitude, $cluster = 'yes', $numberOfCities = 10)
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...
177
    {
178
        $response = new Response();
179
180
        try {
181
            $data = $this->weather->fetchWeatherDataForCitiesInCycle($latitude, $longitude, $cluster, $numberOfCities);
182
            $response->setContent($data);
183
        } catch (NotAuthorizedException $e) {
184
            $response->setContent($e->getMessage());
185
            $response->setStatusCode(Response::HTTP_UNAUTHORIZED);
186
        } catch (NotFoundException $e) {
187
            $response->setContent($e->getMessage());
188
            $response->setStatusCode(Response::HTTP_NOT_FOUND);
189
        }
190
191
        return $response;
192
    }
193
194
    /**
195
     * Returns weather data by several city ids.
196
     *
197
     * @param \Symfony\Component\HttpFoundation\Request $request
198
     *
199
     * @return \Symfony\Component\HttpFoundation\Response
200
     */
201
    public function byCityIds(Request $request)
202
    {
203
        $response = new Response();
204
        if (!$request->query->has('cities')) {
205
            return $response->setStatusCode(Response::HTTP_BAD_REQUEST);
206
        }
207
208
        $cities = $request->query->get('cities');
209
        $cities = explode(',', $cities);
210
211
        try {
212
            $data = $this->weather->fetchWeatherDataForSeveralCityIds($cities);
213
            $response->setContent($data);
214
        } catch (NotAuthorizedException $e) {
215
            $response->setContent($e->getMessage());
216
            $response->setStatusCode(Response::HTTP_UNAUTHORIZED);
217
        } catch (NotFoundException $e) {
218
            $response->setContent($e->getMessage());
219
            $response->setStatusCode(Response::HTTP_NOT_FOUND);
220
        }
221
222
        return $response;
223
    }
224
}
225