Skip to content

Commit c7019da

Browse files
committedJan 24, 2025
Merge pull request #1208: Apply risky Code Style rules
1 parent d12ed37 commit c7019da

28 files changed

+167
-166
lines changed
 

‎src/Config/Alias.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ public function __construct(
1616

1717
public function __toString(): string
1818
{
19-
return sprintf('Alias to `%s`', $this->alias);
19+
return \sprintf('Alias to `%s`', $this->alias);
2020
}
2121
}

‎src/Config/DeferredFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function __construct(
1919

2020
public function __toString(): string
2121
{
22-
return sprintf(
22+
return \sprintf(
2323
"Deferred factory '%s'->%s()",
2424
\is_string($this->factory[0]) ? $this->factory[0] : \get_debug_type($this->factory[0]),
2525
$this->factory[1],

‎src/Config/DeprecationProxy.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function getInterface(): string
3838
$this->version,
3939
);
4040

41-
@trigger_error($message, \E_USER_DEPRECATED);
41+
@\trigger_error($message, \E_USER_DEPRECATED);
4242

4343
return parent::getInterface();
4444
}

‎src/Config/Scalar.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ public function __construct(
1212

1313
public function __toString(): string
1414
{
15-
return sprintf('Scalar value (%s) %s', \gettype($this->value), \var_export($this->value, true));
15+
return \sprintf('Scalar value (%s) %s', \gettype($this->value), \var_export($this->value, true));
1616
}
1717
}

‎src/Internal/Introspector/Accessor.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public function __construct(
3535

3636
public function __get(string $name): object
3737
{
38-
return (fn(PublicContainer $c): object => $c->$name)->call($this->publicContainer, $this->publicContainer);
38+
return (static fn(PublicContainer $c): object => $c->$name)
39+
->bindTo(null, $this->publicContainer)($this->publicContainer);
3940
}
4041
}

‎src/Internal/Proxy/ProxyClassRenderer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public static function renderClass(
108108

109109
$traitsStr = $traits === [] ? '' : \implode(
110110
"\n ",
111-
\array_map(fn(string $trait): string => 'use \\' . \ltrim($trait, '\\') . ';', $traits),
111+
\array_map(static fn(string $trait): string => 'use \\' . \ltrim($trait, '\\') . ';', $traits),
112112
);
113113
return <<<PHP
114114
$classNamespaceStr

‎tests/AutowireTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ public function testSerializeAutowire(): void
337337
{
338338
$wire = new Container\Autowire('sample-binding', ['a' => new Container\Autowire('b')]);
339339

340-
$wireb = unserialize(serialize($wire));
340+
$wireb = \unserialize(\serialize($wire));
341341

342342
self::assertEquals($wire, $wireb);
343343
}

‎tests/BindingsTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function testInstanceBindingWithForceMode(): void
6565
$options = new Options();
6666
$options->allowSingletonsRebinding = true;
6767
$container = new Container(options: $options);
68-
$container->bindSingleton('sampleClass', fn(): SampleClass => new SampleClass());
68+
$container->bindSingleton('sampleClass', static fn(): SampleClass => new SampleClass());
6969

7070
$instance = $container->get('sampleClass');
7171
$container->bindSingleton('sampleClass', new SampleClass());
@@ -78,7 +78,7 @@ public function testInstanceBindingWithForceMode2(): void
7878
$options = new Options();
7979
$options->allowSingletonsRebinding = false;
8080
$container = new Container(options: $options);
81-
$container->bindSingleton('sampleClass', fn(): SampleClass => new SampleClass());
81+
$container->bindSingleton('sampleClass', static fn(): SampleClass => new SampleClass());
8282

8383
$instance = $container->get('sampleClass');
8484
$container->bindSingleton('sampleClass', new SampleClass(), true);
@@ -111,7 +111,7 @@ public function testInstanceBindingWithoutForceMode2(): void
111111
{
112112
$container = new Container();
113113

114-
$container->bindSingleton('sampleClass', fn(): SampleClass => new SampleClass());
114+
$container->bindSingleton('sampleClass', static fn(): SampleClass => new SampleClass());
115115

116116
$container->get('sampleClass');
117117

@@ -138,7 +138,7 @@ public function testInstanceBindingWithoutForceMode4(): void
138138
$options->allowSingletonsRebinding = false;
139139
$container = new Container(options: $options);
140140

141-
$container->bindSingleton('sampleClass', fn(): SampleClass => new SampleClass());
141+
$container->bindSingleton('sampleClass', static fn(): SampleClass => new SampleClass());
142142

143143
$container->get('sampleClass');
144144

‎tests/InjectableConfigTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ public function testSerialize(): void
108108
'keyB' => 'valueB',
109109
]);
110110

111-
$serialized = serialize($config);
112-
self::assertEquals($config, unserialize($serialized));
111+
$serialized = \serialize($config);
112+
self::assertEquals($config, \unserialize($serialized));
113113

114114
self::assertEquals($config, TestConfig::__set_state([
115115
'config' => [

‎tests/Internal/Common/CommonTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function testDisableArgumentsValidationWithInvoker(): void
5050

5151
$this->expectException(\TypeError::class);
5252

53-
$container->invoke(fn(int $x): int => $x, [
53+
$container->invoke(static fn(int $x): int => $x, [
5454
'x' => 'string',
5555
]);
5656
}
@@ -63,7 +63,7 @@ public function testEnableArgumentsValidationWithInvoker(): void
6363

6464
$this->expectException(InvalidArgumentException::class);
6565

66-
$container->invoke(fn(int $x): int => $x, [
66+
$container->invoke(static fn(int $x): int => $x, [
6767
'x' => 'string',
6868
]);
6969
}

‎tests/Internal/Destructor/FinalizerTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class FinalizerTest extends TestCase
1111
{
1212
public function testInternalServicesDontBlockContainer(): void
1313
{
14-
(static function () {
14+
(static function (): void {
1515
$container = new Container();
1616
$finalizer = new class {
1717
public ?\Closure $closure = null;
@@ -23,7 +23,7 @@ public function __destruct()
2323
}
2424
}
2525
};
26-
$finalizer->closure = static function () use ($container) {
26+
$finalizer->closure = static function () use ($container): void {
2727
$container->hasInstance('finalizer');
2828
};
2929
$container->bind('finalizer', $finalizer);

‎tests/Internal/Destructor/MemoryLeaksTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ private function collectInternal(object $source): \WeakMap
3434
{
3535
$map = new \WeakMap();
3636

37-
$fn = function (\WeakMap $map) {
37+
$fn = function (\WeakMap $map): void {
3838
foreach ($this as $key => $value) {
3939
if (\is_object($value)) {
4040
$map->offsetSet($value, $key);

‎tests/Internal/Factory/CommonCasesTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function testMakeInternalClass(): void
6161
'other-parameter' => true,
6262
]);
6363

64-
$this->assertSame(basename(__FILE__), $object->getFilename());
64+
$this->assertSame(\basename(__FILE__), $object->getFilename());
6565
}
6666

6767
public function testMakeInternalClassWithOptional(): void
@@ -89,7 +89,7 @@ public function testAutoFactory(): void
8989

9090
public function testClosureFactory(): void
9191
{
92-
$this->bind(Bucket::class, function ($data) {
92+
$this->bind(Bucket::class, static function ($data) {
9393
return new Bucket('via-closure', $data);
9494
});
9595

@@ -129,7 +129,7 @@ public function testCascadeFactory(): void
129129
$sample = new SampleClass();
130130

131131
$this->bind(Bucket::class, [Factory::class, 'makeBucketWithSample']);
132-
$this->bind(SampleClass::class, function () use ($sample) {
132+
$this->bind(SampleClass::class, static function () use ($sample) {
133133
return $sample;
134134
});
135135

‎tests/Internal/Introspector/CommonTest.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function testScopeName(): void
2121

2222
$container->invoke(static fn() => self::assertSame('root', Introspector::scopeName()));
2323

24-
$container->runScope(new Scope('test'), function (ContainerInterface $container): void {
24+
$container->runScope(new Scope('test'), static function (ContainerInterface $container): void {
2525
self::assertSame('test', Introspector::scopeName($container));
2626
self::assertSame('test', Introspector::scopeName());
2727
});
@@ -31,9 +31,9 @@ public function testScopeNames(): void
3131
{
3232
$container = new Container();
3333

34-
$container->runScope(new Scope('test'), function (Container $c): void {
35-
$c->runScope(new Scope(), function (Container $c): void {
36-
$c->runScope(new Scope('bar'), function (Container $c): void {
34+
$container->runScope(new Scope('test'), static function (Container $c): void {
35+
$c->runScope(new Scope(), static function (Container $c): void {
36+
$c->runScope(new Scope('bar'), static function (Container $c): void {
3737
self::assertSame(['bar', null, 'test', 'root'], Introspector::scopeNames($c));
3838
self::assertSame(['bar', null, 'test', 'root'], Introspector::scopeNames());
3939
});
@@ -45,9 +45,9 @@ public function testProxyContainer(): void
4545
{
4646
$container = new Container();
4747

48-
$container->runScope(new Scope('test'), function (Container $c): void {
49-
$c->runScope(new Scope(), function (Container $c): void {
50-
$c->runScope(new Scope('bar'), function (Container $c, #[Proxy] ContainerInterface $proxy): void {
48+
$container->runScope(new Scope('test'), static function (Container $c): void {
49+
$c->runScope(new Scope(), static function (Container $c): void {
50+
$c->runScope(new Scope('bar'), static function (Container $c, #[Proxy] ContainerInterface $proxy): void {
5151
self::assertSame(['bar', null, 'test', 'root'], Introspector::scopeNames($proxy));
5252
});
5353
});

‎tests/Internal/Proxy/ProxyClassRendererTest.php

+38-38
Original file line numberDiff line numberDiff line change
@@ -27,35 +27,35 @@ public static function provideRenderParameter(): iterable
2727
{
2828
$from = static fn(\Closure $closure): \ReflectionParameter => new \ReflectionParameter($closure, 0);
2929

30-
yield [$from(fn($string) => 0), '$string'];
31-
yield [$from(fn($string = '') => 0), '$string = \'\''];
32-
yield [$from(fn(string $string = "\n\\'\"") => 0), "mixed \$string = '\n\\\\\\'\"'"];
33-
yield [$from(fn(string $string = '123') => 0), 'mixed $string = \'123\''];
34-
yield [$from(fn(string $string = self::STRING_CONST) => 0), 'mixed $string = self::STRING_CONST'];
30+
yield [$from(static fn($string) => 0), '$string'];
31+
yield [$from(static fn($string = '') => 0), '$string = \'\''];
32+
yield [$from(static fn(string $string = "\n\\'\"") => 0), "mixed \$string = '\n\\\\\\'\"'"];
33+
yield [$from(static fn(string $string = '123') => 0), 'mixed $string = \'123\''];
34+
yield [$from(static fn(string $string = self::STRING_CONST) => 0), 'mixed $string = self::STRING_CONST'];
3535
yield [
36-
$from(fn(string $string = ProxyClassRendererTest::STRING_CONST) => 0),
36+
$from(static fn(string $string = ProxyClassRendererTest::STRING_CONST) => 0),
3737
'mixed $string = \\' . self::class . '::STRING_CONST',
3838
];
39-
yield [$from(fn(string|int $string = self::INT_CONST) => 0), 'mixed $string = self::INT_CONST'];
40-
yield [$from(fn(mixed $string = 42) => 0), 'mixed $string = 42'];
41-
yield [$from(fn(int $string = 42) => 0), 'mixed $string = 42'];
42-
yield [$from(fn(float $string = 42) => 0), 'mixed $string = 42.0'];
43-
yield [$from(fn(?bool $string = false) => 0), 'mixed $string = false'];
44-
yield [$from(fn(bool|null $string = true) => 0), 'mixed $string = true'];
45-
yield [$from(fn(?object $string = null) => 0), 'mixed $string = NULL'];
46-
yield [$from(fn(?iterable $string = null) => 0), 'mixed $string = NULL'];
47-
yield [$from(fn(\Countable&\ArrayAccess $val) => 0), 'mixed $val'];
48-
yield [$from(fn(string ...$val) => 0), 'mixed ...$val'];
49-
yield [$from(fn(string|int ...$val) => 0), 'mixed ...$val'];
50-
yield [$from(fn(string|int &$link) => 0), 'mixed &$link'];
39+
yield [$from(static fn(string|int $string = self::INT_CONST) => 0), 'mixed $string = self::INT_CONST'];
40+
yield [$from(static fn(mixed $string = 42) => 0), 'mixed $string = 42'];
41+
yield [$from(static fn(int $string = 42) => 0), 'mixed $string = 42'];
42+
yield [$from(static fn(float $string = 42) => 0), 'mixed $string = 42.0'];
43+
yield [$from(static fn(?bool $string = false) => 0), 'mixed $string = false'];
44+
yield [$from(static fn(bool|null $string = true) => 0), 'mixed $string = true'];
45+
yield [$from(static fn(?object $string = null) => 0), 'mixed $string = NULL'];
46+
yield [$from(static fn(?iterable $string = null) => 0), 'mixed $string = NULL'];
47+
yield [$from(static fn(\Countable&\ArrayAccess $val) => 0), 'mixed $val'];
48+
yield [$from(static fn(string ...$val) => 0), 'mixed ...$val'];
49+
yield [$from(static fn(string|int ...$val) => 0), 'mixed ...$val'];
50+
yield [$from(static fn(string|int &$link) => 0), 'mixed &$link'];
5151
yield [$from(self::withSelf(...)), 'mixed $self = new self()'];
52-
yield [$from(fn(object $link = new \stdClass()) => 0), 'mixed $link = new \stdClass()'];
52+
yield [$from(static fn(object $link = new \stdClass()) => 0), 'mixed $link = new \stdClass()'];
5353
yield [
54-
$from(fn(#[Proxy] float|int|\stdClass|null $string = new \stdClass(1, 2, bar: "\n'zero")) => 0),
54+
$from(static fn(#[Proxy] float|int|\stdClass|null $string = new \stdClass(1, 2, bar: "\n'zero")) => 0),
5555
"mixed \$string = new \stdClass(1, 2, bar: '\n\'zero')",
5656
];
5757
yield [
58-
$from(fn(SimpleEnum $val = SimpleEnum::B) => 0),
58+
$from(static fn(SimpleEnum $val = SimpleEnum::B) => 0),
5959
\sprintf('mixed $val = \%s::B', SimpleEnum::class),
6060
];
6161
}
@@ -95,23 +95,23 @@ public static function provideRenderParameterTypes(): iterable
9595
{
9696
$from = static fn(\Closure $closure): \ReflectionParameter => new \ReflectionParameter($closure, 0);
9797

98-
yield [$from(fn(string $string) => 0), 'string'];
99-
yield [$from(fn(string|int $string) => 0), 'string|int'];
100-
yield [$from(fn(mixed $string) => 0), 'mixed'];
101-
yield [$from(fn(int $string) => 0), 'int'];
102-
yield [$from(fn(float $string) => 0), 'float'];
103-
yield [$from(fn(?bool $string) => 0), '?bool'];
104-
yield [$from(fn(bool|null $string) => 0), '?bool'];
105-
yield [$from(fn(object $string) => 0), 'object'];
106-
yield [$from(fn(iterable $string) => 0), 'iterable'];
107-
yield [$from(fn(\Countable&\ArrayAccess $val) => 0), '\Countable&\ArrayAccess'];
108-
yield [$from(fn(string ...$val) => 0), 'string'];
109-
yield [$from(fn(string|int ...$val) => 0), 'string|int'];
110-
yield [$from(fn(string|int &$link) => 0), 'string|int'];
98+
yield [$from(static fn(string $string) => 0), 'string'];
99+
yield [$from(static fn(string|int $string) => 0), 'string|int'];
100+
yield [$from(static fn(mixed $string) => 0), 'mixed'];
101+
yield [$from(static fn(int $string) => 0), 'int'];
102+
yield [$from(static fn(float $string) => 0), 'float'];
103+
yield [$from(static fn(?bool $string) => 0), '?bool'];
104+
yield [$from(static fn(bool|null $string) => 0), '?bool'];
105+
yield [$from(static fn(object $string) => 0), 'object'];
106+
yield [$from(static fn(iterable $string) => 0), 'iterable'];
107+
yield [$from(static fn(\Countable&\ArrayAccess $val) => 0), '\Countable&\ArrayAccess'];
108+
yield [$from(static fn(string ...$val) => 0), 'string'];
109+
yield [$from(static fn(string|int ...$val) => 0), 'string|int'];
110+
yield [$from(static fn(string|int &$link) => 0), 'string|int'];
111111
yield [$from(self::withSelf(...)), '\\' . self::class];
112-
yield [$from(fn(object $link) => 0), 'object'];
113-
yield [$from(fn(#[Proxy] float|int|\stdClass|null $string) => 0), '\stdClass|int|float|null'];
114-
yield [$from(fn(SimpleEnum $val) => 0), '\\' . SimpleEnum::class];
112+
yield [$from(static fn(object $link) => 0), 'object'];
113+
yield [$from(static fn(#[Proxy] float|int|\stdClass|null $string) => 0), '\stdClass|int|float|null'];
114+
yield [$from(static fn(SimpleEnum $val) => 0), '\\' . SimpleEnum::class];
115115
}
116116

117117
public function testInterfaceWithConstructor(): void
@@ -144,12 +144,12 @@ public function testRenderParameter(\ReflectionParameter $param, $expected): voi
144144
}
145145

146146
/**
147-
* @dataProvider provideRenderMethod
148147
* @covers ::renderMethod
149148
* @covers ::renderParameter
150149
* @covers ::renderParameterTypes
151150
* @param mixed $expected
152151
*/
152+
#[DataProvider('provideRenderMethod')]
153153
public function testRenderMethod(\ReflectionMethod $param, $expected): void
154154
{
155155
$rendered = ProxyClassRenderer::renderMethod($param);

0 commit comments

Comments
 (0)