Skip to content

Commit c0b51b6

Browse files
committed
coding style
1 parent 72cf9e2 commit c0b51b6

File tree

11 files changed

+35
-31
lines changed

11 files changed

+35
-31
lines changed

src/PhpGenerator/Dumper.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private function dumpVar(mixed &$var, array $parents = [], int $level = 0, int $
5555
throw new Nette\InvalidArgumentException('Cannot dump resource.');
5656

5757
} else {
58-
return var_export($var, true);
58+
return var_export($var, return: true);
5959
}
6060
}
6161

@@ -105,7 +105,7 @@ private function dumpArray(array &$var, array $parents, int $level, int $column)
105105
if (empty($var)) {
106106
return '[]';
107107

108-
} elseif ($level > $this->maxDepth || in_array($var, $parents, true)) {
108+
} elseif ($level > $this->maxDepth || in_array($var, $parents, strict: true)) {
109109
throw new Nette\InvalidArgumentException('Nesting level too deep or recursive dependency.');
110110
}
111111

@@ -140,10 +140,10 @@ private function dumpObject(object $var, array $parents, int $level): string
140140
{
141141
$class = $var::class;
142142

143-
if (in_array($class, [\DateTime::class, \DateTimeImmutable::class], true)) {
143+
if (in_array($class, [\DateTime::class, \DateTimeImmutable::class], strict: true)) {
144144
return $this->format("new \\$class(?, new \\DateTimeZone(?))", $var->format('Y-m-d H:i:s.u'), $var->getTimeZone()->getName());
145145

146-
} elseif ($var instanceof \Serializable) { // deprecated
146+
} elseif ($var instanceof \Serializable) {
147147
return 'unserialize(' . $this->dumpString(serialize($var)) . ')';
148148

149149
} elseif ($var instanceof \UnitEnum) {
@@ -162,7 +162,7 @@ private function dumpObject(object $var, array $parents, int $level): string
162162
} elseif ((new \ReflectionObject($var))->isAnonymous()) {
163163
throw new Nette\InvalidArgumentException('Cannot dump anonymous class.');
164164

165-
} elseif ($level > $this->maxDepth || in_array($var, $parents, true)) {
165+
} elseif ($level > $this->maxDepth || in_array($var, $parents, strict: true)) {
166166
throw new Nette\InvalidArgumentException('Nesting level too deep or recursive dependency.');
167167
}
168168

src/PhpGenerator/Extractor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ private function addFunctionToFile(PhpFile $phpFile, Node\Stmt\Function_ $node):
295295
private function addTraitToClass(ClassLike $class, Node\Stmt\TraitUse $node): void
296296
{
297297
foreach ($node->traits as $item) {
298-
$trait = $class->addTrait($item->toString(), true);
298+
$trait = $class->addTrait($item->toString());
299299
}
300300

301301
foreach ($node->adaptations as $item) {

src/PhpGenerator/PhpNamespace.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function getBracketedSyntax(): bool
103103
public function addUse(string $name, ?string $alias = null, string $of = self::NameNormal): static
104104
{
105105
if (
106-
!Helpers::isNamespaceIdentifier($name, true)
106+
!Helpers::isNamespaceIdentifier($name, allowLeadingSlash: true)
107107
|| (Helpers::isIdentifier($name) && isset(Helpers::Keywords[strtolower($name)]))
108108
) {
109109
throw new Nette\InvalidArgumentException("Value '$name' is not valid class/function/constant name.");

src/PhpGenerator/Printer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,13 +335,13 @@ protected function printParameters(Closure|GlobalFunction|Method $function, int
335335
}
336336

337337
if (!$special || ($this->singleParameterOnOneLine && count($function->getParameters()) === 1)) {
338-
$line = $this->formatParameters($function, false);
338+
$line = $this->formatParameters($function, multiline: false);
339339
if (!str_contains($line, "\n") && strlen($line) + $column <= $this->wrapLength) {
340340
return $line;
341341
}
342342
}
343343

344-
return $this->formatParameters($function, true);
344+
return $this->formatParameters($function, multiline: true);
345345
}
346346

347347

src/PhpGenerator/TraitUse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ final class TraitUse
3030

3131
public function __construct(string $name, ?ClassLike $parent = null)
3232
{
33-
if (!Nette\PhpGenerator\Helpers::isNamespaceIdentifier($name, true)) {
33+
if (!Nette\PhpGenerator\Helpers::isNamespaceIdentifier($name, allowLeadingSlash: true)) {
3434
throw new Nette\InvalidArgumentException("Value '$name' is not valid trait name.");
3535
}
3636

src/PhpGenerator/Type.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ class Type
8383
public const STATIC = self::Static;
8484

8585

86-
public static function nullable(string $type, bool $state = true): string
86+
public static function nullable(string $type, bool $nullable = true): string
8787
{
88-
return ($state ? '?' : '') . ltrim($type, '?');
88+
return ($nullable ? '?' : '') . ltrim($type, '?');
8989
}
9090

9191

tests/PhpGenerator/ClassType.from.bodies.phpt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ require __DIR__ . '/../bootstrap.php';
99
require __DIR__ . '/fixtures/bodies.php';
1010

1111

12-
Assert::exception(function () {
13-
ClassType::from(PDO::class, withBodies: true);
14-
}, Nette\InvalidStateException::class, 'Source code of PDO not found.');
12+
Assert::exception(
13+
fn() => ClassType::from(PDO::class, withBodies: true),
14+
Nette\InvalidStateException::class,
15+
'Source code of PDO not found.',
16+
);
1517

1618

1719
Assert::exception(

tests/PhpGenerator/Helpers.comments.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ require __DIR__ . '/../bootstrap.php';
1515
Assert::same('', Helpers::formatDocComment(' '));
1616
Assert::same("/** @var string */\n", Helpers::formatDocComment('@var string'));
1717
Assert::same("/**\n * @var string\n */\n", Helpers::formatDocComment("@var string\n"));
18-
Assert::same("/**\n * @var string\n */\n", Helpers::formatDocComment('@var string', true));
18+
Assert::same("/**\n * @var string\n */\n", Helpers::formatDocComment('@var string', forceMultiLine: true));
1919
Assert::same("/**\n * A\n * B\n * C\n */\n", Helpers::formatDocComment("A\nB\nC\n"));
2020
Assert::same("/**\n * @var string\n */\n", Helpers::formatDocComment("@var string \r\n"));
2121
Assert::same("/**\n * A\n *\n * B\n */\n", Helpers::formatDocComment("A\n\nB"));

tests/PhpGenerator/Helpers.isNamespaceIdentifier.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ Assert::false(Helpers::isNamespaceIdentifier('Item\\\\Item'));
1717
Assert::false(Helpers::isNamespaceIdentifier('\\Item'));
1818
Assert::false(Helpers::isNamespaceIdentifier('Item\\'));
1919

20-
Assert::true(Helpers::isNamespaceIdentifier('\\Item', true));
21-
Assert::false(Helpers::isNamespaceIdentifier('Item\\', true));
20+
Assert::true(Helpers::isNamespaceIdentifier('\\Item', allowLeadingSlash: true));
21+
Assert::false(Helpers::isNamespaceIdentifier('Item\\', allowLeadingSlash: true));

tests/PhpGenerator/PhpNamespace.add.phpt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ use Tester\Assert;
88
require __DIR__ . '/../bootstrap.php';
99

1010

11-
Assert::exception(function () {
12-
(new PhpNamespace('Foo'))->add(new ClassType);
13-
}, Nette\InvalidArgumentException::class, 'Class does not have a name.');
11+
Assert::exception(
12+
fn() => (new PhpNamespace('Foo'))->add(new ClassType),
13+
Nette\InvalidArgumentException::class,
14+
'Class does not have a name.',
15+
);
1416

1517

1618
$namespace = (new PhpNamespace('Foo'))
@@ -40,10 +42,10 @@ Assert::same('X', $classB->getNamespace()->getName());
4042

4143

4244
// duplicity
43-
Assert::noError(function () use ($namespace, $classA) {
44-
$namespace->add($classA);
45-
});
45+
Assert::noError(fn() => $namespace->add($classA));
4646

47-
Assert::exception(function () use ($namespace) {
48-
$namespace->add(new ClassType('a'));
49-
}, Nette\InvalidStateException::class, "Cannot add 'a', because it already exists.");
47+
Assert::exception(
48+
fn() => $namespace->add(new ClassType('a')),
49+
Nette\InvalidStateException::class,
50+
"Cannot add 'a', because it already exists.",
51+
);

0 commit comments

Comments
 (0)