This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php namespace nyx\utils\str; |
||
2 | |||
3 | // Internal includes |
||
4 | use nyx\utils; |
||
5 | |||
6 | /** |
||
7 | * Cases |
||
8 | * |
||
9 | * Multi-byte safe utility for manipulating the character case in strings. |
||
10 | * |
||
11 | * @package Nyx\Utils\Strings |
||
12 | * @version 0.1.0 |
||
13 | * @author Michal Chojnacki <[email protected]> |
||
14 | * @copyright 2012-2016 Nyx Dev Team |
||
15 | * @link http://docs.muyo.io/nyx/utils/strings.html |
||
16 | */ |
||
17 | class Cases |
||
18 | { |
||
19 | /** |
||
20 | * The traits of the Cases class. |
||
21 | */ |
||
22 | use utils\traits\StaticallyExtendable; |
||
23 | |||
24 | /** |
||
25 | * Converts the string to "camelCase" using whitespace, dashes and underscores as case delimiters (all of |
||
26 | * which will be effectively removed). |
||
27 | * |
||
28 | * @param string $str The string to convert. |
||
29 | * @param string|null $encoding The encoding to use. |
||
30 | * @return string The converted string. |
||
31 | */ |
||
32 | public static function camel(string $str, string $encoding = null) : string |
||
33 | { |
||
34 | $encoding = $encoding ?: utils\Str::encoding($str); |
||
35 | |||
36 | return static::lowerFirst(static::studly($str, $encoding), $encoding); |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * Shorthand alias for @see Cases::delimit() using a dash as delimiter. |
||
41 | * |
||
42 | * @param string $str The string to convert. |
||
43 | * @param string|null $encoding The encoding to use. |
||
44 | * @return string The resulting string. |
||
45 | */ |
||
46 | public static function dashed(string $str, string $encoding = null) : string |
||
47 | { |
||
48 | return static::delimit($str, '-', $encoding); |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * Delimits the given string on spaces, underscores and dashes and before uppercase characters using the |
||
53 | * given delimiter string. The resulting string will also be trimmed and lower-cased. |
||
54 | * |
||
55 | * @param string $str The string to delimit. |
||
56 | * @param string $delimiter The delimiter to use. Can be a sequence of multiple characters. |
||
57 | * @param string|null $encoding The encoding to use. |
||
58 | * @return string The resulting string. |
||
59 | * @todo Decide whether to keep the trimming and case change in here (too much responsibility). |
||
60 | */ |
||
61 | public static function delimit(string $str, string $delimiter, string $encoding = null) : string |
||
62 | { |
||
63 | $encoding = $encoding ?: utils\Str::encoding($str); |
||
64 | |||
65 | // Keep track of the internal encoding as we'll change it temporarily and then revert back to it. |
||
66 | $internalEncoding = mb_regex_encoding(); |
||
67 | |||
68 | // Swap out the internal encoding for what we want... |
||
69 | mb_regex_encoding($encoding); |
||
70 | |||
71 | // ... trim the input string, convert it to lowercase, insert the delimiter. |
||
72 | $str = mb_ereg_replace('\B([A-Z])', '-\1', mb_ereg_replace("^[[:space:]]+|[[:space:]]+\$", '', $str)); |
||
73 | $str = mb_strtolower($str, $encoding); |
||
74 | $str = mb_ereg_replace('[-_\s]+', $delimiter, $str); |
||
75 | |||
76 | // Restore the initial internal encoding. |
||
77 | mb_regex_encoding($internalEncoding); |
||
78 | |||
79 | return $str; |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * Converts all characters in the given string to lowercase. |
||
84 | * |
||
85 | * @param string $str The string to convert. |
||
86 | * @param string|null $encoding The encoding to use. |
||
87 | * @return string The converted string. |
||
88 | */ |
||
89 | public static function lower(string $str, string $encoding = null) : string |
||
90 | { |
||
91 | return mb_strtolower($str, $encoding ?: utils\Str::encoding($str)); |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * Converts the first character in the given string to lowercase. |
||
96 | * |
||
97 | * @param string $str The string to convert. |
||
98 | * @param string|null $encoding The encoding to use. |
||
99 | * @return string The converted string. |
||
100 | */ |
||
101 | View Code Duplication | public static function lowerFirst(string $str, string $encoding = null) : string |
|
0 ignored issues
–
show
|
|||
102 | { |
||
103 | $encoding = $encoding ?: utils\Str::encoding($str); |
||
104 | |||
105 | // Lowercase the first character and append the remainder. |
||
106 | return mb_strtolower(mb_substr($str, 0, 1, $encoding), $encoding) . mb_substr($str, 1, null, $encoding); |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * Converts the string to "snake_case" using whitespace, dashes and underscores as case delimiters (all of |
||
111 | * which will be effectively removed). |
||
112 | * |
||
113 | * Shorthand alias for @see Cases::delimit() using an uderscore as delimiter. |
||
114 | * |
||
115 | * @param string $str The string to convert. |
||
116 | * @param string|null $encoding The encoding to use. |
||
117 | * @return string The resulting string. |
||
118 | */ |
||
119 | public static function snake(string $str, string $encoding = null) : string |
||
120 | { |
||
121 | return static::delimit($str, '_', $encoding); |
||
122 | } |
||
123 | |||
124 | /** |
||
125 | * Converts the string to "StudlyCaps" using whitespace, dashes and underscores as case delimiters (all of |
||
126 | * which will be effectively removed). This is, essentially, simply a variant of camelCase which starts |
||
127 | * with a capital letter. |
||
128 | * |
||
129 | * @param string $str The string to convert. |
||
130 | * @param string|null $encoding The encoding to use. |
||
131 | * @return string The converted string. |
||
132 | */ |
||
133 | public static function studly(string $str, string $encoding = null) : string |
||
134 | { |
||
135 | $encoding = $encoding ?: utils\Str::encoding($str); |
||
136 | |||
137 | // Convert dashes and underscores to spaces, then convert the string to title case (ie. ucwords()). |
||
138 | // Note: We are using a simple str_replace here since we are looking for exact characters known |
||
139 | // to not be multi-byte. |
||
140 | $str = mb_convert_case(str_replace(['-', '_'], ' ', $str), MB_CASE_TITLE, $encoding); |
||
141 | |||
142 | // Lastly we are going to remove *all* whitespace characters, including multi-byte whitespace, tabs, |
||
143 | // newlines etc., which will effectively trim and collapse the string. |
||
144 | return utils\Str::replace($str, '[[:space:]]', ' ', 'msr', $encoding); |
||
145 | } |
||
146 | |||
147 | /** |
||
148 | * Converts the given string to title case. Multi-byte-safe equivalent of ucwords(). |
||
149 | * |
||
150 | * @param string $str The string to convert. |
||
151 | * @param string|null $encoding The encoding to use. |
||
152 | * @return string The converted string. |
||
153 | */ |
||
154 | public static function title(string $str, string $encoding = null) : string |
||
155 | { |
||
156 | return mb_convert_case($str, MB_CASE_TITLE, $encoding ?: utils\Str::encoding($str)); |
||
157 | } |
||
158 | |||
159 | /** |
||
160 | * Converts all characters in the given string to uppercase. |
||
161 | * |
||
162 | * @param string $str The string to convert. |
||
163 | * @param string|null $encoding The encoding to use. |
||
164 | * @return string The converted string. |
||
165 | */ |
||
166 | public static function upper(string $str, string $encoding = null) : string |
||
167 | { |
||
168 | return mb_strtoupper($str, $encoding ?: utils\Str::encoding($str)); |
||
169 | } |
||
170 | |||
171 | /** |
||
172 | * Converts the first character in the given string to uppercase. |
||
173 | * |
||
174 | * @param string $str The string to convert. |
||
175 | * @param string|null $encoding The encoding to use. |
||
176 | * @return string The converted string. |
||
177 | */ |
||
178 | View Code Duplication | public static function upperFirst(string $str, string $encoding = null) : string |
|
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. ![]() |
|||
179 | { |
||
180 | $encoding = $encoding ?: utils\Str::encoding($str); |
||
181 | |||
182 | // Uppercase the first character and append the remainder. |
||
183 | return mb_strtoupper(mb_substr($str, 0, 1, $encoding), $encoding) . mb_substr($str, 1, null, $encoding); |
||
184 | } |
||
185 | } |
||
186 |
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.