Skip to content

Commit 6a58685

Browse files
committed
Update to PHP 8.1+
1 parent 141d0d6 commit 6a58685

21 files changed

+248
-261
lines changed

.editorconfig

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_size = 4
7+
indent_style = space
8+
insert_final_newline = false
9+
max_line_length = 120
10+
tab_width = 4

.github/workflows/test.yml

+3-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111

1212
steps:
13-
- uses: actions/checkout@v2
13+
- uses: actions/checkout@v3
1414

1515
- uses: shivammathur/setup-php@v2
1616
with:
@@ -32,7 +32,7 @@ jobs:
3232
composer-flags: ['']
3333

3434
steps:
35-
- uses: actions/checkout@v2
35+
- uses: actions/checkout@v3
3636
with:
3737
fetch-depth: 0
3838

@@ -45,10 +45,6 @@ jobs:
4545

4646
- run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
4747

48-
- name: "Use PHPUnit 9.3+ on PHP 8"
49-
run: composer require --no-update --dev phpunit/phpunit:^9.3
50-
if: "matrix.php == '8.0'"
51-
5248
- run: composer update --no-progress ${{ matrix.composer-flags }}
5349

5450
- run: vendor/bin/phpunit --no-coverage
@@ -65,7 +61,7 @@ jobs:
6561
runs-on: ubuntu-latest
6662

6763
steps:
68-
- uses: actions/checkout@v2
64+
- uses: actions/checkout@v3
6965

7066
- uses: shivammathur/setup-php@v2
7167
with:

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ composer.phar
44
vendor
55
.sass-cache
66
.phpunit.result.cache
7+
.phpunit.cache
78
.phpcs-cache
89
docs/.jekyll-cache
910
docs/_site

phpstan.neon

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
parameters:
22
level: 5
3+
treatPhpDocTypesAsCertain: false
34
paths:
45
- src

phpunit.xml

+14-20
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,23 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit bootstrap="vendor/autoload.php"
3-
backupGlobals="false"
4-
backupStaticAttributes="false"
5-
colors="true"
6-
verbose="true"
7-
convertErrorsToExceptions="true"
8-
convertNoticesToExceptions="true"
9-
convertWarningsToExceptions="true"
10-
processIsolation="false"
11-
stopOnFailure="false">
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
3+
<coverage>
4+
<report>
5+
<clover outputFile="build/logs/clover.xml"/>
6+
<html outputDirectory="build/coverage"/>
7+
<text outputFile="build/coverage.txt"/>
8+
</report>
9+
</coverage>
1210
<testsuites>
1311
<testsuite name="League Test Suite">
1412
<directory>tests</directory>
1513
</testsuite>
1614
</testsuites>
17-
<filter>
18-
<whitelist>
19-
<directory suffix=".php">src/</directory>
20-
</whitelist>
21-
</filter>
2215
<logging>
23-
<log type="tap" target="build/report.tap"/>
24-
<log type="junit" target="build/report.junit.xml"/>
25-
<log type="coverage-html" target="build/coverage"/>
26-
<log type="coverage-text" target="build/coverage.txt"/>
27-
<log type="coverage-clover" target="build/logs/clover.xml"/>
16+
<junit outputFile="build/report.junit.xml"/>
2817
</logging>
18+
<source>
19+
<include>
20+
<directory suffix=".php">src/</directory>
21+
</include>
22+
</source>
2923
</phpunit>

src/Argument/LiteralArgument.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88

