Skip to content

Commit 23113a7

Browse files
committed
cs
1 parent 50a8827 commit 23113a7

9 files changed

Lines changed: 28 additions & 42 deletions

File tree

src/PhpGenerator/Attribute.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,14 @@
1515
*/
1616
final class Attribute
1717
{
18-
private string $name;
19-
20-
/** @var mixed[] */
21-
private array $args;
22-
23-
24-
/** @param mixed[] $args */
25-
public function __construct(string $name, array $args)
26-
{
18+
public function __construct(
19+
private readonly string $name,
20+
/** @var mixed[] */
21+
private readonly array $args,
22+
) {
2723
if (!Helpers::isNamespaceIdentifier($name)) {
2824
throw new Nette\InvalidArgumentException("Value '$name' is not valid attribute name.");
2925
}
30-
31-
$this->name = $name;
32-
$this->args = $args;
3326
}
3427

3528

src/PhpGenerator/ClassManipulator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
final class ClassManipulator
1515
{
1616
public function __construct(
17-
private ClassType $class,
17+
private readonly ClassType $class,
1818
) {
1919
}
2020

src/PhpGenerator/Dumper.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace Nette\PhpGenerator;
99

1010
use Nette;
11-
use function addcslashes, array_keys, array_shift, count, dechex, implode, in_array, is_array, is_int, is_object, is_resource, is_string, ltrim, method_exists, ord, preg_match, preg_replace, preg_replace_callback, preg_split, range, serialize, str_contains, str_pad, str_repeat, str_replace, strlen, strrpos, strtoupper, substr, trim, unserialize, var_export;
11+
use function addcslashes, array_keys, array_shift, count, dechex, get_mangled_object_vars, implode, in_array, is_array, is_int, is_object, is_resource, is_string, ltrim, method_exists, ord, preg_match, preg_replace, preg_replace_callback, preg_split, range, serialize, str_contains, str_pad, str_repeat, str_replace, strlen, strrpos, strtoupper, substr, trim, unserialize, var_export;
1212
use const PREG_SPLIT_DELIM_CAPTURE, STR_PAD_LEFT;
1313

1414

@@ -149,15 +149,15 @@ private function dumpObject(object $var, array $parents, int $level, int $column
149149
return $this->format(
150150
"new \\$class(?, new \\DateTimeZone(?))",
151151
$var->format('Y-m-d H:i:s.u'),
152-
$var->getTimeZone()->getName(),
152+
$var->getTimezone()->getName(),
153153
);
154154

155155
} elseif ($var instanceof \UnitEnum) {
156156
return '\\' . $var::class . '::' . $var->name;
157157

158158
} elseif ($var instanceof \Closure) {
159159
$inner = Nette\Utils\Callback::unwrap($var);
160-
if (Nette\Utils\Callback::isStatic($inner)) {
160+
if (is_callable($inner) && Nette\Utils\Callback::isStatic($inner)) {
161161
return implode('::', (array) $inner) . '(...)';
162162
}
163163

@@ -276,7 +276,7 @@ private function dumpArguments(array $args, int $column, bool $named): string
276276
*/
277277
public static function createObject(string $class, array $props): object
278278
{
279-
if (method_exists($class, '__serialize')) {
279+
if (method_exists($class, '__unserialize')) {
280280
$obj = (new \ReflectionClass($class))->newInstanceWithoutConstructor();
281281
$obj->__unserialize($props);
282282
return $obj;

src/PhpGenerator/Extractor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ private function prepareReplacements(array $nodes, int $level): array
157157

158158
} elseif (
159159
$node instanceof Node\Scalar\String_
160-
&& in_array($node->getAttribute('kind'), [Node\Scalar\String_::KIND_SINGLE_QUOTED, Node\Scalar\String_::KIND_DOUBLE_QUOTED], true)
160+
&& in_array($node->getAttribute('kind'), [Node\Scalar\String_::KIND_SINGLE_QUOTED, Node\Scalar\String_::KIND_DOUBLE_QUOTED], strict: true)
161161
&& str_contains($node->getAttribute('rawValue'), "\n")
162162
) { // multi-line strings -> single line
163163
$replacements[] = [
@@ -168,7 +168,7 @@ private function prepareReplacements(array $nodes, int $level): array
168168

169169
} elseif (
170170
$node instanceof Node\Scalar\String_
171-
&& in_array($node->getAttribute('kind'), [Node\Scalar\String_::KIND_NOWDOC, Node\Scalar\String_::KIND_HEREDOC], true)
171+
&& in_array($node->getAttribute('kind'), [Node\Scalar\String_::KIND_NOWDOC, Node\Scalar\String_::KIND_HEREDOC], strict: true)
172172
&& Helpers::unindent($node->getAttribute('docIndentation'), $level) === $node->getAttribute('docIndentation')
173173
) { // fix indentation of NOWDOW/HEREDOC
174174
$replacements[] = [

src/PhpGenerator/Factory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function fromClassReflection(
156156
public function fromMethodReflection(\ReflectionMethod $from): Method
157157
{
158158
$method = new Method($from->name);
159-
$method->setParameters(array_map([$this, 'fromParameterReflection'], $from->getParameters()));
159+
$method->setParameters(array_map($this->fromParameterReflection(...), $from->getParameters()));
160160
$method->setStatic($from->isStatic());
161161
$isInterface = $from->getDeclaringClass()->isInterface();
162162
$method->setVisibility($isInterface ? null : $this->getVisibility($from));
@@ -175,7 +175,7 @@ public function fromMethodReflection(\ReflectionMethod $from): Method
175175
public function fromFunctionReflection(\ReflectionFunction $from, bool $withBody = false): GlobalFunction|Closure
176176
{
177177
$function = $from->isClosure() ? new Closure : new GlobalFunction($from->name);
178-
$function->setParameters(array_map([$this, 'fromParameterReflection'], $from->getParameters()));
178+
$function->setParameters(array_map($this->fromParameterReflection(...), $from->getParameters()));
179179
$function->setReturnReference($from->returnsReference());
180180
$function->setVariadic($from->isVariadic());
181181
if (!$from->isClosure()) {
@@ -313,7 +313,7 @@ private function addHooks(\ReflectionProperty $from, Property|PromotedParameter
313313
$params = [];
314314
}
315315
$prop->addHook($type)
316-
->setParameters(array_map([$this, 'fromParameterReflection'], $params))
316+
->setParameters(array_map($this->fromParameterReflection(...), $params))
317317
->setAbstract($hook->isAbstract())
318318
->setFinal($hook->isFinal())
319319
->setReturnReference($hook->returnsReference())

src/PhpGenerator/Literal.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ public static function new(string $class, array $args = []): self
2424

2525

2626
public function __construct(
27-
private string $value,
27+
private readonly string $value,
2828
/** @var ?mixed[] */
29-
private ?array $args = null,
29+
private readonly ?array $args = null,
3030
) {
3131
}
3232

src/PhpGenerator/Printer.php

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public function printClass(
145145
$this->namespace = $this->resolveTypes ? $namespace : null;
146146
$class->validate();
147147
$resolver = $this->namespace
148-
? [$namespace, 'simplifyType']
148+
? $namespace->simplifyType(...)
149149
: fn($s) => $s;
150150

151151
$traits = [];
@@ -178,23 +178,16 @@ public function printClass(
178178
$readOnlyClass = $class instanceof ClassType && $class->isReadOnly();
179179
$consts = [];
180180
$methods = [];
181-
if (
182-
$class instanceof ClassType
183-
|| $class instanceof InterfaceType
184-
|| $class instanceof TraitType
185-
|| $class instanceof EnumType
186-
) {
187-
foreach ($class->getConstants() as $const) {
188-
$consts[] = $this->printConstant($const);
189-
}
181+
foreach ($class->getConstants() as $const) {
182+
$consts[] = $this->printConstant($const);
183+
}
190184

191-
foreach ($class->getMethods() as $method) {
192-
if ($readOnlyClass && $method->getName() === Method::Constructor) {
193-
$method = clone $method;
194-
array_map(fn($param) => $param instanceof PromotedParameter ? $param->setReadOnly(false) : null, $method->getParameters());
195-
}
196-
$methods[] = $this->printMethod($method, $namespace, $class->isInterface());
185+
foreach ($class->getMethods() as $method) {
186+
if ($readOnlyClass && $method->getName() === Method::Constructor) {
187+
$method = clone $method;
188+
array_map(fn($param) => $param instanceof PromotedParameter ? $param->setReadOnly(false) : null, $method->getParameters());
197189
}
190+
$methods[] = $this->printMethod($method, $namespace, $class->isInterface());
198191
}
199192

200193
$properties = [];

src/PhpGenerator/Traits/PropertyLike.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function setPublic(PropertyAccessMode|string $mode = PropertyAccessMode::
5656
public function isPublic(PropertyAccessMode|string $mode = PropertyAccessMode::Get): bool
5757
{
5858
$mode = is_string($mode) ? PropertyAccessMode::from($mode) : $mode;
59-
return in_array($this->visibility[$mode->value], [Visibility::Public, null], true);
59+
return in_array($this->visibility[$mode->value], [Visibility::Public, null], strict: true);
6060
}
6161

6262

src/PhpGenerator/Traits/TraitsAware.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function addTrait(string $name): TraitUse
5555
$this->traits[$name] = $trait = new TraitUse($name);
5656
if (func_num_args() > 1 && is_array(func_get_arg(1))) { // back compatibility
5757
trigger_error('Passing second argument to ' . __METHOD__ . '() is deprecated, use addResolution() instead.');
58-
array_map(fn($item) => $trait->addResolution($item), func_get_arg(1));
58+
array_map($trait->addResolution(...), func_get_arg(1));
5959
}
6060

6161
return $trait;

0 commit comments

Comments
 (0)