Completed
Push — master ( 8bf5d0...687d14 )
by recca
07:27
created

PHP   B

Complexity

Total Complexity 38

Size/Duplication

Total Lines 351
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 23.08%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 38
c 1
b 1
f 0
lcom 1
cbo 4
dl 0
loc 351
ccs 18
cts 78
cp 0.2308
rs 8.3999

31 Methods

Rating   Name   Duplication   Size   Complexity  
A addcslashes() 0 4 1
A addslashes() 0 4 1
A bin2hex() 0 4 1
A convertEncoding() 0 6 2
A convertTo() 0 4 1
A chineseToNumber() 0 4 1
A explode() 0 6 2
A htmlEntityDecode() 0 6 2
A htmlentities() 0 6 2
A htmlspecialcharsDecode() 0 6 2
A htmlspecialchars() 0 6 2
A lcfirst() 0 4 1
A ltrim() 0 4 1
A md5() 0 4 1
A nl2br() 0 4 1
A parse() 0 7 1
A rtrim() 0 4 1
A sha1() 0 4 1
A sscanf() 0 4 1
A pad() 0 4 1
A rot13() 0 4 1
A shuffle() 0 4 1
A stripTags() 0 6 2
A stripcslashes() 0 4 1
A stripslashes() 0 4 1
A reverse() 0 4 1
A toFullCase() 0 4 1
A toHalfCase() 0 4 1
A ucfirst() 0 4 1
A ucwords() 0 4 1
A wordwrap() 0 4 1
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
     * @return static
17
     */
18
    public function addcslashes($charlist)
19
    {
20
        return new static(addcslashes($this->subject, $charlist));
21
    }
22
23
    /**
24
     *  Quote string with slashes.
25
     *
26
     * @return static
27
     */
28
    public function addslashes()
29
    {
30
        return new static(addslashes($this->subject));
31
    }
32
33
    /**
34
     *  Convert binary data into hexadecimal representation.
35
     *
36
     * @return static
37
     */
38
    public function bin2hex()
39
    {
40
        return new static(bin2hex($this->subject));
41
    }
42
43 1
    /**
44
     * convertEncoding.
45 1
     *
46 1
     * @param  string $toEncoding
47 1
     * @return static
48
     */
49
    public function convertEncoding($toEncoding)
50 1
    {
51
        return func_num_args() === 1 ?
52 1
            new static(mb_convert_encoding($this->subject, $toEncoding)) :
53
            new static(mb_convert_encoding($this->subject, $toEncoding, func_get_arg(0)));
54
    }
55
56
    /**
57
     * convertTo.
58
     *
59
     * @param string $variant
60
     * @return static
61
     */
62
    public function convertTo($variant = 'zh-tw')
63
    {
64
        return new static(Converter::instance()->convertTo($this->subject, $variant));
65
    }
66
67 1
    /**
68
     * chineseToNumber.
69 1
     *
70 1
     * @return int
71 1
     */
72
    public function chineseToNumber()
73
    {
74
        return (new Chinese($this->subject))->toNumber();
75
    }
76
77
    /**
78
     * Split a string by string.
79
     *
80
     * @param string $delimiter
81
     * @param int $limit
1 ignored issue
show
Bug introduced by
There is no parameter named $limit. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
82
     * @return \Recca0120\Lodash\JArray
83
     */
84
    public function explode($delimiter)
85
    {
86
        return func_num_args() === 1 ?
87
            new JArray(explode($delimiter, $this->subject)) :
88
            new JArray(explode($delimiter, $this->subject, func_get_arg(1)));
89
    }
90
91
    /**
92
     * Convert all HTML entities to their applicable characters.
93 1
     *
94
     * @param int $flags
95 1
     * @return static
96 1
     */
97 1
    public function htmlEntityDecode()
98
    {
99
        return func_num_args() === 0 ?
100
            new static(html_entity_decode($this->subject)) :
101
            new static(html_entity_decode($this->subject, func_get_arg(0)));
102
    }
103
104
    /**
105
     * Convert all applicable characters to HTML entities.
106
     *
107
     * @param int $flags
108
     * @return static
109
     */
110
    public function htmlentities()
111
    {
112
        return func_num_args() === 0 ?
113
            new static(htmlentities($this->subject)) :
114
            new static(htmlentities($this->subject, func_get_arg(0)));
115
    }
116
117
    /**
118
     * Convert special HTML entities back to characters.
119
     *
120
     * @param int $flags
1 ignored issue
show
Bug introduced by
There is no parameter named $flags. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
121
     * @return static
122
     */
123
    public function htmlspecialcharsDecode()
124
    {
125
        return func_num_args() === 0 ?
126
            new static(htmlspecialchars_decode($this->subject)) :
127
            new static(htmlspecialchars_decode($this->subject, func_get_arg(0)));
128
    }
129
130
    /**
131
     * Convert special characters to HTML entities.
132
     *
133
     * @param int $flags
134
     * @return static
135
     */
136
    public function htmlspecialchars()
137
    {
138
        return func_num_args() === 0 ?
139
            new static(htmlspecialchars($this->subject)) :
140
            new static(htmlspecialchars($this->subject, func_get_arg(0)));
141
    }
142 1
143
    /**
144 1
     * Make a string's first character lowercase.
145
     *
146
     * @return static
147
     */
148
    public function lcfirst()
149
    {
150
        return new static(lcfirst($this->subject));
151
    }
152
153
    /**
154
     * Strip whitespace (or other characters) from the beginning of a string.
155
     *
156
     * @param string $characterMask
157
     * @return static
158
     */
159
    public function ltrim($characterMask = " \t\n\r\0\x0B")
160
    {
161
        return new static(ltrim($this->subject, $characterMask));
162
    }
163
164
    /**
165
     * Calculate the md5 hash of a string.
166
     *
167
     * @param bool $rawOutput
168
     * @return static
169
     */
170
    public function md5($rawOutput = false)
171
    {
172
        return new static(md5($this->subject, $rawOutput));
173
    }
174
175
    /**
176
     * Inserts HTML line breaks before all newlines in a string.
177
     *
178
     * @param bool $isXHTML
179
     * @return static
180
     */
181
    public function nl2br($isXHTML = true)
182
    {
183
        return new static(nl2br($this->subject, $isXHTML));
184
    }
185
186
    /**
187
     * Parses the string into variables.
188 1
     *
189
     * @return \Recca0120\Lodash\JArray
190 1
     */
191
    public function parse()
192
    {
193
        $results = [];
194
        parse_str($this->subject, $results);
195
196
        return new JArray($results);
197
    }
198
199
    /**
200
     * Strip whitespace (or other characters) from the end of a string.
201
     *
202
     * @param string $characterMask
203
     * @return static
204
     */
205
    public function rtrim($characterMask = " \t\n\r\0\x0B")
206
    {
207
        return new static(rtrim($this->subject, $characterMask));
208
    }
209
210
    /**
211
     * Calculate the sha1 hash of a string.
212
     *
213
     * @return static
214
     */
215
    public function sha1()
216
    {
217
        return new static(sha1($this->subject));
218
    }
219
220
    /**
221
     * Parses input from a string according to a format.
222
     *
223
     * @param string $format
224
     * @return \Recca0120\Lodash\JArray
225
     */
226
    public function sscanf($format)
227
    {
228
        return new JArray(sscanf($this->subject, $format));
229
    }
230
231
    /**
232
     * Pad a string to a certain length with another string.
233
     *
234
     * @param int $length
235
     * @param string $chars
236
     * @param int $type
237
     * @return static
238
     */
239
    public function pad($length = 0, $chars = ' ', $type = STR_PAD_BOTH)
240
    {
241
        return new static(str_pad($this->subject, $length, $chars, $type));
242
    }
243
244
    /**
245
     * Perform the rot13 transform on a string.
246
     *
247
     * @return static
248
     */
249
    public function rot13()
250
    {
251
        return new static(str_rot13($this->subject));
252
    }
253
254
    /**
255
     * Randomly shuffles a string.
256
     *
257
     * @return static
258
     */
259
    public function shuffle()
260
    {
261
        return new static(str_shuffle($this->subject));
262
    }
263
264
    /**
265
     * Strip HTML and PHP tags from a string.
266
     *
267
     * @param string $allowable_tags
268
     * @return static
269
     */
270
    public function stripTags()
271
    {
272
        return func_num_args() === 0 ?
273
            new static(strip_tags($this->subject)) :
274
            new static(strip_tags($this->subject, func_get_arg(0)));
275
    }
276
277
    /**
278
     * Un-quote string quoted with addcslashes().
279
     *
280
     * @return static
281
     */
282
    public function stripcslashes()
283
    {
284
        return new static(stripcslashes($this->subject));
285
    }
286
287
    /**
288
     * Un-quotes a quoted string.
289
     *
290
     * @return static
291
     */
292
    public function stripslashes()
293
    {
294
        return new static(stripslashes($this->subject));
295
    }
296
297
    /**
298
     * Reverse a string.
299
     *
300
     * @return static
301
     */
302
    public function reverse()
303
    {
304
        return new static(strrev($this->subject));
305
    }
306
307
    /**
308
     * toFullCase.
309
     *
310
     * @return static
311
     */
312
    public function toFullCase()
313
    {
314
        return new static((new FullCase($this->subject))->toFullCase());
315
    }
316
317
    /**
318
     * toHalfCase.
319
     *
320
     * @return static
321
     */
322
    public function toHalfCase()
323
    {
324
        return new static((new FullCase($this->subject))->toHalfCase());
325
    }
326
327
    /**
328
     * Make a string's first character uppercase.
329
     *
330
     * @return static
331
     */
332
    public function ucfirst()
333
    {
334
        return new static(ucfirst($this->subject));
335
    }
336
337
    /**
338
     * Uppercase the first character of each word in a string.
339
     *
340
     * @param string $delimiters
341
     * @return static
342
     */
343
    public function ucwords($delimiters = " \t\r\n\f\v")
344
    {
345
        return new static(ucwords($this->subject, $delimiters));
346
    }
347
348
    /**
349
     * Wraps a string to a given number of characters.
350
     *
351
     * @param int $width
352
     * @param string $break
353
     * @param bool $cut
354
     * @return static
355
     */
356
    public function wordwrap($width = 75, $break = "\n", $cut = false)
357
    {
358
        return new static(wordwrap($this->subject, $width, $break, $cut));
1 ignored issue
show
Unused Code introduced by
The call to PHP::__construct() has too many arguments starting with wordwrap($this->subject, $width, $break, $cut).

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
359
    }
360
}
361