Issues (15)

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/CLI/Command/Geocoder/Geocode.php (3 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
 * This file is part of the Geotools library.
5
 *
6
 * (c) Antoine Corcy <[email protected]>
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 League\Geotools\CLI\Command\Geocoder;
13
14
use Geocoder\ProviderAggregator;
15
use Http\Discovery\HttpClientDiscovery;
16
use League\Geotools\Batch\Batch;
17
use Symfony\Component\Console\Input\InputArgument;
18
use Symfony\Component\Console\Input\InputInterface;
19
use Symfony\Component\Console\Input\InputOption;
20
use Symfony\Component\Console\Output\OutputInterface;
21
22
/**
23
 * Command-line geocoder:geocode class
24
 *
25
 * @author Antoine Corcy <[email protected]>
26
 */
27
class Geocode extends Command
28 1
{
29
    protected function configure()
30
    {
31 1
        $this
32 1
            ->setName('geocoder:geocode')
33 1
            ->setDescription('Geocode a street-address, IPv4 or IPv6 against a provider with an adapter')
34 1
            ->addArgument('value', InputArgument::REQUIRED, 'The street-address, IPv4 or IPv6 to geocode')
35 1
            ->addOption('provider', null, InputOption::VALUE_REQUIRED,
36 1
                'If set, the name of the provider to use, Google Maps by default', 'google_maps')
37 1
            ->addOption('cache', null, InputOption::VALUE_REQUIRED,
38 1
                'If set, the name of a factory method that will create a PSR-6 cache. "Example\Acme::create"')
39 1
            ->addOption('raw', null, InputOption::VALUE_NONE,
40 1
                'If set, the raw format of the reverse geocoding result')
41 1
            ->addOption('json', null, InputOption::VALUE_NONE,
42 1
                'If set, the json format of the reverse geocoding result')
43 1
            ->addOption('dumper', null, InputOption::VALUE_REQUIRED,
44 1
                'If set, the name of the dumper to use, no dumper by default')
45 1
            ->addOption('args', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
46 1
                'If set, the provider constructor arguments like api key, locale, region, ssl, toponym and service')
47 1
            ->setHelp(<<<EOT
48 1
<info>Available providers</info>:  {$this->getProviders()} <comment>(some providers need arguments)</comment>
49 1
<info>Available dumpers</info>:    {$this->getDumpers()}
50 1
51 1
<info>Use the default provider with the socket adapter and dump the output in WKT standard</info>:
52
53
    %command.full_name% paris <comment>--adapter=socket --dumper=wkt</comment>
54
55
<info>Use the OpenStreetMaps provider with the default adapter</info>:
56
57
    %command.full_name% paris <comment>--provider=openstreetmaps</comment>
58
59
<info>Use the FreeGeoIp provider with the socket adapter</info>
60
61
    %command.full_name% 74.200.247.59 <comment>--provider="free_geo_ip" --adapter="socket"</comment>
62
63
<info>Use the default provider with the french locale and region via SSL</info>:
64
65
    %command.full_name% "Tagensvej 47, Copenhagen" <comment>--args=da_DK --args=Denmark --args="true"</comment>
66
EOT
67
            );
68
    }
69
70 1
    protected function execute(InputInterface $input, OutputInterface $output)
71
    {
72
        $geocoder = new ProviderAggregator;
73
        $httpClient = HttpClientDiscovery::find();
74
        $provider = $this->getProvider($input->getOption('provider'));
75
76
        if ($input->getOption('args')) {
77
            $args = is_array($input->getOption('args'))
78
                ? implode(',', $input->getOption('args'))
79
                : $input->getOption('args');
80
            $geocoder->registerProvider(new $provider($httpClient, $args));
81
        } else {
82
            $geocoder->registerProvider(new $provider($httpClient));
83
        }
84
85
        $batch = new Batch($geocoder);
86
        if ($input->getOption('cache')) {
87
            $batch->setCache($this->getCache($input->getOption('cache')));
88
        }
89
90
        $geocoded = $batch->geocode($input->getArgument('value'))->parallel();
0 ignored issues
show
It seems like $input->getArgument('value') targeting Symfony\Component\Consol...nterface::getArgument() can also be of type null; however, League\Geotools\Batch\Batch::geocode() does only seem to accept string|array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
91
        $address = $geocoded[0]->first();
92
93
        if ($input->getOption('raw')) {
94
            $result = array();
95
            $result[] = sprintf('<label>HttpClient</label>:       <value>%s</value>', get_class($httpClient));
96
            $result[] = sprintf('<label>Provider</label>:      <value>%s</value>', $provider);
97
            $result[] = sprintf('<label>Cache</label>:         <value>%s</value>', isset($cache) ? $cache : 'None');
0 ignored issues
show
The variable $cache seems to never exist, and therefore isset should always return false. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
98
            if ($input->getOption('args')) {
99
                $result[] = sprintf('<label>Arguments</label>:     <value>%s</value>', $args);
100
            }
101
            $result[] = '---';
102
            $coordinates = $address->getCoordinates();
103
            $result[] = sprintf('<label>Latitude</label>:      <value>%s</value>', null !== $coordinates ? $coordinates->getLatitude() : '');
104
            $result[] = sprintf('<label>Longitude</label>:     <value>%s</value>', null !== $coordinates ? $coordinates->getLongitude() : '');
105
            if ($address->getBounds()) {
106
                $bounds = $address->getBounds()->toArray();
107
                $result[] = '<label>Bounds</label>';
108
                $result[] = sprintf(' - <label>South</label>: <value>%s</value>', $bounds['south']);
109
                $result[] = sprintf(' - <label>West</label>:  <value>%s</value>', $bounds['west']);
110
                $result[] = sprintf(' - <label>North</label>: <value>%s</value>', $bounds['north']);
111
                $result[] = sprintf(' - <label>East</label>:  <value>%s</value>', $bounds['east']);
112
            }
113
            $result[] = sprintf('<label>Street Number</label>: <value>%s</value>', $address->getStreetNumber());
114
            $result[] = sprintf('<label>Street Name</label>:   <value>%s</value>', $address->getStreetName());
115
            $result[] = sprintf('<label>Zipcode</label>:       <value>%s</value>', $address->getPostalCode());
116
            $result[] = sprintf('<label>City</label>:          <value>%s</value>', $address->getLocality());
117
            $result[] = sprintf('<label>City District</label>: <value>%s</value>', $address->getSublocality());
118
            if (null !== $adminLevels = $address->getAdminLevels()) {
119
                $result[] = '<label>Admin Levels</label>';
120
                foreach ($adminLevels as $adminLevel) {
121
                    $result[] = sprintf(' - <label>%s</label>: <value>%s</value>', $adminLevel->getCode(), $adminLevel->getName());
122
                }
123
            }
124
            $country = $address->getCountry();
125
            $result[] = sprintf('<label>Country</label>:       <value>%s</value>', null !== $country ? $country->getName() : '');
126
            $result[] = sprintf('<label>Country Code</label>:  <value>%s</value>', null !== $country ? $country->getCode() : '');
127
            $result[] = sprintf('<label>Timezone</label>:      <value>%s</value>', $address->getTimezone());
128
        } elseif ($input->getOption('json')) {
129
            $result = sprintf('<value>%s</value>', json_encode($address->toArray()));
130
        } elseif ($input->getOption('dumper')) {
131
            $dumper = $this->getDumper($input->getOption('dumper'));
132
            $dumper = new $dumper;
133
            $result = sprintf('<value>%s</value>', $dumper->dump($address));
134
        } else {
135
            $coordinates = $address->getCoordinates();
136
            $result = '<value>null, null</value>';
137
            if (null !== $coordinates) {
138
                $result = sprintf('<value>%s, %s</value>', $coordinates->getLatitude(), $coordinates->getLongitude());
139
            }
140
        }
141
142
        $output->writeln($result);
0 ignored issues
show
It seems like $result defined by array() on line 94 can also be of type array<integer,string>; however, Symfony\Component\Consol...putInterface::writeln() does only seem to accept string|object<Symfony\Co...onsole\Output\iterable>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
143
        return 0;
144
    }
145
}
146