Skip to content

Commit 22bc087

Browse files
committed
coding style
1 parent 55c0da7 commit 22bc087

22 files changed

+104
-107
lines changed

src/Utils/Callback.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static function check($callable, bool $syntax = false)
6060
throw new Nette\InvalidArgumentException(
6161
$syntax
6262
? 'Given value is not a callable type.'
63-
: sprintf("Callback '%s' is not callable.", self::toString($callable))
63+
: sprintf("Callback '%s' is not callable.", self::toString($callable)),
6464
);
6565
}
6666
return $callable;

src/Utils/DateTime.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ class DateTime extends \DateTime implements \JsonSerializable
3232
public const WEEK = 7 * self::DAY;
3333

3434
/** average month in seconds */
35-
public const MONTH = 2629800;
35+
public const MONTH = 2_629_800;
3636

3737
/** average year in seconds */
38-
public const YEAR = 31557600;
38+
public const YEAR = 31_557_600;
3939

4040

4141
/**
@@ -72,7 +72,7 @@ public static function fromParts(
7272
int $day,
7373
int $hour = 0,
7474
int $minute = 0,
75-
float $second = 0.0
75+
float $second = 0.0,
7676
) {
7777
$s = sprintf('%04d-%02d-%02d %02d:%02d:%02.5F', $year, $month, $day, $hour, $minute, $second);
7878
if (

src/Utils/Html.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ final public function attributes(): string
842842
. str_replace(
843843
['&', $q, '<'],
844844
['&amp;', $q === '"' ? '&quot;' : '&#39;', self::$xhtml ? '&lt;' : '<'],
845-
$value
845+
$value,
846846
)
847847
. (strpos($value, '`') !== false && strpbrk($value, ' <>"\'') === false ? ' ' : '')
848848
. $q;

src/Utils/Image.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ public function resize($width, $height, int $flags = self::FIT)
338338
$newWidth,
339339
$newHeight,
340340
$this->getWidth(),
341-
$this->getHeight()
341+
$this->getHeight(),
342342
);
343343
$this->image = $newImage;
344344
}
@@ -360,7 +360,7 @@ public static function calculateSize(
360360
int $srcHeight,
361361
$newWidth,
362362
$newHeight,
363-
int $flags = self::FIT
363+
int $flags = self::FIT,
364364
): array {
365365
if ($newWidth === null) {
366366
} elseif (self::isPercent($newWidth)) {
@@ -550,7 +550,7 @@ public function place(self $image, $left = 0, $top = 0, int $opacity = 100)
550550
0,
551551
0,
552552
$width,
553-
$height
553+
$height,
554554
);
555555
return $this;
556556
}
@@ -667,13 +667,13 @@ public function __call(string $name, array $args)
667667
$value['red'],
668668
$value['green'],
669669
$value['blue'],
670-
$value['alpha']
670+
$value['alpha'],
671671
) ?: imagecolorresolvealpha(
672672
$this->image,
673673
$value['red'],
674674
$value['green'],
675675
$value['blue'],
676-
$value['alpha']
676+
$value['alpha'],
677677
);
678678
}
679679
}

src/Utils/ObjectHelpers.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ public static function strictGet(string $class, string $name): void
2525
{
2626
$rc = new \ReflectionClass($class);
2727
$hint = self::getSuggestion(array_merge(
28-
array_filter($rc->getProperties(\ReflectionProperty::IS_PUBLIC), function ($p) { return !$p->isStatic(); }),
29-
self::parseFullDoc($rc, '~^[ \t*]*@property(?:-read)?[ \t]+(?:\S+[ \t]+)??\$(\w+)~m')
28+
array_filter($rc->getProperties(\ReflectionProperty::IS_PUBLIC), fn($p) => !$p->isStatic()),
29+
self::parseFullDoc($rc, '~^[ \t*]*@property(?:-read)?[ \t]+(?:\S+[ \t]+)??\$(\w+)~m'),
3030
), $name);
3131
throw new MemberAccessException("Cannot read an undeclared property $class::\$$name" . ($hint ? ", did you mean \$$hint?" : '.'));
3232
}
@@ -37,8 +37,8 @@ public static function strictSet(string $class, string $name): void
3737
{
3838
$rc = new \ReflectionClass($class);
3939
$hint = self::getSuggestion(array_merge(
40-
array_filter($rc->getProperties(\ReflectionProperty::IS_PUBLIC), function ($p) { return !$p->isStatic(); }),
41-
self::parseFullDoc($rc, '~^[ \t*]*@property(?:-write)?[ \t]+(?:\S+[ \t]+)??\$(\w+)~m')
40+
array_filter($rc->getProperties(\ReflectionProperty::IS_PUBLIC), fn($p) => !$p->isStatic()),
41+
self::parseFullDoc($rc, '~^[ \t*]*@property(?:-write)?[ \t]+(?:\S+[ \t]+)??\$(\w+)~m'),
4242
), $name);
4343
throw new MemberAccessException("Cannot write to an undeclared property $class::\$$name" . ($hint ? ", did you mean \$$hint?" : '.'));
4444
}
@@ -50,7 +50,7 @@ public static function strictCall(string $class, string $method, array $addition
5050
$hint = self::getSuggestion(array_merge(
5151
get_class_methods($class),
5252
self::parseFullDoc(new \ReflectionClass($class), '~^[ \t*]*@method[ \t]+(?:\S+[ \t]+)??(\w+)\(~m'),
53-
$additionalMethods
53+
$additionalMethods,
5454
), $method);
5555

5656
if (method_exists($class, $method)) { // called parent::$method()
@@ -64,8 +64,8 @@ public static function strictCall(string $class, string $method, array $addition
6464
public static function strictStaticCall(string $class, string $method): void
6565
{
6666
$hint = self::getSuggestion(
67-
array_filter((new \ReflectionClass($class))->getMethods(\ReflectionMethod::IS_PUBLIC), function ($m) { return $m->isStatic(); }),
68-
$method
67+
array_filter((new \ReflectionClass($class))->getMethods(\ReflectionMethod::IS_PUBLIC), fn($m) => $m->isStatic()),
68+
$method,
6969
);
7070
throw new MemberAccessException("Call to undefined static method $class::$method()" . ($hint ? ", did you mean $hint()?" : '.'));
7171
}
@@ -89,7 +89,7 @@ public static function getMagicProperties(string $class): array
8989
'~^ [ \t*]* @property(|-read|-write) [ \t]+ [^\s$]+ [ \t]+ \$ (\w+) ()~mx',
9090
(string) $rc->getDocComment(),
9191
$matches,
92-
PREG_SET_ORDER
92+
PREG_SET_ORDER,
9393
);
9494

9595
$props = [];

src/Utils/Random.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ final class Random
2525
*/
2626
public static function generate(int $length = 10, string $charlist = '0-9a-z'): string
2727
{
28-
$charlist = count_chars(preg_replace_callback('#.-.#', function (array $m): string {
29-
return implode('', range($m[0][0], $m[0][2]));
30-
}, $charlist), 3);
28+
$charlist = preg_replace_callback(
29+
'#.-.#',
30+
fn(array $m): string => implode('', range($m[0][0], $m[0][2])),
31+
$charlist,
32+
);
33+
$charlist = count_chars($charlist, mode: 3);
3134
$chLen = strlen($charlist);
3235

3336
if ($length < 1) {

src/Utils/Strings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public static function toAscii(string $s): string
184184
$s = strtr(
185185
$s,
186186
"\xa5\xa3\xbc\x8c\xa7\x8a\xaa\x8d\x8f\x8e\xaf\xb9\xb3\xbe\x9c\x9a\xba\x9d\x9f\x9e\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf8\xf9\xfa\xfb\xfc\xfd\xfe\x96\xa0\x8b\x97\x9b\xa6\xad\xb7",
187-
'ALLSSSSTZZZallssstzzzRAAAALCCCEEEEIIDDNNOOOOxRUUUUYTsraaaalccceeeeiiddnnooooruuuuyt- <->|-.'
187+
'ALLSSSSTZZZallssstzzzRAAAALCCCEEEEIIDDNNOOOOxRUUUUYTsraaaalccceeeeiiddnnooooruuuuyt- <->|-.',
188188
);
189189
$s = self::pcre('preg_replace', ['#[^\x00-\x7F]++#', '', $s]);
190190
} else {

src/Utils/Validators.php

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public static function assertField(
116116
array $array,
117117
$key,
118118
string $expected = null,
119-
string $label = "item '%' in array"
119+
string $label = "item '%' in array",
120120
): void {
121121
if (!array_key_exists($key, $array)) {
122122
throw new AssertionException('Missing ' . str_replace('%', $key, $label) . '.');
@@ -310,14 +310,13 @@ public static function isEmail(string $value): bool
310310
$atom = "[-a-z0-9!#$%&'*+/=?^_`{|}~]"; // RFC 5322 unquoted characters in local-part
311311
$alpha = "a-z\x80-\xFF"; // superset of IDN
312312
return (bool) preg_match(<<<XX
313-
(^
314-
("([ !#-[\\]-~]*|\\\\[ -~])+"|$atom+(\\.$atom+)*) # quoted or unquoted
315-
@
316-
([0-9$alpha]([-0-9$alpha]{0,61}[0-9$alpha])?\\.)+ # domain - RFC 1034
317-
[$alpha]([-0-9$alpha]{0,17}[$alpha])? # top domain
318-
$)Dix
319-
XX
320-
, $value);
313+
(^
314+
("([ !#-[\\]-~]*|\\\\[ -~])+"|$atom+(\\.$atom+)*) # quoted or unquoted
315+
@
316+
([0-9$alpha]([-0-9$alpha]{0,61}[0-9$alpha])?\\.)+ # domain - RFC 1034
317+
[$alpha]([-0-9$alpha]{0,17}[$alpha])? # top domain
318+
$)Dix
319+
XX, $value);
321320
}
322321

323322

@@ -328,20 +327,19 @@ public static function isUrl(string $value): bool
328327
{
329328
$alpha = "a-z\x80-\xFF";
330329
return (bool) preg_match(<<<XX
331-
(^
332-
https?://(
333-
(([-_0-9$alpha]+\\.)* # subdomain
334-
[0-9$alpha]([-0-9$alpha]{0,61}[0-9$alpha])?\\.)? # domain
335-
[$alpha]([-0-9$alpha]{0,17}[$alpha])? # top domain
336-
|\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3} # IPv4
337-
|\\[[0-9a-f:]{3,39}\\] # IPv6
338-
)(:\\d{1,5})? # port
339-
(/\\S*)? # path
340-
(\\?\\S*)? # query
341-
(\\#\\S*)? # fragment
342-
$)Dix
343-
XX
344-
, $value);
330+
(^
331+
https?://(
332+
(([-_0-9$alpha]+\\.)* # subdomain
333+
[0-9$alpha]([-0-9$alpha]{0,61}[0-9$alpha])?\\.)? # domain
334+
[$alpha]([-0-9$alpha]{0,17}[$alpha])? # top domain
335+
|\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3} # IPv4
336+
|\\[[0-9a-f:]{3,39}\\] # IPv6
337+
)(:\\d{1,5})? # port
338+
(/\\S*)? # path
339+
(\\?\\S*)? # query
340+
(\\#\\S*)? # fragment
341+
$)Dix
342+
XX, $value);
345343
}
346344

347345

tests/Iterators/Mapper.phpt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ $arr = [
1818
'David' => 'Grudl',
1919
];
2020

21-
$callback = function ($item, $key) {
22-
return $key . ': ' . $item;
23-
};
21+
$callback = fn($item, $key) => $key . ': ' . $item;
2422

2523
$iterator = new Iterators\Mapper(new \ArrayIterator($arr), $callback);
2624

tests/Utils/Arrays.associate().phpt

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ Assert::same(
2828
'Mary' => ['name' => 'Mary', 'age' => null],
2929
'Paul' => ['name' => 'Paul', 'age' => 44],
3030
],
31-
Arrays::associate($arr, 'name')
31+
Arrays::associate($arr, 'name'),
3232
);
3333

3434
Assert::same(
3535
[],
36-
Arrays::associate([], 'name')
36+
Arrays::associate([], 'name'),
3737
);
3838

3939
Assert::same(
@@ -42,17 +42,17 @@ Assert::same(
4242
'Mary' => ['name' => 'Mary', 'age' => null],
4343
'Paul' => ['name' => 'Paul', 'age' => 44],
4444
],
45-
Arrays::associate($arr, 'name=')
45+
Arrays::associate($arr, 'name='),
4646
);
4747

4848
Assert::same(
4949
['John' => 22, 'Mary' => null, 'Paul' => 44],
50-
Arrays::associate($arr, 'name=age')
50+
Arrays::associate($arr, 'name=age'),
5151
);
5252

