Issues (2)

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/Telephone.php (2 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 Zenapply\DataTypes;
4
5
use libphonenumber\PhoneNumberUtil as Util;
6
use libphonenumber\PhoneNumberFormat as Format;
7
use libphonenumber\PhoneNumberType as Type;
8
9
/**
10
 * @see https://en.wikipedia.org/wiki/Telephone_numbering_plan#Structure
11
 */
12
class Telephone 
13
{
14
    //Telephone variations
15
    protected $format_E164;
16
    protected $format_international;
17
    protected $format_national;
18
    protected $format_RFC3966;
19
20
    //Telephone structure
21
    protected $country_code;
22
    protected $area_code;
23
    protected $subscriber_code;
24
    protected $extension;
25
26
    //Telephone extras
27
    protected $region;
28
    protected $input;
29
    protected $valid;
30
    protected $type;
31
32
    //Telephone types
33
    protected $typeMap = [
34
        Type::FIXED_LINE => 'FIXED_LINE',
35
        Type::MOBILE => 'MOBILE',
36
        Type::FIXED_LINE_OR_MOBILE => 'FIXED_LINE_OR_MOBILE',
37
        Type::TOLL_FREE => 'TOLL_FREE',
38
        Type::PREMIUM_RATE => 'PREMIUM_RATE',
39
        Type::SHARED_COST => 'SHARED_COST',
40
        Type::VOIP => 'VOIP',
41
        Type::PERSONAL_NUMBER => 'PERSONAL_NUMBER',
42
        Type::PAGER => 'PAGER',
43
        Type::UAN => 'UAN',
44
        Type::UNKNOWN => 'UNKNOWN',
45
        Type::EMERGENCY => 'EMERGENCY',
46
        Type::VOICEMAIL => 'VOICEMAIL',
47
        Type::SHORT_CODE => 'SHORT_CODE',
48
        Type::STANDARD_RATE => 'STANDARD_RATE',
49
    ];
50
51
    /**
52
     * @param string $input  The phone number
53
     * @param string $region The region or country of the phone number
54
     */
55 6
    public function __construct($input,$region = 'US')
56
    {
57 6
        $this->input = $input;
58 6
        $this->region = $region;
59 6
        $this->setup();
60 6
    }
61
62
    /**
63
     * @return void
64
     */
65 6
    protected function setup()
66
    {
67 6
        $util = Util::getInstance();
68 6
        $number = $util->parse($this->input, $this->region);
69
        
70
        //Meta
71 6
        $this->valid  = $util->isValidNumber($number);
72 6
        $this->type   = $this->typeMap[$util->getNumberType($number)];
73
74
        //Formats
75 6
        $this->format_E164          = $util->format($number, Format::E164);
76 6
        $this->format_international = $util->format($number, Format::INTERNATIONAL);
77 6
        $this->format_national      = $util->format($number, Format::NATIONAL);
78 6
        $this->format_RFC3966       = $util->format($number, Format::RFC3966);
79
        
80
        //Get the parts
81 6
        $this->country_code    = $number->getCountryCode();
82 6
        $this->extension       = $number->getExtension();
83 6
        $this->area_code       = $this->extractAreaCode();
84 6
        $this->subscriber_code = $this->extractSubscriberCode();
85 6
    }
86
87 6 View Code Duplication
    protected function extractAreaCode()
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...
88
    {
89 6
        if($this->region === 'US' && $this->isValid()){
90 6
            $exp = '/^\+?(1)?\s?\(?(\d{3})\)?(?:\s|\.|\-)?(\d{3})(?:\s|\.|\-)?(\d{4})$/';
91 6
            preg_match($exp,$this->format_E164,$matches);
92 6
            if(count($matches) === 5){
93 6
                return $matches[2];
94
            }
95
        }
96
97
        return null;
98
    }
99
100 6 View Code Duplication
    protected function extractSubscriberCode()
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...
101
    {
102 6
        if($this->region === 'US' && $this->isValid()){
103 6
            $exp = '/^\+?(1)?\s?\(?(\d{3})\)?(?:\s|\.|\-)?(\d{3})(?:\s|\.|\-)?(\d{4})$/';
104 6
            preg_match($exp,$this->format_E164,$matches);
105 6
            if(count($matches) === 5){
106 6
                return $matches[3] . $matches[4];
107
            }
108
        }
109
110
        return null;
111
    }
112
113
    /*=====================================
114
    =            Ouput Methods            =
115
    =====================================*/
116
117
    /**
118
     * @return string
119
     */
120 3
    public function getRFC3966()
121
    {
122 3
        return $this->format_RFC3966;
123
    }
124
125
    /**
126
     * @return string
127
     */
128 3
    public function getNational()
129
    {
130 3
        return $this->format_national;
131
    }
132
133
    /**
134
     * @return string
135
     */
136 3
    public function getInternational()
137
    {
138 3
        return $this->format_international;
139
    }
140
141
    /**
142
     * @return string
143
     */
144 3
    public function getE164()
145
    {
146 3
        return $this->format_E164;
147
    }
148
149
150
    /**
151
     * @return string
152
     */
153 3
    public function getOriginal()
154
    {
155 3
        return $this->input;
156
    }
157
158
    /**
159
     * @return string
160
     */
161 3
    public function getAreaCode()
162
    {
163 3
        return $this->area_code;
164
    }
165
166
    /**
167
     * @return string
168
     */
169 3
    public function getCountryCode()
170
    {
171 3
        return $this->country_code;
172
    }
173
174
    /**
175
     * @return string
176
     */
177 3
    public function getSubscriberCode()
178
    {
179 3
        return $this->subscriber_code;
180
    }
181
182
    /**
183
     * @return string
184
     */
185 3
    public function getType()
186
    {
187 3
        return $this->type;
188
    }
189
190
    /**
191
     * @return string
192
     */
193 6
    public function isValid()
194
    {
195 6
        return $this->valid;
196
    }
197
198
    /**
199
     * @return string
200
     */
201 3
    public function __toString()
202
    {
203 3
        return $this->getE164();
204
    }
205
    
206
    /*=====  End of Ouput Methods  ======*/
207
}