Skip to content

Commit c4ceab9

Browse files
committed
coding style
1 parent 5f1437d commit c4ceab9

24 files changed

+107
-110
lines changed

ecs.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
return function (Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator $containerConfigurator): void {
12-
$containerConfigurator->import(PRESET_DIR . '/php71.php');
12+
$containerConfigurator->import(PRESET_DIR . '/php80.php');
1313

1414
$parameters = $containerConfigurator->parameters();
1515

src/Iterators/CachingIterator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function __construct($iterator)
4747
} elseif ($iterator instanceof \Traversable) {
4848
$iterator = new \IteratorIterator($iterator);
4949
} else {
50-
throw new Nette\InvalidArgumentException(sprintf('Invalid argument passed to %s; array or Traversable expected, %s given.', self::class, is_object($iterator) ? get_class($iterator) : gettype($iterator)));
50+
throw new Nette\InvalidArgumentException(sprintf('Invalid argument passed to %s; array or Traversable expected, %s given.', self::class, is_object($iterator) ? $iterator::class : gettype($iterator)));
5151
}
5252

5353
parent::__construct($iterator, 0);

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
@@ -843,7 +843,7 @@ final public function attributes(): string
843843
. str_replace(
844844
['&', $q, '<'],
845845
['&amp;', $q === '"' ? '&quot;' : '&#39;', self::$xhtml ? '&lt;' : '<'],
846-
$value
846+
$value,
847847
)
848848
. (strpos($value, '`') !== false && strpbrk($value, ' <>"\'') === false ? ' ' : '')
849849
. $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
}
@@ -67,7 +67,7 @@ public static function strictCall(string $class, string $method, array $addition
6767
$hint = self::getSuggestion(array_merge(
6868
get_class_methods($class),
6969
self::parseFullDoc(new \ReflectionClass($class), '~^[ \t*]*@method[ \t]+(?:\S+[ \t]+)??(\w+)\(~m'),
70-
$additionalMethods
70+
$additionalMethods,
7171
), $method);
7272
throw new MemberAccessException("Call to undefined method $class::$method()" . ($hint ? ", did you mean $hint()?" : '.'));
7373
}
@@ -95,8 +95,8 @@ public static function strictStaticCall(string $class, string $method): void
9595

9696
} else {
9797
$hint = self::getSuggestion(
98-
array_filter((new \ReflectionClass($class))->getMethods(\ReflectionMethod::IS_PUBLIC), function ($m) { return $m->isStatic(); }),
99-
$method
98+
array_filter((new \ReflectionClass($class))->getMethods(\ReflectionMethod::IS_PUBLIC), fn($m) => $m->isStatic()),
99+
$method,
100100
);
101101
throw new MemberAccessException("Call to undefined static method $class::$method()" . ($hint ? ", did you mean $hint()?" : '.'));
102102
}
@@ -121,7 +121,7 @@ public static function getMagicProperties(string $class): array
121121
'~^ [ \t*]* @property(|-read|-write) [ \t]+ [^\s$]+ [ \t]+ \$ (\w+) ()~mx',
122122
(string) $rc->getDocComment(),
123123
$matches,
124-
PREG_SET_ORDER
124+
PREG_SET_ORDER,
125125
);
126126

127127
$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: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public static function assert($value, string $expected, string $label = 'variabl
9999
if (is_int($value) || is_float($value) || (is_string($value) && strlen($value) < 40)) {
100100
$type .= ' ' . var_export($value, true);
101101
} elseif (is_object($value)) {
102-
$type .= ' ' . get_class($value);
102+
$type .= ' ' . $value::class;
103103
}
104104
throw new AssertionException("The $label expects to be $expected, $type given.");
105105
}
@@ -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

0 commit comments

Comments
 (0)