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 Recca0120\LoDash\JString; |
||
4 | |||
5 | use Recca0120\LoDash\JArray; |
||
6 | use Recca0120\LoDash\JString\Extensions\Chinese; |
||
7 | use Recca0120\LoDash\JString\Extensions\FullCase; |
||
8 | use Recca0120\LoDash\JString\Extensions\Converter; |
||
9 | |||
10 | trait PHP |
||
11 | { |
||
12 | /** |
||
13 | * Quote string with slashes in a C style. |
||
14 | * |
||
15 | * @param string $charlist |
||
16 | * |
||
17 | * @return static |
||
18 | */ |
||
19 | public function addcslashes($charlist) |
||
20 | { |
||
21 | return new static(addcslashes($this->subject, $charlist)); |
||
1 ignored issue
–
show
|
|||
22 | } |
||
23 | |||
24 | /** |
||
25 | * Quote string with slashes. |
||
26 | * |
||
27 | * @return static |
||
28 | */ |
||
29 | public function addslashes() |
||
30 | { |
||
31 | return new static(addslashes($this->subject)); |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * Convert binary data into hexadecimal representation. |
||
36 | * |
||
37 | * @return static |
||
38 | */ |
||
39 | public function bin2hex() |
||
40 | { |
||
41 | return new static(bin2hex($this->subject)); |
||
42 | } |
||
43 | |||
44 | 1 | public function convertEncoding($toEncoding) |
|
45 | { |
||
46 | 1 | return func_num_args() === 1 ? |
|
47 | 1 | new static(mb_convert_encoding($this->subject, $toEncoding)) : |
|
48 | 1 | new static(mb_convert_encoding($this->subject, $toEncoding, func_get_arg(0))); |
|
49 | } |
||
50 | |||
51 | 1 | public function convertTo($variant = 'zh-tw') |
|
52 | { |
||
53 | 1 | return new static(Converter::instance()->convertTo($this->subject, $variant)); |
|
54 | } |
||
55 | |||
56 | public function chineseToNumber() |
||
57 | { |
||
58 | return (new Chinese($this->subject))->toNumber(); |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * Split a string by string. |
||
63 | * |
||
64 | * @param string $delimiter |
||
65 | * @param int $limit |
||
66 | * @return \Recca0120\LoDash\JArray |
||
67 | */ |
||
68 | 1 | public function explode($delimiter) |
|
69 | { |
||
70 | 1 | return func_num_args() === 1 ? |
|
71 | 1 | new JArray(explode($delimiter, $this->subject)) : |
|
72 | 1 | new JArray(explode($delimiter, $this->subject, func_get_arg(1))); |
|
73 | } |
||
74 | |||
75 | /** |
||
76 | * Convert all HTML entities to their applicable characters. |
||
77 | * |
||
78 | * @param int $flags |
||
79 | * @return static |
||
80 | */ |
||
81 | public function htmlEntityDecode() |
||
82 | { |
||
83 | return func_num_args() === 0 ? |
||
84 | new static(html_entity_decode($this->subject)) : |
||
85 | new static(html_entity_decode($this->subject, func_get_arg(0))); |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * Convert all applicable characters to HTML entities. |
||
90 | * |
||
91 | * @param int $flags |
||
92 | * @return static |
||
93 | */ |
||
94 | 1 | public function htmlentities() |
|
95 | { |
||
96 | 1 | return func_num_args() === 0 ? |
|
97 | 1 | new static(htmlentities($this->subject)) : |
|
98 | 1 | new static(htmlentities($this->subject, func_get_arg(0))); |
|
99 | } |
||
100 | |||
101 | /** |
||
102 | * Convert special HTML entities back to characters. |
||
103 | * |
||
104 | * @param int $flags |
||
105 | * @return static |
||
106 | */ |
||
107 | public function htmlspecialcharsDecode() |
||
108 | { |
||
109 | return func_num_args() === 0 ? |
||
110 | new static(htmlspecialchars_decode($this->subject)) : |
||
111 | new static(htmlspecialchars_decode($this->subject, func_get_arg(0))); |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * Convert special characters to HTML entities. |
||
116 | * |
||
117 | * @param int $flags |
||
118 | * @return static |
||
119 | */ |
||
120 | public function htmlspecialchars() |
||
121 | { |
||
122 | return func_num_args() === 0 ? |
||
123 | new static(htmlspecialchars($this->subject)) : |
||
124 | new static(htmlspecialchars($this->subject, func_get_arg(0))); |
||
125 | } |
||
126 | |||
127 | /** |
||
128 | * Make a string's first character lowercase. |
||
129 | * |
||
130 | * @return static |
||
131 | */ |
||
132 | public function lcfirst() |
||
133 | { |
||
134 | return new static(lcfirst($this->subject)); |
||
135 | } |
||
136 | |||
137 | /** |
||
138 | * Strip whitespace (or other characters) from the beginning of a string. |
||
139 | * |
||
140 | * @param string $characterMask |
||
141 | * @return static |
||
142 | */ |
||
143 | 1 | public function ltrim($characterMask = " \t\n\r\0\x0B") |
|
144 | { |
||
145 | 1 | return new static(ltrim($this->subject, $characterMask)); |
|
146 | } |
||
147 | |||
148 | /** |
||
149 | * Calculate the md5 hash of a string. |
||
150 | * |
||
151 | * @param bool $rawOutput |
||
152 | * @return static |
||
153 | */ |
||
154 | public function md5($rawOutput = false) |
||
155 | { |
||
156 | return new static(md5($this->subject, $rawOutput)); |
||
157 | } |
||
158 | |||
159 | /** |
||
160 | * Inserts HTML line breaks before all newlines in a string. |
||
161 | * |
||
162 | * @param bool $isXHTML |
||
163 | * @return static |
||
164 | */ |
||
165 | public function nl2br($isXHTML = true) |
||
166 | { |
||
167 | return new static(nl2br($this->subject, $isXHTML)); |
||
168 | } |
||
169 | |||
170 | /** |
||
171 | * Parses the string into variables. |
||
172 | * |
||
173 | * @return \Recca0120\LoDash\JArray |
||
174 | */ |
||
175 | public function parse() |
||
176 | { |
||
177 | $results = []; |
||
178 | parse_str($this->subject, $results); |
||
179 | |||
180 | return new JArray($results); |
||
181 | } |
||
182 | |||
183 | /** |
||
184 | * Strip whitespace (or other characters) from the end of a string. |
||
185 | * |
||
186 | * @param string $characterMask |
||
187 | * @return static |
||
188 | */ |
||
189 | 1 | public function rtrim($characterMask = " \t\n\r\0\x0B") |
|
190 | { |
||
191 | 1 | return new static(rtrim($this->subject, $characterMask)); |
|
192 | } |
||
193 | |||
194 | /** |
||
195 | * Calculate the sha1 hash of a string. |
||
196 | * |
||
197 | * @return static |
||
198 | */ |
||
199 | public function sha1() |
||
200 | { |
||
201 | return new static(sha1($this->subject)); |
||
202 | } |
||
203 | |||
204 | /** |
||
205 | * Parses input from a string according to a format. |
||
206 | * |
||
207 | * @param string $format |
||
208 | * @return static |
||
209 | */ |
||
210 | public function sscanf($format) |
||
211 | { |
||
212 | return new JArray(sscanf($this->subject, $format)); |
||
213 | } |
||
214 | |||
215 | /** |
||
216 | * Pad a string to a certain length with another string. |
||
217 | * |
||
218 | * @param int $length |
||
219 | * @param string $chars |
||
220 | * @param int $type |
||
221 | * @return static |
||
222 | */ |
||
223 | public function pad($length = 0, $chars = ' ', $type = STR_PAD_BOTH) |
||
224 | { |
||
225 | return new static(str_pad($this->subject, $length, $chars, $type)); |
||
226 | } |
||
227 | |||
228 | /** |
||
229 | * Perform the rot13 transform on a string. |
||
230 | * |
||
231 | * @return static |
||
232 | */ |
||
233 | public function rot13() |
||
234 | { |
||
235 | return new static(str_rot13($this->subject)); |
||
236 | } |
||
237 | |||
238 | /** |
||
239 | * Randomly shuffles a string. |
||
240 | * |
||
241 | * @return static |
||
242 | */ |
||
243 | public function shuffle() |
||
244 | { |
||
245 | return new static(str_shuffle($this->subject)); |
||
246 | } |
||
247 | |||
248 | /** |
||
249 | * Strip HTML and PHP tags from a string. |
||
250 | * |
||
251 | * @param string $allowable_tags |
||
252 | * |
||
253 | * @return static |
||
254 | */ |
||
255 | public function stripTags() |
||
256 | { |
||
257 | return func_num_args() === 0 ? |
||
258 | new static(strip_tags($this->subject)) : |
||
259 | new static(strip_tags($this->subject, func_get_arg(0))); |
||
260 | } |
||
261 | |||
262 | /** |
||
263 | * Un-quote string quoted with addcslashes(). |
||
264 | * |
||
265 | * @return static |
||
266 | */ |
||
267 | public function stripcslashes() |
||
268 | { |
||
269 | return new static(stripcslashes($this->subject)); |
||
270 | } |
||
271 | |||
272 | /** |
||
273 | * Un-quotes a quoted string. |
||
274 | * |
||
275 | * @return static |
||
276 | */ |
||
277 | public function stripslashes() |
||
278 | { |
||
279 | return new static(stripslashes($this->subject)); |
||
280 | } |
||
281 | |||
282 | /** |
||
283 | * Reverse a string. |
||
284 | * |
||
285 | * @return static |
||
286 | */ |
||
287 | public function reverse() |
||
288 | { |
||
289 | return new static(strrev($this->subject)); |
||
290 | } |
||
291 | |||
292 | public function toFullCase() |
||
293 | { |
||
294 | return new static((new FullCase($this->subject))->toFullCase()); |
||
295 | } |
||
296 | |||
297 | public function toHalfCase() |
||
298 | { |
||
299 | return new static((new FullCase($this->subject))->toHalfCase()); |
||
300 | } |
||
301 | |||
302 | /** |
||
303 | * Make a string's first character uppercase. |
||
304 | * |
||
305 | * @return static |
||
306 | */ |
||
307 | public function ucfirst() |
||
308 | { |
||
309 | return new static(ucfirst($this->subject)); |
||
310 | } |
||
311 | |||
312 | /** |
||
313 | * Uppercase the first character of each word in a string. |
||
314 | * |
||
315 | * @param string $delimiters |
||
316 | * |
||
317 | * @return static |
||
318 | */ |
||
319 | public function ucwords($delimiters = " \t\r\n\f\v") |
||
320 | { |
||
321 | return new static(ucwords($this->subject, $delimiters)); |
||
322 | } |
||
323 | |||
324 | /** |
||
325 | * Wraps a string to a given number of characters. |
||
326 | * |
||
327 | * @param int $width |
||
328 | * @param string $break |
||
329 | * @param bool $cut |
||
330 | * |
||
331 | * @return static |
||
332 | */ |
||
333 | public function wordwrap($width = 75, $break = "\n", $cut = false) |
||
334 | { |
||
335 | return new static(wordwrap($this->subject, $break, $cut)); |
||
336 | } |
||
337 | } |
||
338 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: