Skip to content

Commit 85e6361

Browse files
committed
style: $ composer fix
Signed-off-by: Jack Cherng <jfcherng@gmail.com>
1 parent 03d7ff0 commit 85e6361

4 files changed

Lines changed: 63 additions & 63 deletions

File tree

benchmark/benchmark.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,33 @@ function benchmark(string $str, int $runs, string $title = ''): void
1919
$title = 'Untitled';
2020
}
2121

22-
$separator = \str_repeat('=', \strlen($title));
22+
$separator = str_repeat('=', \strlen($title));
2323
echo "{$title}\n{$separator}\n";
2424

25-
//////////////////
25+
// ////////////////
2626
// begin mb_*() //
27-
//////////////////
27+
// ////////////////
2828

29-
$time = \microtime(true);
29+
$time = microtime(true);
3030

31-
$strLen = \mb_strlen($str, 'UTF-8');
31+
$strLen = mb_strlen($str, 'UTF-8');
3232
for ($run = 0; $run < $runs; ++$run) {
3333
for ($i = 0; $i < $strLen; ++$i) {
3434
// get nth char
35-
$char = \mb_substr($str, $i, 1, 'UTF-8');
35+
$char = mb_substr($str, $i, 1, 'UTF-8');
3636
// in-place replacement of nth char
37-
$str = \mb_substr($str, 0, $i) . '' . \mb_substr($str, $i + 1);
37+
$str = mb_substr($str, 0, $i) . '' . mb_substr($str, $i + 1);
3838
}
3939
}
4040

41-
$timeMbNative = \microtime(true) - $time;
41+
$timeMbNative = microtime(true) - $time;
4242
echo "PHP mb_*(): {$timeMbNative}\n";
4343

44-
////////////////////
44+
// //////////////////
4545
// begin MbString //
46-
////////////////////
46+
// //////////////////
4747

48-
$time = \microtime(true);
48+
$time = microtime(true);
4949

5050
$mbStr = new MbString($str, 'UTF-8');
5151
$strLen = $mbStr->strlen();
@@ -58,19 +58,19 @@ function benchmark(string $str, int $runs, string $title = ''): void
5858
}
5959
}
6060

61-
$timeMbString = \microtime(true) - $time;
61+
$timeMbString = microtime(true) - $time;
6262
echo "MbString: {$timeMbString}\n";
6363

64-
/////////
64+
// ///////
6565
// end //
66-
/////////
66+
// ///////
6767

6868
echo "{$separator}\n";
6969
echo "Nums of Chars: {$strLen}\n";
7070
echo "Nums of Runs: {$runs}\n";
7171

7272
$speedUp = $timeMbNative / $timeMbString - 1;
73-
$speedUpPercent = \round($speedUp * 100, 2);
73+
$speedUpPercent = round($speedUp * 100, 2);
7474
echo "Speed up: {$speedUpPercent}%\n\n";
7575
}
7676

@@ -83,8 +83,8 @@ function benchmark(string $str, int $runs, string $title = ''): void
8383

8484
foreach ($benchmarks as $file => $runs) {
8585
benchmark(
86-
\file_get_contents(__DIR__ . "/{$file}"),
86+
file_get_contents(__DIR__ . "/{$file}"),
8787
(int) $runs,
88-
"# BENCHMARK: {$file}"
88+
"# BENCHMARK: {$file}",
8989
);
9090
}

src/MbString.php

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,17 @@ public function setAt(int $idx, string $char): self
7878
{
7979
$char = $this->inputConv($char);
8080
if (\strlen($char) > 4) {
81-
$char = \substr($char, 0, 4);
81+
$char = substr($char, 0, 4);
8282
}
8383

8484
$spacesPrepend = $idx - $this->strlen();
8585
// set index (out of bound)
8686
if ($spacesPrepend > 0) {
87-
$this->str .= $this->inputConv(\str_repeat(' ', $spacesPrepend)) . $char;
87+
$this->str .= $this->inputConv(str_repeat(' ', $spacesPrepend)) . $char;
8888
}
8989
// set index (in bound)
9090
else {
91-
$this->str = \substr_replace($this->str, $char, $idx << 2, 4);
91+
$this->str = substr_replace($this->str, $char, $idx << 2, 4);
9292
}
9393

9494
return $this;
@@ -114,12 +114,12 @@ public function getRaw(): string
114114

115115
public function getAt(int $idx): string
116116
{
117-
return $this->outputConv(\substr($this->str, $idx << 2, 4));
117+
return $this->outputConv(substr($this->str, $idx << 2, 4));
118118
}
119119

120120
public function getAtRaw(int $idx): string
121121
{
122-
return \substr($this->str, $idx << 2, 4);
122+
return substr($this->str, $idx << 2, 4);
123123
}
124124

125125
public function toArray(): array
@@ -133,7 +133,7 @@ public function toArraySplit(string $regex, int $limit = -1, $flags = 0): array
133133
return [];
134134
}
135135

136-
return \preg_split($regex, $this->get(), $limit, $flags);
136+
return preg_split($regex, $this->get(), $limit, $flags);
137137
}
138138

139139
public function toArrayRaw(): array
@@ -142,22 +142,22 @@ public function toArrayRaw(): array
142142
return [];
143143
}
144144

145-
return \str_split($this->str, 4);
145+
return str_split($this->str, 4);
146146
}
147147

148148
public static function strToChars(string $str): array
149149
{
150-
return \preg_split('//uS', $str, -1, \PREG_SPLIT_NO_EMPTY) ?: [];
150+
return preg_split('//uS', $str, -1, \PREG_SPLIT_NO_EMPTY) ?: [];
151151
}
152152

153-
///////////////////////////////////
153+
// /////////////////////////////////
154154
// string manipulation functions //
155-
///////////////////////////////////
155+
// /////////////////////////////////
156156

157157
public function stripos(string $needle, int $offset = 0)
158158
{
159159
$needle = $this->inputConv($needle);
160-
$pos = \stripos($this->str, $needle, $offset << 2);
160+
$pos = stripos($this->str, $needle, $offset << 2);
161161

162162
return \is_bool($pos) ? $pos : $pos >> 2;
163163
}
@@ -170,7 +170,7 @@ public function strlen(): int
170170
public function strpos(string $needle, int $offset = 0)
171171
{
172172
$needle = $this->inputConv($needle);
173-
$pos = \strpos($this->str, $needle, $offset << 2);
173+
$pos = strpos($this->str, $needle, $offset << 2);
174174

175175
return \is_bool($pos) ? $pos : $pos >> 2;
176176
}
@@ -179,8 +179,8 @@ public function substr(int $start = 0, ?int $length = null): string
179179
{
180180
return $this->outputConv(
181181
isset($length)
182-
? \substr($this->str, $start << 2, $length << 2)
183-
: \substr($this->str, $start << 2)
182+
? substr($this->str, $start << 2, $length << 2)
183+
: substr($this->str, $start << 2),
184184
);
185185
}
186186

@@ -190,55 +190,55 @@ public function substr_replace(string $replacement, int $start = 0, ?int $length
190190

191191
return $this->outputConv(
192192
isset($length)
193-
? \substr_replace($this->str, $replacement, $start << 2, $length << 2)
194-
: \substr_replace($this->str, $replacement, $start << 2)
193+
? substr_replace($this->str, $replacement, $start << 2, $length << 2)
194+
: substr_replace($this->str, $replacement, $start << 2),
195195
);
196196
}
197197

198198
public function strtolower(): string
199199
{
200-
return \strtolower($this->get());
200+
return strtolower($this->get());
201201
}
202202

203203
public function strtoupper(): string
204204
{
205-
return \strtoupper($this->get());
205+
return strtoupper($this->get());
206206
}
207207

208-
////////////////////////////////
208+
// //////////////////////////////
209209
// non-manipulative functions //
210-
////////////////////////////////
210+
// //////////////////////////////
211211

212212
public function has(string $needle): bool
213213
{
214214
$needle = $this->inputConv($needle);
215215

216-
return \strpos($this->str, $needle) !== false;
216+
return str_contains($this->str, $needle);
217217
}
218218

219219
public function startsWith(string $needle): bool
220220
{
221221
$needle = $this->inputConv($needle);
222222

223-
return $needle === \substr($this->str, 0, \strlen($needle));
223+
return $needle === substr($this->str, 0, \strlen($needle));
224224
}
225225

226226
public function endsWith(string $needle): bool
227227
{
228228
$needle = $this->inputConv($needle);
229229
$length = \strlen($needle);
230230

231-
return $length === 0 ? true : $needle === \substr($this->str, -$length);
231+
return $length === 0 ? true : $needle === substr($this->str, -$length);
232232
}
233233

234-
/////////////////////////////////////////////
234+
// ///////////////////////////////////////////
235235
// those functions will not return a value //
236-
/////////////////////////////////////////////
236+
// ///////////////////////////////////////////
237237

