Issues (7)

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/Rule/Length.php (1 issue)

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
declare(strict_types=1);
3
/**
4
 * Caridea
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
7
 * use this file except in compliance with the License. You may obtain a copy of
8
 * the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
 * License for the specific language governing permissions and limitations under
16
 * the License.
17
 *
18
 * @copyright 2015-2018 LibreWorks contributors
19
 * @license   Apache-2.0
20
 */
21
namespace Caridea\Validate\Rule;
22
23
/**
24
 * Compares string length to accepted boundaries.
25
 *
26
 * @copyright 2015-2018 LibreWorks contributors
27
 * @license   Apache-2.0
28
 */
29
class Length implements \Caridea\Validate\Rule
30
{
31
    /**
32
     * @var string The operator type
33
     */
34
    private $operator;
35
    /**
36
     * @var int|int[] The length comparison
37
     */
38
    private $length;
39
    /**
40
     * @var string The encoding to pass to `mb_strlen`
41
     */
42
    private $encoding;
43
44
    /**
45
     * Creates a new LengthRule.
46
     *
47
     * @param string $operator The operator type
48
     * @param int|int[] $length The length comparison
49
     * @param string $encoding The encoding to pass to `mb_strlen`
50
     */
51 4
    protected function __construct(string $operator, $length, string $encoding = 'UTF-8')
52
    {
53 4
        $this->operator = $operator;
54 4
        $this->length = $length;
55 4
        $this->encoding = $encoding;
56 4
    }
57
58
    /**
59
     * {@inheritDoc}
60
     */
61 4
    public function apply($value, $data = []): ?array
62
    {
63 4
        if (!is_string($value)) {
64 4
            return ['FORMAT_ERROR'];
65
        }
66 4
        $length = mb_strlen($value, $this->encoding);
67 4
        switch ($this->operator) {
68 4
            case "lt":
0 ignored issues
show
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
69 1
                return $length > $this->length ? ['TOO_LONG'] : null;
70 3
            case "gt":
71 1
                return $length < $this->length ? ['TOO_SHORT'] : null;
72 2
            case "eq":
73 1
                if ($length > $this->length) {
74 1
                    return ['TOO_LONG'];
75 1
                } elseif ($length < $this->length) {
76 1
                    return ['TOO_SHORT'];
77
                }
78 1
                return null;
79 1
            case "bt":
80 1
                if ($length > $this->length[1]) {
81 1
                    return ['TOO_LONG'];
82 1
                } elseif ($length < $this->length[0]) {
83 1
                    return ['TOO_SHORT'];
84
                }
85 1
                return null;
86
        }
87
    }
88
89
    /**
90
     * Gets a rule that requires strings to be no longer than the limit.
91
     *
92
     * @param int $length The maximum length
93
     * @param string $encoding The string encoding
94
     * @return \Caridea\Validate\Rule\Length the created rule
95
     */
96 1
    public static function max(int $length, string $encoding = 'UTF-8'): Length
97
    {
98 1
        return new Length('lt', $length, $encoding);
99
    }
100
101
    /**
102
     * Gets a rule that requires strings to be no shorter than the limit.
103
     *
104
     * @param int $length The minimum length
105
     * @param string $encoding The string encoding
106
     * @return \Caridea\Validate\Rule\Length the created rule
107
     */
108 1
    public static function min(int $length, string $encoding = 'UTF-8'): Length
109
    {
110 1
        return new Length('gt', $length, $encoding);
111
    }
112
113
    /**
114
     * Gets a rule that requires strings to be exactly the length of the limit.
115
     *
116
     * @param int $length The required length
117
     * @param string $encoding The string encoding
118
     * @return \Caridea\Validate\Rule\Length the created rule
119
     */
120 1
    public static function equal(int $length, string $encoding = 'UTF-8'): Length
121
    {
122 1
        return new Length('eq', $length, $encoding);
123
    }
124
125
    /**
126
     * Gets a rule that requires strings to have a minimum and maximum length.
127
     *
128
     * @param int $min The minimum length, inclusive
129
     * @param int $max The maximum length, inclusive
130
     * @param string $encoding The string encoding
131
     * @return \Caridea\Validate\Rule\Length the created rule
132
     */
133 1
    public static function between(int $min, int $max, string $encoding = 'UTF-8'): Length
134
    {
135 1
        $length = [$min, $max];
136 1
        sort($length);
137 1
        return new Length('bt', $length, $encoding);
138
    }
139
}
140