Skip to content

Commit 8b0d808

Browse files
committed
cs
1 parent a73c124 commit 8b0d808

File tree

4 files changed

+25
-24
lines changed

4 files changed

+25
-24
lines changed

src/PhpGenerator/Extractor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function extractMethodBodies(string $className): array
7171

7272
$res = [];
7373
foreach ($nodeFinder->findInstanceOf($classNode, Node\Stmt\ClassMethod::class) as $methodNode) {
74-
/** @var Node\Stmt\ClassMethod $methodNode */
74+
assert($methodNode instanceof Node\Stmt\ClassMethod);
7575
if ($methodNode->stmts) {
7676
$res[$methodNode->name->toString()] = $this->getReformattedContents($methodNode->stmts, 2);
7777
}
@@ -83,11 +83,11 @@ public function extractMethodBodies(string $className): array
8383

8484
public function extractFunctionBody(string $name): ?string
8585
{
86-
/** @var Node\Stmt\Function_ $functionNode */
8786
$functionNode = (new NodeFinder)->findFirst(
8887
$this->statements,
8988
fn(Node $node) => $node instanceof Node\Stmt\Function_ && $node->namespacedName->toString() === $name,
9089
);
90+
assert($functionNode instanceof Node\Stmt\Function_);
9191

9292
return $this->getReformattedContents($functionNode->stmts, 1);
9393
}

src/PhpGenerator/Factory.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public function fromClassReflection(
3232
\ReflectionClass $from,
3333
bool $withBodies = false,
3434
?bool $materializeTraits = null,
35-
): ClassLike {
35+
): ClassLike
36+
{
3637
if ($materializeTraits !== null) {
3738
trigger_error(__METHOD__ . '() parameter $materializeTraits has been removed (is always false).', E_USER_DEPRECATED);
3839
}
@@ -70,7 +71,7 @@ public function fromClassReflection(
7071
}
7172

7273
$class->setComment(Helpers::unformatDocComment((string) $from->getDocComment()));
73-
$class->setAttributes(self::getAttributes($from));
74+
$class->setAttributes($this->getAttributes($from));
7475
if ($from->getParentClass()) {
7576
$class->setExtends($from->getParentClass()->name);
7677
$class->setImplements(array_diff($class->getImplements(), $from->getParentClass()->getInterfaceNames()));
@@ -160,7 +161,7 @@ public function fromMethodReflection(\ReflectionMethod $from): Method
160161
$method->setReturnReference($from->returnsReference());
161162
$method->setVariadic($from->isVariadic());
162163
$method->setComment(Helpers::unformatDocComment((string) $from->getDocComment()));
163-
$method->setAttributes(self::getAttributes($from));
164+
$method->setAttributes($this->getAttributes($from));
164165
$method->setReturnType((string) $from->getReturnType());
165166

166167
return $method;
@@ -177,7 +178,7 @@ public function fromFunctionReflection(\ReflectionFunction $from, bool $withBody
177178
$function->setComment(Helpers::unformatDocComment((string) $from->getDocComment()));
178179
}
179180

180-
$function->setAttributes(self::getAttributes($from));
181+
$function->setAttributes($this->getAttributes($from));
181182
$function->setReturnType((string) $from->getReturnType());
182183

183184
if ($withBody) {
@@ -196,8 +197,8 @@ public function fromCallable(callable $from): Method|GlobalFunction|Closure
196197
{
197198
$ref = Nette\Utils\Callback::toReflection($from);
198199
return $ref instanceof \ReflectionMethod
199-
? self::fromMethodReflection($ref)
200-
: self::fromFunctionReflection($ref);
200+
? $this->fromMethodReflection($ref)
201+
: $this->fromFunctionReflection($ref);
201202
}
202203

203204

@@ -226,7 +227,7 @@ public function fromParameterReflection(\ReflectionParameter $from): Parameter
226227
$param->setNullable($param->isNullable() && $param->getDefaultValue() !== null);
227228
}
228229

229-
$param->setAttributes(self::getAttributes($from));
230+
$param->setAttributes($this->getAttributes($from));
230231
return $param;
231232
}
232233

@@ -238,7 +239,7 @@ public function fromConstantReflection(\ReflectionClassConstant $from): Constant
238239
$const->setVisibility($this->getVisibility($from));
239240
$const->setFinal(PHP_VERSION_ID >= 80100 ? $from->isFinal() : false);
240241
$const->setComment(Helpers::unformatDocComment((string) $from->getDocComment()));
241-
$const->setAttributes(self::getAttributes($from));
242+
$const->setAttributes($this->getAttributes($from));
242243
return $const;
243244
}
244245

@@ -248,7 +249,7 @@ public function fromCaseReflection(\ReflectionClassConstant $from): EnumCase
248249
$const = new EnumCase($from->name);
249250
$const->setValue($from->getValue()->value ?? null);
250251
$const->setComment(Helpers::unformatDocComment((string) $from->getDocComment()));
251-
$const->setAttributes(self::getAttributes($from));
252+
$const->setAttributes($this->getAttributes($from));
252253
return $const;
253254
}
254255

