Issues (12)

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/Validator.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 Tylercd100\Validator\State;
4
5
use Illuminate\Support\Str;
6
7
class Validator
8
{
9
    protected $params;
10
11
    protected $states = [
12
        "usa" => [
13
            ["abbr" => 'AL', "name" => 'Alabama'],
14
            ["abbr" => 'AK', "name" => 'Alaska'],
15
            ["abbr" => 'AZ', "name" => 'Arizona'],
16
            ["abbr" => 'AR', "name" => 'Arkansas'],
17
            ["abbr" => 'CA', "name" => 'California'],
18
            ["abbr" => 'CO', "name" => 'Colorado'],
19
            ["abbr" => 'CT', "name" => 'Connecticut'],
20
            ["abbr" => 'DC', "name" => 'District Of Columbia'],
21
            ["abbr" => 'DE', "name" => 'Delaware'],
22
            ["abbr" => 'FL', "name" => 'Florida'],
23
            ["abbr" => 'GA', "name" => 'Georgia'],
24
            ["abbr" => 'HI', "name" => 'Hawaii'],
25
            ["abbr" => 'ID', "name" => 'Idaho'],
26
            ["abbr" => 'IL', "name" => 'Illinois'],
27
            ["abbr" => 'IN', "name" => 'Indiana'],
28
            ["abbr" => 'IA', "name" => 'Iowa'],
29
            ["abbr" => 'KS', "name" => 'Kansas'],
30
            ["abbr" => 'KY', "name" => 'Kentucky'],
31
            ["abbr" => 'LA', "name" => 'Louisiana'],
32
            ["abbr" => 'ME', "name" => 'Maine'],
33
            ["abbr" => 'MD', "name" => 'Maryland'],
34
            ["abbr" => 'MA', "name" => 'Massachusetts'],
35
            ["abbr" => 'MI', "name" => 'Michigan'],
36
            ["abbr" => 'MN', "name" => 'Minnesota'],
37
            ["abbr" => 'MS', "name" => 'Mississippi'],
38
            ["abbr" => 'MO', "name" => 'Missouri'],
39
            ["abbr" => 'MT', "name" => 'Montana'],
40
            ["abbr" => 'NE', "name" => 'Nebraska'],
41
            ["abbr" => 'NV', "name" => 'Nevada'],
42
            ["abbr" => 'NH', "name" => 'New Hampshire'],
43
            ["abbr" => 'NJ', "name" => 'New Jersey'],
44
            ["abbr" => 'NM', "name" => 'New Mexico'],
45
            ["abbr" => 'NY', "name" => 'New York'],
46
            ["abbr" => 'NC', "name" => 'North Carolina'],
47
            ["abbr" => 'ND', "name" => 'North Dakota'],
48
            ["abbr" => 'OH', "name" => 'Ohio'],
49
            ["abbr" => 'OK', "name" => 'Oklahoma'],
50
            ["abbr" => 'OR', "name" => 'Oregon'],
51
            ["abbr" => 'PA', "name" => 'Pennsylvania'],
52
            ["abbr" => 'RI', "name" => 'Rhode Island'],
53
            ["abbr" => 'SC', "name" => 'South Carolina'],
54
            ["abbr" => 'SD', "name" => 'South Dakota'],
55
            ["abbr" => 'TN', "name" => 'Tennessee'],
56
            ["abbr" => 'TX', "name" => 'Texas'],
57
            ["abbr" => 'UT', "name" => 'Utah'],
58
            ["abbr" => 'VT', "name" => 'Vermont'],
59
            ["abbr" => 'VA', "name" => 'Virginia'],
60
            ["abbr" => 'WA', "name" => 'Washington'],
61
            ["abbr" => 'WV', "name" => 'West Virginia'],
62
            ["abbr" => 'WI', "name" => 'Wisconsin'],
63
            ["abbr" => 'WY', "name" => 'Wyoming'],
64
            ["abbr" => 'AS', "name" => 'American Samoa'],
65
            ["abbr" => 'FM', "name" => 'Federated States Of Micronesia'],
66
            ["abbr" => 'GU', "name" => 'Guam'],
67
            ["abbr" => 'MH', "name" => 'Marshall Islands'],
68
            ["abbr" => 'MP', "name" => 'Northern Mariana Islands'],
69
            ["abbr" => 'PW', "name" => 'Pala'],
70
            ["abbr" => 'PR', "name" => 'Puerto Rico'],
71
            ["abbr" => 'VI', "name" => 'Virgin Islands']
72
        ],
73
        "canada" => [
74
            ["abbr" => 'AB', "name" => 'Alberta'],
75
            ["abbr" => 'BC', "name" => 'British Columbia'],
76
            ["abbr" => 'MB', "name" => 'Manitoba'],
77
            ["abbr" => 'NB', "name" => 'New Brunswick'],
78
            ["abbr" => 'NL', "name" => 'Newfoundland And Labrador'],
79
            ["abbr" => 'NS', "name" => 'Nova Scotia'],
80
            ["abbr" => 'NT', "name" => 'Northwest Territories'],
81
            ["abbr" => 'NU', "name" => 'Nunavut'],
82
            ["abbr" => 'ON', "name" => 'Ontario'],
83
            ["abbr" => 'PE', "name" => 'Prince Edward Island'],
84
            ["abbr" => 'QC', "name" => 'Quebec'],
85
            ["abbr" => 'SK', "name" => 'Saskatchewan'],
86
            ["abbr" => 'YT', "name" => 'Yukon'],
87
        ],
88
    ];
89
90 30
    public function __construct(Parameters $params)
91
    {
92 30
        $this->params = $params;
93 30
    }
94
95 27
    public function validate($value)
96
    {
97 27
        return $value === null || $value === [] || (
98 27
            is_string($value) &&
99 27
            Str::length($value) > 0 &&
100 27
            $this->validateCountry($value) &&
101 27
            $this->validateCase($value) &&
102 24
            $this->validateType($value)
103 27
        );
104
    }
105
106 24
    protected function validateCountry($value)
107
    {
108 24
        $country = $this->params->getCountry();
109 24
        return $this->isAbbr($value, $country) || $this->isFull($value, $country);
110
    }
111
112 24
    protected function validateCase($value)
113
    {
114 24
        switch ($this->params->getCase()) {
115 24
            case 'lower':
116 3
                return $value === Str::lower($value);
117
118 21
            case 'upper':
119 9
                return $value === Str::upper($value);
120
121 12
            case 'title':
122 3
                return $this->isAbbr($value) ? $value === Str::upper($value) : $value === Str::title($value);
123
124 9
            default:
125 9
                return true;
126 9
        }
127
    }
128
129 24
    protected function validateType($value)
130
    {
131 24
        switch ($this->params->getType()) {
132 24
            case 'abbr':
133 6
                return $this->isAbbr($value);
134 18
            case 'full':
135
                return $this->isFull($value);
136 18
            default:
137 18
                return true;
138 18
        }
139
    }
140
141 24
    protected function isFull($value, $country = null)
142
    {
143 24
        return in_array(Str::title($value), $this->getStateNames($country));
144
    }
145
146 24
    protected function isAbbr($value, $country = null)
147
    {
148 24
        return in_array(Str::upper($value), $this->getStateAbbreviations($country));
149
    }
150
151 24 View Code Duplication
    protected function getStateAbbreviations($country = null)
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...
152
    {
153 24
        $x = [];
154 24
        foreach ($this->states as $c => $states) {
155 24
            if ($country === null || $c === $country) {
156 24
                foreach ($states as $state) {
157 24
                    $x[] = $state['abbr'];
158 24
                }
159 24
            }
160 24
        }
161 24
        return $x;
162
    }
163
164 24 View Code Duplication
    protected function getStateNames($country = null)
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...
165
    {
166 24
        $x = [];
167 24
        foreach ($this->states as $c => $states) {
168 24
            if ($country === null || $c === $country) {
169 24
                foreach ($states as $state) {
170 24
                    $x[] = $state['name'];
171 24
                }
172 24
            }
173 24
        }
174 24
        return $x;
175
    }
176
}
177