238238
public function str_insert_i(string $insert, int $position): self
239239
{
240240
$insert = $this->inputConv($insert);
241-
$this->str = \substr_replace($this->str, $insert, $position << 2, 0);
241+
$this->str = substr_replace($this->str, $insert, $position << 2, 0);
242242

243243
return $this;
244244
}
@@ -252,15 +252,15 @@ public function str_enclose_i(array $closures, int $start = 0, ?int $length = nu
252252
unset($closure);
253253

254254
if (\count($closures) < 2) {
255-
$closures[0] = $closures[1] = \reset($closures);
255+
$closures[0] = $closures[1] = reset($closures);
256256
}
257257

258258
if (isset($length)) {
259-
$replacement = $closures[0] . \substr($this->str, $start << 2, $length << 2) . $closures[1];
260-
$this->str = \substr_replace($this->str, $replacement, $start << 2, $length << 2);
259+
$replacement = $closures[0] . substr($this->str, $start << 2, $length << 2) . $closures[1];
260+
$this->str = substr_replace($this->str, $replacement, $start << 2, $length << 2);
261261
} else {
262-
$replacement = $closures[0] . \substr($this->str, $start << 2) . $closures[1];
263-
$this->str = \substr_replace($this->str, $replacement, $start << 2);
262+
$replacement = $closures[0] . substr($this->str, $start << 2) . $closures[1];
263+
$this->str = substr_replace($this->str, $replacement, $start << 2);
264264
}
265265

266266
return $this;
@@ -270,7 +270,7 @@ public function str_replace_i(string $search, string $replace): self
270270
{
271271
$search = $this->inputConv($search);
272272
$replace = $this->inputConv($replace);
273-
$this->str = \str_replace($search, $replace, $this->str);
273+
$this->str = str_replace($search, $replace, $this->str);
274274

275275
return $this;
276276
}
@@ -280,16 +280,16 @@ public function substr_replace_i(string $replacement, int $start = 0, ?int $leng
280280
$replacement = $this->inputConv($replacement);
281281
$this->str = (
282282
isset($length)
283-
? \substr_replace($this->str, $replacement, $start << 2, $length << 2)
284-
: \substr_replace($this->str, $replacement, $start << 2)
283+
? substr_replace($this->str, $replacement, $start << 2, $length << 2)
284+
: substr_replace($this->str, $replacement, $start << 2)
285285
);
286286

287287
return $this;
288288
}
289289

290-
/////////////////
290+
// ///////////////
291291
// ArrayObject //
292-
/////////////////
292+
// ///////////////
293293

294294
public function offsetSet(mixed $idx, mixed $char): void
295295
{
@@ -316,9 +316,9 @@ public function count(): int
316316
return $this->strlen();
317317
}
318318

319-
////////////////////
319+
// //////////////////
320320
// misc functions //
321-
////////////////////
321+
// //////////////////
322322

323323
/**
324324
* Gets the utf 32 header.
@@ -328,9 +328,9 @@ public function count(): int
328328
protected static function getUtf32Header(): string
329329
{
330330
// just use any string to get the endian header, here we use "A"
331-
$tmp = \iconv('UTF-8', 'UTF-32', 'A');
331+
$tmp = iconv('UTF-8', 'UTF-32', 'A');
332332
// some distributions like "php alpine" docker image won't generate the header
333-
return $tmp && \strlen($tmp) > 4 ? \substr($tmp, 0, 4) : '';
333+
return $tmp && \strlen($tmp) > 4 ? substr($tmp, 0, 4) : '';
334334
}
335335

336336
/**
@@ -344,7 +344,7 @@ protected function outputConv(string $str): string
344344
return '';
345345
}
346346

347-
return \iconv('UTF-32', $this->encoding, static::$utf32Header . $str);
347+
return iconv('UTF-32', $this->encoding, static::$utf32Header . $str);
348348
}
349349

350350
/**
@@ -358,6 +358,6 @@ protected function inputConv(string $str): string
358358
return '';
359359
}
360360

361-
return \substr(\iconv($this->encoding, 'UTF-32', $str), \strlen(static::$utf32Header));
361+
return substr(iconv($this->encoding, 'UTF-32', $str), \strlen(static::$utf32Header));
362362
}
363363
}

tests/MbStringTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ public function testMbString(): void
9999
$mb->set('本月,是五月。');
100100
static::assertSame(
101101
['本月', '', '是五月', '', ''],
102-
$mb->toArraySplit('/([,。])/uS', -1, \PREG_SPLIT_DELIM_CAPTURE)
102+
$mb->toArraySplit('/([,。])/uS', -1, \PREG_SPLIT_DELIM_CAPTURE),
103103
);
104104

105105
static::assertSame(
106106
['', '', '', '', '', "\n", ''],
107-
MbString::strToChars("本月是五月\n")
107+
MbString::strToChars("本月是五月\n"),
108108
);
109109
}
110110
}

tests/bootstrap.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
\error_reporting(\E_ALL);
6-
\ini_set('display_errors', '1');
5+
error_reporting(\E_ALL);
6+
ini_set('display_errors', '1');
77

88
include __DIR__ . '/../vendor/autoload.php';

0 commit comments

Comments
 (0)