99
class LiteralArgument implements LiteralArgumentInterface
1010
{
11-
public const TYPE_ARRAY = 'array';
12-
public const TYPE_BOOL = 'boolean';
13-
public const TYPE_BOOLEAN = 'boolean';
11+
public const TYPE_ARRAY = 'array';
12+
public const TYPE_BOOL = 'boolean';
13+
public const TYPE_BOOLEAN = 'boolean';
1414
public const TYPE_CALLABLE = 'callable';
15-
public const TYPE_DOUBLE = 'double';
16-
public const TYPE_FLOAT = 'double';
17-
public const TYPE_INT = 'integer';
18-
public const TYPE_INTEGER = 'integer';
19-
public const TYPE_OBJECT = 'object';
20-
public const TYPE_STRING = 'string';
15+
public const TYPE_DOUBLE = 'double';
16+
public const TYPE_FLOAT = 'double';
17+
public const TYPE_INT = 'integer';
18+
public const TYPE_INTEGER = 'integer';
19+
public const TYPE_OBJECT = 'object';
20+
public const TYPE_STRING = 'string';
2121

2222
/**
2323
* @var mixed

src/Container.php

+5-19
Original file line numberDiff line numberDiff line change
@@ -106,31 +106,17 @@ public function addServiceProvider(ServiceProviderInterface $provider): Definiti
106106
return $this;
107107
}
108108

109-
/**
110-
* @template RequestedType
111-
*
112-
* @param class-string<RequestedType>|string $id
113-
*
114-
* @return RequestedType|mixed
115-
*/
116-
public function get($id)
109+
public function get(string $id)
117110
{
118111
return $this->resolve($id);
119112
}
120113

121-
/**
122-
* @template RequestedType
123-
*
124-
* @param class-string<RequestedType>|string $id
125-
*
126-
* @return RequestedType|mixed
127-
*/
128-
public function getNew($id)
114+
public function getNew(string $id): mixed
129115
{
130116
return $this->resolve($id, true);
131117
}
132118

133-
public function has($id): bool
119+
public function has(string $id): bool
134120
{
135121
if ($this->definitions->has($id)) {
136122
return true;
@@ -169,7 +155,7 @@ public function delegate(ContainerInterface $container): self
169155
return $this;
170156
}
171157

172-
protected function resolve($id, bool $new = false)
158+
protected function resolve(string $id, bool $new = false)
173159
{
174160
if ($this->definitions->has($id)) {
175161
$resolved = (true === $new) ? $this->definitions->resolveNew($id) : $this->definitions->resolve($id);
@@ -191,7 +177,7 @@ protected function resolve($id, bool $new = false)
191177
if ($this->providers->provides($id)) {
192178
$this->providers->register($id);
193179

194-
if (!$this->definitions->has($id) && !$this->definitions->hasTag($id)) {
180+
if (false === $this->definitions->has($id) && false === $this->definitions->hasTag($id)) {
195181
throw new ContainerException(sprintf('Service provider lied about providing (%s) service', $id));
196182
}
197183

src/Definition/Definition.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,10 @@ class Definition implements ArgumentResolverInterface, DefinitionInterface
5555
*/
5656
protected $resolved;
5757

58-
/**
59-
* @param string $id
60-
* @param mixed|null $concrete
61-
*/
62-
public function __construct(string $id, $concrete = null)
58+
public function __construct(string $id, mixed $concrete = null)
6359
{
6460
$concrete ??= $id;
65-
$this->alias = $id;
61+
$this->alias = $id;
6662
$this->concrete = $concrete;
6763
}
6864

src/Definition/DefinitionAggregate.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class DefinitionAggregate implements DefinitionAggregateInterface
1515
/**
1616
* @var DefinitionInterface[]
1717
*/
18-
protected $definitions = [];
18+
protected array $definitions = [];
1919

2020
public function __construct(array $definitions = [])
2121
{

src/DefinitionContainerInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ public function add(string $id, $concrete = null): DefinitionInterface;
1515
public function addServiceProvider(ServiceProviderInterface $provider): self;
1616
public function addShared(string $id, $concrete = null): DefinitionInterface;
1717
public function extend(string $id): DefinitionInterface;
18-
public function getNew($id);
18+
public function getNew(string $id): mixed;
1919
public function inflector(string $type, callable $callback = null): InflectorInterface;
2020
}

src/ServiceProvider/AbstractServiceProvider.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ abstract class AbstractServiceProvider implements ServiceProviderInterface
1313
/**
1414
* @var string
1515
*/
16-
protected $identifier;
16+
protected string $identifier;
1717

1818
public function getIdentifier(): string
1919
{
20-
return $this->identifier ?? get_class($this);
20+
if (empty($this->identifier)) {
21+
$this->identifier = get_class($this);
22+
}
23+
24+
return $this->identifier;
2125
}
2226

2327
public function setIdentifier(string $id): ServiceProviderInterface

tests/Argument/ArgumentResolverTest.php

+32-33
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,23 @@ public function testResolverResolvesFromContainer(): void
2525

2626
$container = $this->getMockBuilder(Container::class)->getMock();
2727

28+
$matcher = $this->exactly(2);
29+
2830
$container
29-
->expects(self::at(0))
31+
->expects($matcher)
3032
->method('has')
31-
->with(self::equalTo('alias1'))
32-
->willReturn(true)
33+
->willReturnOnConsecutiveCalls(true, false)
3334
;
3435

35-
$container->expects(self::at(1))->method('get')->with(self::equalTo('alias1'))->willReturn($resolver);
36-
$container->expects(self::at(2))->method('has')->with(self::equalTo('alias2'))->willReturn(false);
36+
$container->expects($this->once())->method('get')->with($this->equalTo('alias1'))->willReturn($resolver);
3737

3838
/** @var Container $container */
3939
$resolver->setContainer($container);
4040

4141
$args = $resolver->resolveArguments(['alias1', 'alias2']);
4242

43-
self::assertSame($resolver, $args[0]);
44-
self::assertSame('alias2', $args[1]);
43+
$this->assertSame($resolver, $args[0]);
44+
$this->assertSame('alias2', $args[1]);
4545
}
4646

4747
public function testResolverResolvesLiteralArguments(): void
@@ -54,16 +54,15 @@ public function testResolverResolvesLiteralArguments(): void
5454
$container = $this->getMockBuilder(Container::class)->getMock();
5555

5656
$container
57-
->expects(self::at(0))
57+
->expects($this->once())
5858
->method('has')
59-
->with(self::equalTo('alias1'))
60-
->willReturn(true)
59+
->willReturnOnConsecutiveCalls(true, false)
6160
;
6261

6362
$container
64-
->expects(self::at(1))
63+
->expects($this->once())
6564
->method('get')
66-
->with(self::equalTo('alias1'))
65+
->with($this->equalTo('alias1'))
6766
->willReturn(new Literal\StringArgument('value1'))
6867
;
6968

@@ -72,8 +71,8 @@ public function testResolverResolvesLiteralArguments(): void
7271

7372
$args = $resolver->resolveArguments(['alias1', new Literal\StringArgument('value2')]);
7473

75-
self::assertSame('value1', $args[0]);
76-
self::assertSame('value2', $args[1]);
74+
$this->assertSame('value1', $args[0]);
75+
$this->assertSame('value2', $args[1]);
7776
}
7877

7978
public function testResolverResolvesArgumentsViaReflection(): void
@@ -85,21 +84,21 @@ public function testResolverResolvesArgumentsViaReflection(): void
8584
$class = $this->getMockBuilder(ReflectionNamedType::class)->disableOriginalConstructor()->getMock();
8685
$container = $this->getMockBuilder(Container::class)->getMock();
8786

88-
$class->expects(self::once())->method('getName')->willReturn('Class');
89-
$param1->expects(self::once())->method('getName')->willReturn('param1');
90-
$param1->expects(self::once())->method('getType')->willReturn($class);
87+
$class->expects($this->once())->method('getName')->willReturn('Class');
88+
$param1->expects($this->once())->method('getName')->willReturn('param1');
89+
$param1->expects($this->once())->method('getType')->willReturn($class);
9190

92-
$param2->expects(self::once())->method('getName')->willReturn('param2');
93-
$param2->expects(self::once())->method('getType')->willReturn(null);
94-
$param2->expects(self::once())->method('isDefaultValueAvailable')->willReturn(true);
95-
$param2->expects(self::once())->method('getDefaultValue')->willReturn('value2');
91+
$param2->expects($this->once())->method('getName')->willReturn('param2');
92+
$param2->expects($this->once())->method('getType')->willReturn(null);
93+
$param2->expects($this->once())->method('isDefaultValueAvailable')->willReturn(true);
94+
$param2->expects($this->once())->method('getDefaultValue')->willReturn('value2');
9695

97-
$param3->expects(self::once())->method('getName')->willReturn('param3');
96+
$param3->expects($this->once())->method('getName')->willReturn('param3');
9897

99-
$method->expects(self::once())->method('getParameters')->willReturn([$param1, $param2, $param3]);
98+
$method->expects($this->once())->method('getParameters')->willReturn([$param1, $param2, $param3]);
10099

101-
$container->expects(self::once())->method('has')->with($this->equalTo('Class'))->willReturn(true);
102-
$container->expects(self::once())->method('get')->with($this->equalTo('Class'))->willReturn('classObject');
100+
$container->expects($this->once())->method('has')->with($this->equalTo('Class'))->willReturn(true);
101+
$container->expects($this->once())->method('get')->with($this->equalTo('Class'))->willReturn('classObject');
103102

104103
$resolver = new class implements ArgumentResolverInterface {
105104
use ArgumentResolverTrait;
@@ -111,9 +110,9 @@ public function testResolverResolvesArgumentsViaReflection(): void
111110

112111
$args = $resolver->reflectArguments($method, ['param3' => 'value3']);
113112

114-
self::assertSame('classObject', $args[0]);
115-
self::assertSame('value2', $args[1]);
116-
self::assertSame('value3', $args[2]);
113+
$this->assertSame('classObject', $args[0]);
114+
$this->assertSame('value2', $args[1]);
115+
$this->assertSame('value3', $args[2]);
117116
}
118117

119118
public function testResolvesDefaultValueArgument(): void
@@ -124,7 +123,7 @@ public function testResolvesDefaultValueArgument(): void
124123
};
125124

126125
$result = $resolver->reflectArguments((new ReflectionClass(Baz::class))->getConstructor());
127-
self::assertSame([null], $result);
126+
$this->assertSame([null], $result);
128127
}
129128

130129
public function testResolverThrowsExceptionWhenReflectionDoesNotResolve(): void
@@ -134,11 +133,11 @@ public function testResolverThrowsExceptionWhenReflectionDoesNotResolve(): void
134133
$method = $this->getMockBuilder(ReflectionFunctionAbstract::class)->getMock();
135134
$param = $this->getMockBuilder(ReflectionParameter::class)->disableOriginalConstructor()->getMock();
136135

137-
$param->expects(self::once())->method('getName')->willReturn('param1');
138-
$param->expects(self::once())->method('getType')->willReturn(null);
139-
$param->expects(self::once())->method('isDefaultValueAvailable')->willReturn(false);
136+
$param->expects($this->once())->method('getName')->willReturn('param1');
137+
$param->expects($this->once())->method('getType')->willReturn(null);
138+
$param->expects($this->once())->method('isDefaultValueAvailable')->willReturn(false);
140139

141-
$method->expects(self::once())->method('getParameters')->willReturn([$param]);
140+
$method->expects($this->once())->method('getParameters')->willReturn([$param]);
142141

143142
$resolver = new class implements ArgumentResolverInterface {
144143
use ArgumentResolverTrait;

tests/Argument/TypedArgumentTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function testLiteralArgumentSetsAndGetsArgument(): void
2727

2828
foreach ($arguments as $type => $expected) {
2929
$argument = new $type($expected);
30-
self::assertSame($expected, $argument->getValue());
30+
$this->assertSame($expected, $argument->getValue());
3131
}
3232
}
3333

0 commit comments

Comments
 (0)