Issues (115)

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/Geography/Address.php (15 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 ValueObjects\Geography;
4
5
use ValueObjects\Util\Util;
6
use ValueObjects\ValueObjectInterface;
7
use ValueObjects\StringLiteral\StringLiteral;
8
9
class Address implements ValueObjectInterface
10
{
11
    /**
12
     * Name of the addressee (natural person or company)
13
     * @var StringLiteral
14
     */
15
    protected $name;
16
17
    /** @var Street */
18
    protected $street;
19
20
    /**
21
     * District/City area
22
     * @var StringLiteral
23
     */
24
    protected $district;
25
26
    /**
27
     * City/Town/Village
28
     * @var StringLiteral
29
     */
30
    protected $city;
31
32
    /**
33
     * Region/County/State
34
     * @var StringLiteral
35
     */
36
    protected $region;
37
38
    /**
39
     * Postal code/P.O. Box/ZIP code
40
     * @var StringLiteral
41
     */
42
    protected $postalCode;
43
44
    /** @var Country */
45
    protected $country;
46
47
    /**
48
     * Returns a new Address from native PHP arguments
49
     *
50
     * @param string $name
0 ignored issues
show
There is no parameter named $name. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
51
     * @param string $street_name
0 ignored issues
show
There is no parameter named $street_name. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
52
     * @param string $street_number
0 ignored issues
show
There is no parameter named $street_number. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
53
     * @param string $district
0 ignored issues
show
There is no parameter named $district. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
54
     * @param string $city
0 ignored issues
show
There is no parameter named $city. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
55
     * @param string $region
0 ignored issues
show
There is no parameter named $region. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
56
     * @param string $postal_code
0 ignored issues
show
There is no parameter named $postal_code. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
57
     * @param string $country_code
0 ignored issues
show
There is no parameter named $country_code. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
58
     * @return self
59
     * @throws \BadMethodCallException
60
     */
61 2
    public static function fromNative()
62
    {
63 2
        $args = \func_get_args();
64
65 2
        if (\count($args) != 8) {
66 1
            throw new \BadMethodCallException('You must provide exactly 8 arguments: 1) addressee name, 2) street name, 3) street number, 4) district, 5) city, 6) region, 7) postal code, 8) country code.');
67
        }
68
69 1
        $name       = new StringLiteral($args[0]);
70 1
        $street     = new Street(new StringLiteral($args[1]), new StringLiteral($args[2]));
71 1
        $district   = new StringLiteral($args[3]);
72 1
        $city       = new StringLiteral($args[4]);
73 1
        $region     = new StringLiteral($args[5]);
74 1
        $postalCode = new StringLiteral($args[6]);
75 1
        $country    = Country::fromNative($args[7]);
76
77 1
        return new static($name, $street, $district, $city, $region, $postalCode, $country);
78
    }
79
80
    /**
81
     * Returns a new Address object
82
     *
83
     * @param StringLiteral $name
84
     * @param Street        $street
85
     * @param StringLiteral $district
86
     * @param StringLiteral $city
87
     * @param StringLiteral $region
88
     * @param StringLiteral $postalCode
89
     * @param Country $country
90
     */
91 11
    public function __construct(StringLiteral $name, Street $street, StringLiteral $district, StringLiteral $city, StringLiteral $region, StringLiteral $postalCode, Country $country)
92
    {
93 11
        $this->name       = $name;
94 11
        $this->street     = $street;
95 11
        $this->district   = $district;
96 11
        $this->city       = $city;
97 11
        $this->region     = $region;
98 11
        $this->postalCode = $postalCode;
99 11
        $this->country    = $country;
100 11
    }
101
102
    /**
103
     * Tells whether two Address are equal
104
     *
105
     * @param  ValueObjectInterface $address
106
     * @return bool
107
     */
108 2
    public function sameValueAs(ValueObjectInterface $address)
109
    {
110 2
        if (false === Util::classEquals($this, $address)) {
111 1
            return false;
112
        }
113
114 2
        return $this->getName()->sameValueAs($address->getName())             &&
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface ValueObjects\ValueObjectInterface as the method getName() does only exist in the following implementations of said interface: ValueObjects\DateTime\Month, ValueObjects\DateTime\TimeZone, ValueObjects\DateTime\WeekDay, ValueObjects\Enum\Enum, ValueObjects\Geography\Address, ValueObjects\Geography\Continent, ValueObjects\Geography\Country, ValueObjects\Geography\CountryCode, ValueObjects\Geography\DistanceFormula, ValueObjects\Geography\DistanceUnit, ValueObjects\Geography\Ellipsoid, ValueObjects\Geography\Street, ValueObjects\Money\CurrencyCode, ValueObjects\Number\RoundingMode, ValueObjects\Person\Gender, ValueObjects\Web\IPAddressVersion.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
115 2
               $this->getStreet()->sameValueAs($address->getStreet())         &&
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface ValueObjects\ValueObjectInterface as the method getStreet() does only exist in the following implementations of said interface: ValueObjects\Geography\Address.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
116 2
               $this->getDistrict()->sameValueAs($address->getDistrict())     &&
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface ValueObjects\ValueObjectInterface as the method getDistrict() does only exist in the following implementations of said interface: ValueObjects\Geography\Address.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
117 2
               $this->getCity()->sameValueAs($address->getCity())             &&
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface ValueObjects\ValueObjectInterface as the method getCity() does only exist in the following implementations of said interface: ValueObjects\Geography\Address.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
118 2
               $this->getRegion()->sameValueAs($address->getRegion())         &&
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface ValueObjects\ValueObjectInterface as the method getRegion() does only exist in the following implementations of said interface: ValueObjects\Geography\Address.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
119 2
               $this->getPostalCode()->sameValueAs($address->getPostalCode()) &&
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface ValueObjects\ValueObjectInterface as the method getPostalCode() does only exist in the following implementations of said interface: ValueObjects\Geography\Address.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
120 2
               $this->getCountry()->sameValueAs($address->getCountry())
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface ValueObjects\ValueObjectInterface as the method getCountry() does only exist in the following implementations of said interface: ValueObjects\Geography\Address.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
121 2
        ;
122
    }
123
124
    /**
125
     * Returns addressee name
126
     *
127
     * @return StringLiteral
128
     */
129 4
    public function getName()
130
    {
131 4
        return clone $this->name;
132
    }
133
134
    /**
135
     * Returns street
136
     *
137
     * @return Street
138
     */
139 4
    public function getStreet()
140
    {
141 4
        return clone $this->street;
142
    }
143
144
    /**
145
     * Returns district
146
     *
147
     * @return StringLiteral
148
     */
149 3
    public function getDistrict()
150
    {
151 3
        return clone $this->district;
152
    }
153
154
    /**
155
     * Returns city
156
     *
157
     * @return StringLiteral
158
     */
159 4
    public function getCity()
160
    {
161 4
        return clone $this->city;
162
    }
163
164
    /**
165
     * Returns region
166
     *
167
     * @return StringLiteral
168
     */
169 4
    public function getRegion()
170
    {
171 4
        return clone $this->region;
172
    }
173
174
    /**
175
     * Returns postal code
176
     *
177
     * @return StringLiteral
178
     */
179 4
    public function getPostalCode()
180
    {
181 4
        return clone $this->postalCode;
182
    }
183
184
    /**
185
     * Returns country
186
     *
187
     * @return Country
188
     */
189 4
    public function getCountry()
190
    {
191 4
        return clone $this->country;
192
    }
193
194
    /**
195
     * Returns a string representation of the Address in US standard format.
196
     *
197
     * @return string
198
     */
199 1
    public function __toString()
200
    {
201
        $format = <<<ADDR
202
%s
203
%s
204
%s %s %s
205
%s
206 1
ADDR;
207
208 1
        $addressString = \sprintf($format, $this->getName(), $this->getStreet(), $this->getCity(), $this->getRegion(), $this->getPostalCode(), $this->getCountry());
209
210 1
        return $addressString;
211
    }
212
}
213