Issues (135)

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/Generics.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 declare(strict_types=1);
2
3
namespace Limoncello\Validation\Validator;
4
5
/**
6
 * Copyright 2015-2020 [email protected]
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 * http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
21
use Limoncello\Validation\Contracts\Errors\ErrorCodes;
22
use Limoncello\Validation\Contracts\Rules\RuleInterface;
23
use Limoncello\Validation\I18n\Messages;
24
use Limoncello\Validation\Rules\Generic\AndOperator;
25
use Limoncello\Validation\Rules\Generic\Enum;
26
use Limoncello\Validation\Rules\Generic\Fail;
27
use Limoncello\Validation\Rules\Generic\Filter;
28
use Limoncello\Validation\Rules\Generic\IfOperator;
29
use Limoncello\Validation\Rules\Generic\OrOperator;
30
use Limoncello\Validation\Rules\Generic\Required;
31
use Limoncello\Validation\Rules\Generic\Success;
32
use Limoncello\Validation\Rules\Generic\Value;
33
use function assert;
34
use function is_resource;
35
36
/**
37
 * @package Limoncello\Validation
38
 */
39
trait Generics
40
{
41
    /**
42
     * @param RuleInterface $first
43
     * @param RuleInterface $second
44
     *
45
     * @return RuleInterface
46
     */
47 1
    protected static function andX(RuleInterface $first, RuleInterface $second): RuleInterface
48
    {
49 1
        return new AndOperator($first, $second);
50
    }
51
52
    /**
53
     * @param RuleInterface $primary
54
     * @param RuleInterface $secondary
55
     *
56
     * @return RuleInterface
57
     */
58 1
    protected static function orX(RuleInterface $primary, RuleInterface $secondary): RuleInterface
59
    {
60 1
        return new OrOperator($primary, $secondary);
61
    }
62
63
    /**
64
     * @param callable      $condition
65
     * @param RuleInterface $onTrue
66
     * @param RuleInterface $onFalse
67
     * @param array         $settings
68
     *
69
     * @return RuleInterface
70
     */
71 3
    protected static function ifX(
72
        callable $condition,
73
        RuleInterface $onTrue,
74
        RuleInterface $onFalse,
75
        array $settings = []
76
    ): RuleInterface {
77 3
        return new IfOperator($condition, $onTrue, $onFalse, $settings);
78
    }
79
80
    /**
81
     * @return RuleInterface
82
     */
83 10
    protected static function success(): RuleInterface
84
    {
85 10
        return new Success();
86
    }
87
88
    /**
89
     * @param int    $errorCode
90
     * @param string $messageTemplate
91
     * @param array  $messageParams
92
     *
93
     * @return RuleInterface
94
     */
95 3
    protected static function fail(
96
        int $errorCode = ErrorCodes::INVALID_VALUE,
97
        string $messageTemplate = Messages::INVALID_VALUE,
98
        array $messageParams = []
99
    ): RuleInterface {
100 3
        return new Fail($errorCode, $messageTemplate, $messageParams);
101
    }
102
103
    /**
104
     * @param mixed $value
105
     *
106
     * @return RuleInterface
107
     */
108 1
    protected static function value($value): RuleInterface
109
    {
110
        // check the value is not a resource and can be represented as string
111 1
        assert(is_resource($value) === false);
112
113 1
        return new Value($value);
114
    }
115
116
    /**
117
     * @param array              $values
118
     * @param RuleInterface|null $next
119
     *
120
     * @return RuleInterface
121
     */
122 1
    protected static function enum(array $values, RuleInterface $next = null): RuleInterface
123
    {
124 1
        return $next === null ? new Enum($values) : new AndOperator(static::enum($values), $next);
125
    }
126
127
    /**
128
     * @param int                $filterId
129
     * @param mixed              $options
130
     * @param int                $errorCode
131
     * @param string             $messageTemplate
132
     * @param RuleInterface|null $next
133
     *
134
     * @return RuleInterface
135
     */
136 1
    protected static function filter(
137
        int $filterId,
138
        $options = null,
139
        int $errorCode = ErrorCodes::INVALID_VALUE,
140
        string $messageTemplate = Messages::INVALID_VALUE,
141
        RuleInterface $next = null
142
    ): RuleInterface {
143 1
        $filterRule = new Filter($filterId, $options, $errorCode, $messageTemplate);
144
145 1
        return $next === null ? $filterRule : new AndOperator($filterRule, $next);
146
    }
147
148
    /**
149
     * @param RuleInterface $rule
0 ignored issues
show
Should the type for parameter $rule not be null|RuleInterface?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
150
     *
151
     * @return RuleInterface
152
     */
153 1
    protected static function required(RuleInterface $rule = null): RuleInterface
154
    {
155 1
        return $rule === null ? new Required(static::success()) : new Required($rule);
156
    }
157
}
158