Issues (17)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  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.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  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.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  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.
  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.
  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.
  Header Injection
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.

app/LibPhoneNumberValidator.php (7 issues)

1
<?php
2
3
namespace App;
4
5
use Exception;
6
use libphonenumber\PhoneNumber;
7
use libphonenumber\PhoneNumberType;
8
use libphonenumber\PhoneNumberUtil;
9
use libphonenumber\PhoneNumberFormat;
10
use libphonenumber\PhoneNumberToCarrierMapper;
11
12
class LibPhoneNumberValidator implements PhoneNumberValidator
13
{
14
    /**
15
     * @var libphonenumber\PhoneNumberUtil
0 ignored issues
show
The type App\libphonenumber\PhoneNumberUtil was not found. Did you mean libphonenumber\PhoneNumberUtil? If so, make sure to prefix the type with \.
Loading history...
16
     */
17
    protected $util;
18
19
    /**
20
     * @var libphonenumber\PhoneNumberToCarrierMapper
0 ignored issues
show
The type App\libphonenumber\PhoneNumberToCarrierMapper was not found. Did you mean libphonenumber\PhoneNumberToCarrierMapper? If so, make sure to prefix the type with \.
Loading history...
21
     */
22
    protected $carrierMapper;
23
24
    /**
25
     * Number to validate.
26
     * @var libphonenumber\PhoneNumber
0 ignored issues
show
The type App\libphonenumber\PhoneNumber was not found. Did you mean libphonenumber\PhoneNumber? If so, make sure to prefix the type with \.
Loading history...
27
     */
28
    protected $number;
29
30
    /**
31
     * @var bool
32
     */
33
    protected $isValid = false;
34
35
    /**
36
     * Instantiate the class and get an instance
37
     * of the libphonenumber util.
38
     */
39 20
    public function __construct(PhoneNumberUtil $util, PhoneNumberToCarrierMapper $carrierMapper)
40
    {
41 20
        $this->util = $util;
0 ignored issues
show
Documentation Bug introduced by
It seems like $util of type libphonenumber\PhoneNumberUtil is incompatible with the declared type App\libphonenumber\PhoneNumberUtil of property $util.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
42 20
        $this->carrierMapper = $carrierMapper;
0 ignored issues
show
Documentation Bug introduced by
It seems like $carrierMapper of type libphonenumber\PhoneNumberToCarrierMapper is incompatible with the declared type App\libphonenumber\PhoneNumberToCarrierMapper of property $carrierMapper.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
43
44
        // Default the phone number to prevent exceptions and allow control flow
45
        // to be handled by the developer with the 'isValid...' methods
46 20
        $this->number = new PhoneNumber;
0 ignored issues
show
Documentation Bug introduced by
It seems like new libphonenumber\PhoneNumber() of type libphonenumber\PhoneNumber is incompatible with the declared type App\libphonenumber\PhoneNumber of property $number.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
47 20
    }
48
49
    /**
50
     * Validate the given number.
51
     *
52
     * @param  mixed        $number
53
     * @param  null|string  $countryCode
54
     * @return App\PhoneNumberValidator
0 ignored issues
show
The type App\App\PhoneNumberValidator was not found. Did you mean App\PhoneNumberValidator? If so, make sure to prefix the type with \.
Loading history...
55
     */
56 19
    public function make($number, string $countryCode = null): PhoneNumberValidator
57
    {
58
        try {
59 19
            $this->number = $this->util->parse($number, $countryCode);
60 1
        } catch (Exception $e) {
61
            // Let the 'isValid' methods handle the control-flow.
62
        }
63
64 19
        return $this;
65
    }
66
67
    /**
68
     * Is the number valid for the given country code.
69
     *
70
     * @param  mixed  $countryCode
71
     * @return bool
72
     */
73 7
    public function isValidForCountry($countryCode): bool
74
    {
75 7
        foreach (array_wrap($countryCode) as $code) {
76 7
            if ($this->util->isValidNumberForRegion($this->number, mb_strtoupper($code))) {
77 7
                return true;
78
            }
79
        }
80
81 2
        return false;
82
    }
83
84
    /**
85
     * Is the number a valid mobile.
86
     *
87
     * @return bool
88
     */
89 7
    public function isValidMobile(): bool
90
    {
91 7
        return $this->util->getNumberType($this->number) === PhoneNumberType::MOBILE;
92
    }
93
94
    /**
95
     * Is the number a valid landline/fixed-line.
96
     *
97
     * @return bool
98
     */
99 2
    public function isValidFixedLine(): bool
100
    {
101 2
        return $this->util->getNumberType($this->number) === PhoneNumberType::FIXED_LINE;
102
    }
103
104
    /**
105
     * Return the carrier name.
106
     *
107
     * @return string
108
     */
109 7
    public function getCarrierName(): string
110
    {
111 7
        return $this->carrierMapper->getNameForNumber($this->number, 'en');
112
    }
113
114
    /**
115
     * Return the phone number.
116
     *
117
     * @return string
118
     */
119 6
    public function getNumber(): string
120
    {
121 6
        return $this->util->format($this->number, PhoneNumberFormat::INTERNATIONAL);
122
    }
123
124
    /**
125
     * Get a new instance of the validator.
126
     *
127
     * @param libphonenumber\PhoneNumberToCarrierMapper $mapper
128
     */
129 20
    public static function getInstance()
130
    {
131 20
        return new static(PhoneNumberUtil::getInstance(), PhoneNumberToCarrierMapper::getInstance());
132
    }
133
}
134