Skip to content

Commit 8508449

Browse files
committed
coding style
1 parent 0206d6a commit 8508449

28 files changed

+124
-133
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
@@ -844,7 +844,7 @@ final public function attributes(): string
844844
. str_replace(
845845
['&', $q, '<'],
846846
['&amp;', $q === '"' ? '&quot;' : '&#39;', self::$xhtml ? '&lt;' : '<'],
847-
$value
847+
$value,
848848
)
849849
. (strpos($value, '`') !== false && strpbrk($value, ' <>"\'') === false ? ' ' : '')
850850
. $q;

src/Utils/Image.php

Lines changed: 6 additions & 6 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
}
@@ -580,7 +580,7 @@ public function save(string $file, int $quality = null, int $type = null): void
580580
*/
581581
public function toString(int $type = self::JPEG, int $quality = null): string
582582
{
583-
return Helpers::capture(function () use ($type, $quality) {
583+
return Helpers::capture(function () use ($type, $quality): void {
584584
$this->output($type, $quality);
585585
});
586586
}
@@ -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: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public static function strictGet(string $class, string $name): void
2828
{
2929
$rc = new \ReflectionClass($class);
3030
$hint = self::getSuggestion(array_merge(
31-
array_filter($rc->getProperties(\ReflectionProperty::IS_PUBLIC), function ($p) { return !$p->isStatic(); }),
32-
self::parseFullDoc($rc, '~^[ \t*]*@property(?:-read)?[ \t]+(?:\S+[ \t]+)??\$(\w+)~m')
31+
array_filter($rc->getProperties(\ReflectionProperty::IS_PUBLIC), fn($p) => !$p->isStatic()),
32+
self::parseFullDoc($rc, '~^[ \t*]*@property(?:-read)?[ \t]+(?:\S+[ \t]+)??\$(\w+)~m'),
3333
), $name);
3434
throw new MemberAccessException("Cannot read an undeclared property $class::\$$name" . ($hint ? ", did you mean \$$hint?" : '.'));
3535
}
@@ -43,8 +43,8 @@ public static function strictSet(string $class, string $name): void
4343
{
4444
$rc = new \ReflectionClass($class);
4545
$hint = self::getSuggestion(array_merge(
46-
array_filter($rc->getProperties(\ReflectionProperty::IS_PUBLIC), function ($p) { return !$p->isStatic(); }),
47-
self::parseFullDoc($rc, '~^[ \t*]*@property(?:-write)?[ \t]+(?:\S+[ \t]+)??\$(\w+)~m')
46+
array_filter($rc->getProperties(\ReflectionProperty::IS_PUBLIC), fn($p) => !$p->isStatic()),
47+
self::parseFullDoc($rc, '~^[ \t*]*@property(?:-write)?[ \t]+(?:\S+[ \t]+)??\$(\w+)~m'),
4848
), $name);
4949
throw new MemberAccessException("Cannot write to an undeclared property $class::\$$name" . ($hint ? ", did you mean \$$hint?" : '.'));
5050
}
@@ -76,7 +76,7 @@ public static function strictCall(string $class, string $method, array $addition
7676
$hint = self::getSuggestion(array_merge(
7777
get_class_methods($class),
7878
self::parseFullDoc(new \ReflectionClass($class), '~^[ \t*]*@method[ \t]+(?:\S+[ \t]+)??(\w+)\(~m'),
79-
$additionalMethods
79+
$additionalMethods,
8080
), $method);
8181
throw new MemberAccessException("Call to undefined method $class::$method()" . ($hint ? ", did you mean $hint()?" : '.'));
8282
}
@@ -107,8 +107,8 @@ public static function strictStaticCall(string $class, string $method): void
107107

108108
} else {
109109
$hint = self::getSuggestion(
110-
array_filter((new \ReflectionClass($class))->getMethods(\ReflectionMethod::IS_PUBLIC), function ($m) { return $m->isStatic(); }),
111-
$method
110+
array_filter((new \ReflectionClass($class))->getMethods(\ReflectionMethod::IS_PUBLIC), fn($m) => $m->isStatic()),
111+
$method,
112112
);
113113
throw new MemberAccessException("Call to undefined static method $class::$method()" . ($hint ? ", did you mean $hint()?" : '.'));
114114
}
@@ -133,7 +133,7 @@ public static function getMagicProperties(string $class): array
133133
'~^ [ \t*]* @property(|-read|-write) [ \t]+ [^\s$]+ [ \t]+ \$ (\w+) ()~mx',
134134
(string) $rc->getDocComment(),
135135
$matches,
136-
PREG_SET_ORDER
136+
PREG_SET_ORDER,
137137
);
138138

139139
$props = [];
@@ -196,7 +196,7 @@ private static function parseFullDoc(\ReflectionClass $rc, string $pattern): arr
196196
$traits += $trait->getTraits();
197197
}
198198
} while ($rc = $rc->getParentClass());
199-
return preg_match_all($pattern, implode($doc), $m) ? $m[1] : [];
199+
return preg_match_all($pattern, implode('', $doc), $m) ? $m[1] : [];
200200
}
201201

202202

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/Type.php

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ public static function fromReflection($reflection): ?self
5252
} elseif ($type instanceof \ReflectionUnionType || $type instanceof \ReflectionIntersectionType) {
5353
return new self(
5454
array_map(
55-
function ($t) use ($reflection) { return self::resolve($t->getName(), $reflection); },
56-
$type->getTypes()
55+
fn($t) => self::resolve($t->getName(), $reflection),
56+
$type->getTypes(),
5757
),
58-
$type instanceof \ReflectionUnionType ? '|' : '&'
58+
$type instanceof \ReflectionUnionType ? '|' : '&',
5959
);
6060

6161
} else {
@@ -140,7 +140,7 @@ public function getNames(): array
140140
*/
141141
public function getTypes(): array
142142
{
143-
return array_map(function ($name) { return self::fromString($name); }, $this->types);
143+
return array_map(fn($name) => self::fromString($name), $this->types);
144144
}
145145

146146

@@ -221,27 +221,21 @@ public function allows(string $type): bool
221221
$type = self::fromString($type);
222222

223223
if ($this->isIntersection()) {
224-
if (!$type->isIntersection()) {
225-
return false;
226-
}
227-
return Arrays::every($this->types, function ($currentType) use ($type) {
228-
$builtin = Reflection::isBuiltinType($currentType);
229-
return Arrays::some($type->types, function ($testedType) use ($currentType, $builtin) {
230-
return $builtin
224+
return $type->isIntersection()
225+
&& Arrays::every($this->types, function ($currentType) use ($type) {
226+
$builtin = Reflection::isBuiltinType($currentType);
227+
return Arrays::some($type->types, fn($testedType) => $builtin
231228
? strcasecmp($currentType, $testedType) === 0
232-
: is_a($testedType, $currentType, true);
229+
: is_a($testedType, $currentType, true));
233230
});
234-
});
235231
}
236232

237233
$method = $type->isIntersection() ? 'some' : 'every';
238234
return Arrays::$method($type->types, function ($testedType) {
239235
$builtin = Reflection::isBuiltinType($testedType);
240-
return Arrays::some($this->types, function ($currentType) use ($testedType, $builtin) {
241-
return $builtin
242-
? strcasecmp($currentType, $testedType) === 0
243-
: is_a($testedType, $currentType, true);
244-
});
236+
return Arrays::some($this->types, fn($currentType) => $builtin
237+
? strcasecmp($currentType, $testedType) === 0
238+
: is_a($testedType, $currentType, true));
245239
});
246240
}
247241
}

0 commit comments

Comments
 (0)