Skip to content

Commit 400b433

Browse files
committed
PHPstan level 7
1 parent 528bbf3 commit 400b433

File tree

6 files changed

+28
-21
lines changed

6 files changed

+28
-21
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
{
99
"name": "Robbert Beesems",
1010
"email": "[email protected]",
11-
"homepage": "https://omines.nl/"
11+
"homepage": "https://www.omines.nl/"
1212
},
1313
{
1414
"name": "Niels Keurentjes",
1515
"email": "[email protected]",
16-
"homepage": "https://omines.nl/"
16+
"homepage": "https://www.omines.nl/"
1717
}
1818
],
1919
"support": {

phpstan.neon

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
parameters:
2-
level: 6
2+
level: 7
33
paths:
44
- src
55
excludePaths:
66
# We're not really testing these 2 barely supported adapters
77
- src/Adapter/Elasticsearch
88
- src/Adapter/MongoDB
99

10-
# Fixture is messy
11-
- tests/Fixtures
12-
13-
checkGenericClassInNonGenericObjectType: false

src/Adapter/AbstractAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ final public function getData(DataTableState $state): ResultSetInterface
6262
}
6363

6464
/**
65-
* @return array{AbstractColumn, string}[]
65+
* @return array{AbstractColumn, ?string}[]
6666
*/
6767
protected function getPropertyMap(AdapterQuery $query): array
6868
{

src/Adapter/Doctrine/FetchJoinORMAdapter.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
* @author Jan Böhmer
2929
*
3030
* @phpstan-import-type ORMOptions from ORMAdapter
31-
* @phpstan-type FetchJoinORMOptions array{simple_total_query: bool}
31+
* @phpstan-type FetchJoinORMOptions ORMOptions&array{simple_total_query: bool}
32+
*
33+
* The above doesn't work yet in PHPstan, see tracker issue at https://github.com/phpstan/phpstan/issues/4703
3234
*/
3335
class FetchJoinORMAdapter extends ORMAdapter
3436
{
@@ -55,6 +57,7 @@ protected function afterConfiguration(array $options): void
5557
{
5658
parent::afterConfiguration($options);
5759

60+
/* @phpstan-ignore-next-line See comment at top of class */
5861
$this->useSimpleTotal = $options['simple_total_query'];
5962
}
6063

src/Adapter/Doctrine/ORMAdapter.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ interface_exists(QueryBuilderProcessorInterface::class);
4545
* @author Robbert Beesems <[email protected]>
4646
*
4747
* @phpstan-type HydrationMode AbstractQuery::HYDRATE_*
48-
* @phpstan-type Processor QueryBuilderProcessorInterface|QueryBuilderProcessorInterface[]|callable
49-
* @phpstan-type ORMOptions array{entity: class-string, hydrate: HydrationMode, query: Processor, criteria: Processor}
48+
* @phpstan-type ORMOptions array{entity: class-string, hydrate: HydrationMode, query: QueryBuilderProcessorInterface[], criteria: QueryBuilderProcessorInterface[]}
5049
*/
5150
class ORMAdapter extends AbstractAdapter
5251
{
@@ -73,10 +72,15 @@ public function __construct(ManagerRegistry $registry = null)
7372
$this->registry = $registry;
7473
}
7574

75+
/**
76+
* @param array<string, mixed> $options
77+
*/
7678
public function configure(array $options): void
7779
{
7880
$resolver = new OptionsResolver();
7981
$this->configureOptions($resolver);
82+
83+
/** @var ORMOptions $options */
8084
$options = $resolver->resolve($options);
8185

8286
$this->afterConfiguration($options);
@@ -126,6 +130,7 @@ protected function getAliases(AdapterQuery $query): array
126130

127131
/** @var Query\Expr\From $from */
128132
foreach ($builder->getDQLPart('from') as $from) {
133+
/* @phpstan-ignore-next-line */
129134
$aliases[$from->getAlias()] = [null, $this->manager->getMetadataFactory()->getMetadataFor($from->getFrom())];
130135
}
131136

src/DependencyInjection/Instantiator.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,18 @@
2222
* The instantiator service handles lazy instantiation of services and/or ad hoc instantiation of objects.
2323
*
2424
* @author Niels Keurentjes <[email protected]>
25+
*
26+
* @phpstan-type SupportedTypes AdapterInterface|AbstractColumn|DataTableTypeInterface
2527
*/
2628
class Instantiator
2729
{
28-
/** @var ServiceLocator[] */
30+
/** @var ServiceLocator<SupportedTypes>[] */
2931
private array $locators;
3032

3133
/**
3234
* Instantiator constructor.
3335
*
34-
* @param ServiceLocator[] $locators
36+
* @param ServiceLocator<SupportedTypes>[] $locators
3537
*/
3638
public function __construct(array $locators = [])
3739
{
@@ -61,15 +63,16 @@ public function getType(string $type): DataTableTypeInterface
6163
private function getInstance(string $type, string $baseType)
6264
{
6365
if (isset($this->locators[$baseType]) && $this->locators[$baseType]->has($type)) {
64-
return $this->locators[$baseType]->get($type);
65-
} elseif (class_exists($type) && is_subclass_of($type, $baseType)) {
66+
$instance = $this->locators[$baseType]->get($type);
67+
} elseif (class_exists($type)) {
6668
$instance = new $type();
67-
if (!$instance instanceof $baseType) {
68-
throw new InvalidArgumentException(sprintf('Class "%s" must implement/extend %s', $type, $baseType));
69-
}
70-
71-
return $instance;
69+
} else {
70+
throw new InvalidArgumentException(sprintf('Could not resolve type "%s" to a service or class, are you missing a use statement? Or is it implemented but does it not correctly derive from "%s"?', $type, $baseType));
7271
}
73-
throw new InvalidArgumentException(sprintf('Could not resolve type "%s" to a service or class, are you missing a use statement? Or is it implemented but does it not correctly derive from "%s"?', $type, $baseType));
72+
if (!$instance instanceof $baseType) {
73+
throw new InvalidArgumentException(sprintf('Class "%s" must implement/extend %s', $type, $baseType));
74+
}
75+
76+
return $instance;
7477
}
7578
}

0 commit comments

Comments
 (0)