Skip to content

Commit

Permalink
PHPstan level 7
Browse files Browse the repository at this point in the history
  • Loading branch information
curry684 committed Oct 25, 2023
1 parent 528bbf3 commit 400b433
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 21 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
{
"name": "Robbert Beesems",
"email": "[email protected]",
"homepage": "https://omines.nl/"
"homepage": "https://www.omines.nl/"
},
{
"name": "Niels Keurentjes",
"email": "[email protected]",
"homepage": "https://omines.nl/"
"homepage": "https://www.omines.nl/"
}
],
"support": {
Expand Down
6 changes: 1 addition & 5 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
parameters:
level: 6
level: 7
paths:
- src
excludePaths:
# We're not really testing these 2 barely supported adapters
- src/Adapter/Elasticsearch
- src/Adapter/MongoDB

# Fixture is messy
- tests/Fixtures

checkGenericClassInNonGenericObjectType: false
2 changes: 1 addition & 1 deletion src/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ final public function getData(DataTableState $state): ResultSetInterface
}

/**
* @return array{AbstractColumn, string}[]
* @return array{AbstractColumn, ?string}[]
*/
protected function getPropertyMap(AdapterQuery $query): array
{
Expand Down
5 changes: 4 additions & 1 deletion src/Adapter/Doctrine/FetchJoinORMAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
* @author Jan Böhmer
*
* @phpstan-import-type ORMOptions from ORMAdapter
* @phpstan-type FetchJoinORMOptions array{simple_total_query: bool}
* @phpstan-type FetchJoinORMOptions ORMOptions&array{simple_total_query: bool}
*
* The above doesn't work yet in PHPstan, see tracker issue at https://github.com/phpstan/phpstan/issues/4703
*/
class FetchJoinORMAdapter extends ORMAdapter
{
Expand All @@ -55,6 +57,7 @@ protected function afterConfiguration(array $options): void
{
parent::afterConfiguration($options);

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

Expand Down
9 changes: 7 additions & 2 deletions src/Adapter/Doctrine/ORMAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ interface_exists(QueryBuilderProcessorInterface::class);
* @author Robbert Beesems <[email protected]>
*
* @phpstan-type HydrationMode AbstractQuery::HYDRATE_*
* @phpstan-type Processor QueryBuilderProcessorInterface|QueryBuilderProcessorInterface[]|callable
* @phpstan-type ORMOptions array{entity: class-string, hydrate: HydrationMode, query: Processor, criteria: Processor}
* @phpstan-type ORMOptions array{entity: class-string, hydrate: HydrationMode, query: QueryBuilderProcessorInterface[], criteria: QueryBuilderProcessorInterface[]}
*/
class ORMAdapter extends AbstractAdapter
{
Expand All @@ -73,10 +72,15 @@ public function __construct(ManagerRegistry $registry = null)
$this->registry = $registry;
}

/**
* @param array<string, mixed> $options
*/
public function configure(array $options): void
{
$resolver = new OptionsResolver();
$this->configureOptions($resolver);

/** @var ORMOptions $options */
$options = $resolver->resolve($options);

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

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

Expand Down
23 changes: 13 additions & 10 deletions src/DependencyInjection/Instantiator.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@
* The instantiator service handles lazy instantiation of services and/or ad hoc instantiation of objects.
*
* @author Niels Keurentjes <[email protected]>
*
* @phpstan-type SupportedTypes AdapterInterface|AbstractColumn|DataTableTypeInterface
*/
class Instantiator
{
/** @var ServiceLocator[] */
/** @var ServiceLocator<SupportedTypes>[] */
private array $locators;

/**
* Instantiator constructor.
*
* @param ServiceLocator[] $locators
* @param ServiceLocator<SupportedTypes>[] $locators
*/
public function __construct(array $locators = [])
{
Expand Down Expand Up @@ -61,15 +63,16 @@ public function getType(string $type): DataTableTypeInterface
private function getInstance(string $type, string $baseType)
{
if (isset($this->locators[$baseType]) && $this->locators[$baseType]->has($type)) {
return $this->locators[$baseType]->get($type);
} elseif (class_exists($type) && is_subclass_of($type, $baseType)) {
$instance = $this->locators[$baseType]->get($type);
} elseif (class_exists($type)) {
$instance = new $type();
if (!$instance instanceof $baseType) {
throw new InvalidArgumentException(sprintf('Class "%s" must implement/extend %s', $type, $baseType));
}

return $instance;
} else {
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));
}
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));
if (!$instance instanceof $baseType) {
throw new InvalidArgumentException(sprintf('Class "%s" must implement/extend %s', $type, $baseType));
}

return $instance;
}
}

0 comments on commit 400b433

Please sign in to comment.