5353
Assert::same(// path as array
5454
['John' => 22, 'Mary' => null, 'Paul' => 44],
55-
Arrays::associate($arr, ['name', '=', 'age'])
55+
Arrays::associate($arr, ['name', '=', 'age']),
5656
);
5757

5858
Assert::equal(
@@ -70,7 +70,7 @@ Assert::equal(
7070
'age' => 44,
7171
],
7272
],
73-
Arrays::associate($arr, 'name->')
73+
Arrays::associate($arr, 'name->'),
7474
);
7575

7676
Assert::equal(
@@ -88,7 +88,7 @@ Assert::equal(
8888
'Paul' => ['name' => 'Paul', 'age' => 44],
8989
],
9090
],
91-
Arrays::associate($arr, 'age->name')
91+
Arrays::associate($arr, 'age->name'),
9292
);
9393

9494
Assert::equal(
@@ -97,12 +97,12 @@ Assert::equal(
9797
'Mary' => ['name' => 'Mary', 'age' => null],
9898
'Paul' => ['name' => 'Paul', 'age' => 44],
9999
],
100-
Arrays::associate($arr, '->name')
100+
Arrays::associate($arr, '->name'),
101101
);
102102

103103
Assert::equal(
104104
(object) [],
105-
Arrays::associate([], '->name')
105+
Arrays::associate([], '->name'),
106106
);
107107