@@ -265,7 +266,7 @@ public function fromPropertyReflection(\ReflectionProperty $from): Property
265266
$prop->setInitialized($from->hasType() && array_key_exists($prop->getName(), $defaults));
266267
$prop->setReadOnly(PHP_VERSION_ID >= 80100 ? $from->isReadOnly() : false);
267268
$prop->setComment(Helpers::unformatDocComment((string) $from->getDocComment()));
268-
$prop->setAttributes(self::getAttributes($from));
269+
$prop->setAttributes($this->getAttributes($from));
269270
return $prop;
270271
}
271272

src/PhpGenerator/Printer.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function printFunction(GlobalFunction $function, ?PhpNamespace $namespace
4949
$body = ltrim(rtrim(Strings::normalize($body)) . "\n");
5050

5151
return $this->printDocComment($function)
52-
. self::printAttributes($function->getAttributes())
52+
. $this->printAttributes($function->getAttributes())
5353
. $line
5454
. $this->printParameters($function, strlen($line) + strlen($returnType) + 2) // 2 = parentheses
5555
. $returnType
@@ -72,7 +72,7 @@ public function printClosure(Closure $closure, ?PhpNamespace $namespace = null):
7272
$body = Helpers::simplifyTaggedNames($closure->getBody(), $this->namespace);
7373
$body = ltrim(rtrim(Strings::normalize($body)) . "\n");
7474

75-
return self::printAttributes($closure->getAttributes(), inline: true)
75+
return $this->printAttributes($closure->getAttributes(), inline: true)
7676
. 'function '
7777
. ($closure->getReturnReference() ? '&' : '')
7878
. $this->printParameters($closure)
@@ -93,7 +93,7 @@ public function printArrowFunction(Closure $closure, ?PhpNamespace $namespace =
9393

9494
$body = Helpers::simplifyTaggedNames($closure->getBody(), $this->namespace);
9595

96-
return self::printAttributes($closure->getAttributes())
96+
return $this->printAttributes($closure->getAttributes())
9797
. 'fn'
9898
. ($closure->getReturnReference() ? '&' : '')
9999
. $this->printParameters($closure)
@@ -120,7 +120,7 @@ public function printMethod(Method $method, ?PhpNamespace $namespace = null, boo
120120
$braceOnNextLine = $this->bracesOnNextLine && !str_contains($params, "\n");
121121

122122
return $this->printDocComment($method)
123-
. self::printAttributes($method->getAttributes())
123+
. $this->printAttributes($method->getAttributes())
124124
. $line
125125
. $params
126126
. $returnType
@@ -133,7 +133,8 @@ public function printMethod(Method $method, ?PhpNamespace $namespace = null, boo
133133
public function printClass(
134134
ClassType|InterfaceType|TraitType|EnumType $class,
135135
?PhpNamespace $namespace = null,
136-
): string {
136+
): string
137+
{
137138
$this->namespace = $this->resolveTypes ? $namespace : null;
138139
$class->validate();
139140
$resolver = $this->namespace
@@ -159,7 +160,7 @@ public function printClass(
159160
foreach ($class->getCases() as $case) {
160161
$enumType ??= is_scalar($case->getValue()) ? get_debug_type($case->getValue()) : null;
161162
$cases[] = $this->printDocComment($case)
162-
. self::printAttributes($case->getAttributes())
163+
. $this->printAttributes($case->getAttributes())
163164
. 'case ' . $case->getName()
164165
. ($case->getValue() === null ? '' : ' = ' . $this->dump($case->getValue()))
165166
. ";\n";
@@ -174,7 +175,7 @@ public function printClass(
174175
. 'const ' . $const->getName() . ' = ';
175176

176177
$consts[] = $this->printDocComment($const)
177-
. self::printAttributes($const->getAttributes())
178+
. $this->printAttributes($const->getAttributes())
178179
. $def
179180
. $this->dump($const->getValue(), strlen($def)) . ";\n";
180181
}
@@ -205,7 +206,7 @@ public function printClass(
205206
. '$' . $property->getName());
206207

207208
$properties[] = $this->printDocComment($property)
208-
. self::printAttributes($property->getAttributes())
209+
. $this->printAttributes($property->getAttributes())
209210
. $def
210211
. ($property->getValue() === null && !$property->isInitialized()
211212
? ''
@@ -243,7 +244,7 @@ public function printClass(
243244
$line[] = $class->getName() ? null : '{';
244245

245246
return $this->printDocComment($class)
246-
. self::printAttributes($class->getAttributes())
247+
. $this->printAttributes($class->getAttributes())
247248
. implode(' ', array_filter($line))
248249
. ($class->getName() ? "\n{\n" : "\n")
249250
. ($members ? $this->indent(implode("\n", $members)) : '')
@@ -333,7 +334,7 @@ protected function printParameters(Closure|GlobalFunction|Method $function, int
333334
$promoted = $param instanceof PromotedParameter ? $param : null;
334335
$params[] =
335336
($promoted ? $this->printDocComment($promoted) : '')
336-
. ($attrs = self::printAttributes($param->getAttributes(), inline: true))
337+
. ($attrs = $this->printAttributes($param->getAttributes(), inline: true))
337338
. ($promoted ?
338339
($promoted->getVisibility() ?: 'public')
339340
. ($promoted->isReadOnly() && $type ? ' readonly' : '')

tests/PhpGenerator/Method.returnTypes.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ namespace A
1313
}
1414
}
1515

16-
namespace
17-
{
16+
namespace {
1817
use Nette\PhpGenerator\Method;
1918
use Tester\Assert;
2019

0 commit comments

Comments
 (0)