Issues (4)

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/Variants.php (4 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 Dgame\Variants;
4
5
use ICanBoogie\Inflector;
6
7
/**
8
 * Class Variants
9
 * @package Dgame\Variants
10
 */
11
class Variants
12
{
13
    /**
14
     * @var string[]
15
     */
16
    private $values = [];
17
18
    /**
19
     * Variants constructor.
20
     *
21
     * @param string[] $values
22
     */
23 5
    public function __construct(array $values)
24
    {
25 5
        $this->values = $values;
26 5
    }
27
28
    /**
29
     * @return string[]
30
     */
31
    final public function getValues(): array
32
    {
33
        return $this->values;
34
    }
35
36
    /**
37
     * @param string ...$values
38
     *
39
     * @return Variants
0 ignored issues
show
Should the return type not be \self?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
40
     */
0 ignored issues
show
Should the type for parameter $values not be string[]?

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...
41 3
    public static function ofArguments(string ...$values): self
42
    {
43 3
        return new self($values);
44
    }
45
46
    /**
47
     * @param array $values
48
     *
49
     * @return Variants
0 ignored issues
show
Should the return type not be \self?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
50
     */
51 2
    public static function ofArray(array $values): self
52
    {
53 2
        return new self($values);
54
    }
55
56
    /**
57
     * @param callable ...$callbacks
58
     *
59
     * @return string[]
60
     */
0 ignored issues
show
Consider making the type for parameter $callbacks a bit more specific; maybe use callable[].
Loading history...
61 2
    final public function with(callable ...$callbacks): array
62
    {
63 2
        $output = [];
64 2
        foreach ($this->values as $value) {
65 2
            foreach ($callbacks as $callback) {
66 2
                $output[] = $callback($value);
67
            }
68
        }
69
70 2
        return $output;
71
    }
72
73
    /**
74
     * @param array $patterns
75
     *
76
     * @return string[]
77
     */
78 1
    final public function withPattern(array $patterns): array
79
    {
80 1
        $output = [];
81 1
        foreach ($this->values as $value) {
82 1
            foreach ($patterns as $pattern => $replacement) {
83 1
                if (is_array($replacement)) {
84 1
                    $output = array_merge(self::replaceArray($pattern, $replacement, $value));
85
                } else {
86 1
                    $output[] = self::replace($pattern, $replacement, $value);
87
                }
88
            }
89
        }
90
91 1
        return $output;
92
    }
93
94
    /**
95
     * @param string $pattern
96
     * @param array  $replacements
97
     * @param string $value
98
     *
99
     * @return array
100
     */
101 1
    private static function replaceArray(string $pattern, array $replacements, string $value): array
102
    {
103 1
        $output = [];
104 1
        foreach ($replacements as $replacement) {
105 1
            $output[] = self::replace($pattern, $replacement, $value);
106
        }
107
108 1
        return $output;
109
    }
110
111
    /**
112
     * @param string $pattern
113
     * @param string $replacement
114
     * @param string $value
115
     *
116
     * @return string|null
117
     */
118 1
    private static function replace(string $pattern, string $replacement, string $value): ?string
119
    {
120 1
        return preg_replace($pattern, $replacement, $value);
121
    }
122
123
    /**
124
     * @return string[]
125
     */
126 1
    final public function withUpperLowerCaseFirst(): array
127
    {
128 1
        return $this->with('lcfirst', 'ucfirst');
129
    }
130
131
    /**
132
     * @return string[]
133
     */
134 1
    final public function withUpperLowerCase(): array
135
    {
136 1
        return $this->with('strtolower', 'strtoupper');
137
    }
138
139
    /**
140
     * @return string[]
141
     */
142 2
    final public function withCamelSnakeCase(): array
143
    {
144 2
        $output = [];
145 2
        foreach ($this->values as $value) {
146 2
            $value = self::replaceWhitespaces($value);
147
            if (empty($value)) {
148 2
                continue;
149 2
            }
150 2
151
            $output[] = Inflector::get()->camelize($value, Inflector::DOWNCASE_FIRST_LETTER);
152
            $output[] = Inflector::get()->camelize($value, Inflector::UPCASE_FIRST_LETTER);
153 2
            $output[] = Inflector::get()->underscore($value);
154
        }
155
156
        return $output;
157
    }
158
159 1
    /**
160
     * @return array
161 1
     */
162 1
    final public function assembled(): array
163 1
    {
164
        $output = $this->withCamelSnakeCase();
165
        foreach ($this->values as $value) {
166 1
            $value = self::replaceWhitespaces($value);
167
            if (empty($value)) {
168
                continue;
169
            }
170
171
            $output[] = Inflector::get()->dasherize($value);
172
        }
173
174 2
        return $output;
175
    }
176 2
177
    /**
178
     * @param string $value
179
     *
180
     * @return string|null
181
     */
182
    private static function replaceWhitespaces(string $value): ?string
183
    {
184
        return preg_replace('/\s+/', '_', trim($value));
185
    }
186
}
187