Skip to content

Commit fbb04ad

Browse files
committed
Begin level 6 typing
1 parent 2f55648 commit fbb04ad

37 files changed

+286
-216
lines changed

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
"composer/composer": "^1.2",
3636
"squizlabs/php_codesniffer": "^3.4",
3737
"symfony/phpunit-bridge": "^5.1",
38-
"phpstan/phpstan": "^0.12.50"
38+
"phpstan/phpstan": "^0.12.50",
39+
"timeweb/phpstan-enum": "^2.2"
3940
},
4041
"autoload" : {
4142
"psr-4" : {
@@ -56,6 +57,6 @@
5657
"phpcs src --standard=PSR12 --encoding=UTF-8",
5758
"phpcs test --standard=PSR12 --encoding=UTF-8"
5859
],
59-
"static": "phpstan --ansi analyse --level 5 src"
60+
"static": "phpstan --ansi analyse --level 6 src"
6061
}
6162
}

composer.lock

Lines changed: 47 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpstan.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
parameters:
22
treatPhpDocTypesAsCertain: false
3+

src/ExerciseRepository.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
/**
1212
* Exercise repository, use to locate individual/all exercises by certain criteria.
13+
*
14+
* @implements IteratorAggregate<int, ExerciseInterface>
1315
*/
1416
class ExerciseRepository implements IteratorAggregate, Countable
1517
{
@@ -21,7 +23,7 @@ class ExerciseRepository implements IteratorAggregate, Countable
2123
/**
2224
* Requires an array of `ExerciseInterface` instances.
2325
*
24-
* @param ExerciseInterface[] $exercises
26+
* @param array<ExerciseInterface> $exercises
2527
*/
2628
public function __construct(array $exercises)
2729
{
@@ -34,7 +36,7 @@ public function __construct(array $exercises)
3436
* @param ExerciseInterface $exercise
3537
* @return ExerciseInterface
3638
*/
37-
private function validateExercise(ExerciseInterface $exercise)
39+
private function validateExercise(ExerciseInterface $exercise): ExerciseInterface
3840
{
3941
$type = $exercise->getType();
4042

@@ -50,9 +52,9 @@ private function validateExercise(ExerciseInterface $exercise)
5052
/**
5153
* Retrieve all of the exercises as an array.
5254
*
53-
* @return ExerciseInterface[]
55+
* @return array<ExerciseInterface>
5456
*/
55-
public function findAll()
57+
public function findAll(): array
5658
{
5759
return $this->exercises;
5860
}
@@ -65,7 +67,7 @@ public function findAll()
6567
* @return ExerciseInterface
6668
* @throws InvalidArgumentException
6769
*/
68-
public function findByName($name)
70+
public function findByName(string $name): ExerciseInterface
6971
{
7072
foreach ($this->exercises as $exercise) {
7173
if ($name === $exercise->getName()) {
@@ -79,9 +81,9 @@ public function findByName($name)
7981
/**
8082
* Get the names of each exercise as an array.
8183
*
82-
* @return array
84+
* @return array<string>
8385
*/
84-
public function getAllNames()
86+
public function getAllNames(): array
8587
{
8688
return array_map(function (ExerciseInterface $exercise) {
8789
return $exercise->getName();
@@ -93,17 +95,17 @@ public function getAllNames()
9395
*
9496
* @return int
9597
*/
96-
public function count()
98+
public function count(): int
9799
{
98100
return count($this->exercises);
99101
}
100102

101103
/**
102104
* Allow to iterate over the repository with `foreach`.
103105
*
104-
* @return ArrayIterator
106+
* @return ArrayIterator<int, ExerciseInterface>
105107
*/
106-
public function getIterator()
108+
public function getIterator(): ArrayIterator
107109
{
108110
return new ArrayIterator($this->exercises);
109111
}

src/Factory/EventDispatcherFactory.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class EventDispatcherFactory
1919
* @return EventDispatcher
2020
* @throws InvalidArgumentException
2121
*/
22-
public function __invoke(ContainerInterface $container)
22+
public function __invoke(ContainerInterface $container): EventDispatcher
2323
{
2424
$dispatcher = new EventDispatcher($container->get(ResultAggregator::class));
2525

@@ -46,10 +46,10 @@ public function __invoke(ContainerInterface $container)
4646
}
4747

4848
/**
49-
* @param array $listeners
50-
* @return array
49+
* @param array<int, array<string, array>> $listeners
50+
* @return array<int, array>
5151
*/
52-
private function mergeListenerGroups(array $listeners)
52+
private function mergeListenerGroups(array $listeners): array
5353
{
5454
$listeners = new Collection($listeners);
5555

@@ -78,17 +78,17 @@ private function mergeListenerGroups(array $listeners)
7878

7979
/**
8080
* @param string $eventName
81-
* @param array $listeners
81+
* @param array<int, ContainerListenerHelper|callable> $listeners
8282
* @param ContainerInterface $container
8383
* @param EventDispatcher $dispatcher
84-
* @throws \PhpSchool\PhpWorkshop\Exception\InvalidArgumentException
84+
* @throws InvalidArgumentException
8585
*/
8686
private function attachListeners(
87-
$eventName,
87+
string $eventName,
8888
array $listeners,
8989
ContainerInterface $container,
9090
EventDispatcher $dispatcher
91-
) {
91+
): void {
9292
array_walk($listeners, function ($listener) use ($eventName, $dispatcher, $container) {
9393
if ($listener instanceof ContainerListenerHelper) {
9494
if (!$container->has($listener->getService())) {
@@ -117,7 +117,6 @@ private function attachListeners(
117117
);
118118
}
119119
$dispatcher->listen($eventName, $listener);
120-
return;
121120
});
122121
}
123122
}

src/Factory/MenuFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ private function isExerciseDisabled(ExerciseInterface $exercise, UserState $user
142142
* @param EventDispatcher $eventDispatcher
143143
* @param ExerciseInterface $exercise
144144
*/
145-
private function dispatchExerciseSelectedEvent(EventDispatcher $eventDispatcher, ExerciseInterface $exercise)
145+
private function dispatchExerciseSelectedEvent(EventDispatcher $eventDispatcher, ExerciseInterface $exercise): void
146146
{
147147
$eventDispatcher->dispatch(
148148
new Event(

src/Factory/ResultRendererFactory.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@
1212
class ResultRendererFactory
1313
{
1414
/**
15-
* @var array
15+
* @var array<class-string, class-string>
1616
*/
1717
private $mappings = [];
1818

1919
/**
20-
* @var array
20+
* @var array<class-string, callable>
2121
*/
2222
private $factories = [];
2323

2424
/**
25-
* @param string $resultClass
26-
* @param string $rendererClass
27-
* @param callable $factory
25+
* @param class-string $resultClass
26+
* @param class-string $rendererClass
27+
* @param callable|null $factory
2828
*/
29-
public function registerRenderer($resultClass, $rendererClass, callable $factory = null)
29+
public function registerRenderer(string $resultClass, string $rendererClass, callable $factory = null): void
3030
{
3131
if (!$this->isImplementationNameOfClass($resultClass, ResultInterface::class)) {
3232
throw new InvalidArgumentException();
@@ -47,7 +47,7 @@ public function registerRenderer($resultClass, $rendererClass, callable $factory
4747
* @param ResultInterface $result
4848
* @return ResultRendererInterface
4949
*/
50-
public function create(ResultInterface $result)
50+
public function create(ResultInterface $result): ResultRendererInterface
5151
{
5252
$class = get_class($result);
5353
if (!isset($this->mappings[$class])) {
@@ -73,7 +73,12 @@ public function create(ResultInterface $result)
7373
return $renderer;
7474
}
7575

76-
protected function isImplementationNameOfClass($implementationName, $className)
76+
/**
77+
* @param class-string $implementationName
78+
* @param class-string $className
79+
* @return bool
80+
*/
81+
protected function isImplementationNameOfClass(string $implementationName, string $className): bool
7782
{
7883
return is_string($implementationName) && is_subclass_of($implementationName, $className);
7984
}

src/Input/Input.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ class Input
1616
private $appName;
1717

1818
/**
19-
* @var array
19+
* @var array<string>
2020
*/
2121
private $arguments = [];
2222

2323
/**
2424
* @param string $appName
25-
* @param array $arguments
25+
* @param array<string> $arguments
2626
*/
27-
public function __construct($appName, array $arguments = [])
27+
public function __construct(string $appName, array $arguments = [])
2828
{
2929
$this->appName = $appName;
3030
$this->arguments = $arguments;
@@ -33,7 +33,7 @@ public function __construct($appName, array $arguments = [])
3333
/**
3434
* @return string
3535
*/
36-
public function getAppName()
36+
public function getAppName(): string
3737
{
3838
return $this->appName;
3939
}
@@ -42,7 +42,7 @@ public function getAppName()
4242
* @param string $name
4343
* @return bool
4444
*/
45-
public function hasArgument($name)
45+
public function hasArgument($name): bool
4646
{
4747
return isset($this->arguments[$name]);
4848
}
@@ -52,7 +52,7 @@ public function hasArgument($name)
5252
* @return string
5353
* @throws InvalidArgumentException
5454
*/
55-
public function getArgument($name)
55+
public function getArgument(string $name): string
5656
{
5757
if (!$this->hasArgument($name)) {
5858
throw new InvalidArgumentException(sprintf('Argument with name: "%s" does not exist', $name));
@@ -65,7 +65,7 @@ public function getArgument($name)
6565
* @param string $name
6666
* @param string $value
6767
*/
68-
public function setArgument($name, $value)
68+
public function setArgument(string $name, string $value): void
6969
{
7070
$this->arguments[$name] = $value;
7171
}

src/Listener/CheckExerciseAssignedListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function __construct(UserState $userState)
2424
/**
2525
* @param Event $event
2626
*/
27-
public function __invoke(Event $event)
27+
public function __invoke(Event $event): void
2828
{
2929
/** @var CommandDefinition $command */
3030
$command = $event->getParameter('command');

src/Listener/CodePatchListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct(CodePatcher $codePatcher)
3434
/**
3535
* @param ExerciseRunnerEvent $event
3636
*/
37-
public function patch(ExerciseRunnerEvent $event)
37+
public function patch(ExerciseRunnerEvent $event): void
3838
{
3939
$fileName = $event->getInput()->getArgument('program');
4040

@@ -48,7 +48,7 @@ public function patch(ExerciseRunnerEvent $event)
4848
/**
4949
* @param ExerciseRunnerEvent $event
5050
*/
51-
public function revert(ExerciseRunnerEvent $event)
51+
public function revert(ExerciseRunnerEvent $event): void
5252
{
5353
if (null === $this->originalCode) {
5454
throw new RuntimeException('Can only revert previously patched code');

0 commit comments

Comments
 (0)