108108
Assert::same(
@@ -118,7 +118,7 @@ Assert::same(
118118
44 => ['name' => 'Paul', 'age' => 44],
119119
],
120120
],
121-
Arrays::associate($arr, 'name|age')
121+
Arrays::associate($arr, 'name|age'),
122122
);
123123

124124
Assert::same(
@@ -127,7 +127,7 @@ Assert::same(
127127
'Mary' => ['name' => 'Mary', 'age' => null],
128128
'Paul' => ['name' => 'Paul', 'age' => 44],
129129
],
130-
Arrays::associate($arr, 'name|')
130+
Arrays::associate($arr, 'name|'),
131131
);
132132

133133
Assert::same(
@@ -143,7 +143,7 @@ Assert::same(
143143
['name' => 'Paul', 'age' => 44],
144144
],
145145
],
146-
Arrays::associate($arr, 'name[]')
146+
Arrays::associate($arr, 'name[]'),
147147
);
148148

149149
Assert::same(
@@ -153,12 +153,12 @@ Assert::same(
153153
['Mary' => ['name' => 'Mary', 'age' => null]],
154154
['Paul' => ['name' => 'Paul', 'age' => 44]],
155155
],
156-
Arrays::associate($arr, '[]name')
156+
Arrays::associate($arr, '[]name'),
157157
);
158158

159159
Assert::same(
160160
['John', 'John', 'Mary', 'Paul'],
161-
Arrays::associate($arr, '[]=name')
161+
Arrays::associate($arr, '[]=name'),
162162
);
163163

164164
Assert::same(
@@ -174,12 +174,12 @@ Assert::same(
174174
[44 => ['name' => 'Paul', 'age' => 44]],
175175
],
176176
],
177-
Arrays::associate($arr, 'name[]age')
177+
Arrays::associate($arr, 'name[]age'),
178178
);
179179

180180
Assert::same(
181181
$arr,
182-
Arrays::associate($arr, '[]')
182+
Arrays::associate($arr, '[]'),
183183
);
184184

185185
// converts object to array
@@ -190,19 +190,19 @@ Assert::same(
190190
(object) ['name' => 'John', 'age' => 22],
191191
(object) ['name' => 'Mary', 'age' => null],
192192
(object) ['name' => 'Paul', 'age' => 44],
193-
], '[]')
193+
], '[]'),
194194
);
195195

196196
// allowes objects in keys
197197
Assert::equal(
198198
['2014-02-05 00:00:00' => new DateTime('2014-02-05')],
199199
Arrays::associate($arr = [
200200
['date' => new DateTime('2014-02-05')],
201-
], 'date=date')
201+
], 'date=date'),
202202
);
203203
Assert::equal(
204204
(object) ['2014-02-05 00:00:00' => new DateTime('2014-02-05')],
205205
Arrays::associate($arr = [
206206
['date' => new DateTime('2014-02-05')],
207-
], '->date=date')
207+
], '->date=date'),
208208
);

0 commit comments

Comments
 (0)