Skip to content

Commit c998a52

Browse files
delyriandmaximehuran
authored andcommitted
fix: phpstan errors
1 parent 923c0a4 commit c998a52

9 files changed

+23
-11
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ test.composer: ## Validate composer.json
114114
${COMPOSER} validate --strict
115115

116116
test.phpstan: ## Run PHPStan
117-
${COMPOSER} phpstan || true
117+
${COMPOSER} phpstan
118118

119119
test.phpmd: ## Run PHPMD
120120
${COMPOSER} phpmd || true

phpstan.neon

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ parameters:
44
- %rootDir%/src/
55

66
checkMissingIterableValueType: false
7+
checkGenericClassInNonGenericObjectType: false
78

89
excludes_analyse:
910
# Makes PHPStan crash
@@ -12,6 +13,6 @@ parameters:
1213

1314
# Test dependencies
1415
- 'tests/Application/**/*'
15-
16+
1617
# Generated files
1718
- 'generated/**/*'

src/AutoMapper/ProductAttributeValueConfiguration.php

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public function process(MapperGeneratorMetadataInterface $metadata): void
5757
return null;
5858
}
5959
if (!\array_key_exists($productAttributeValue->getType(), $this->productAttributeValueReaders)) {
60+
// @phpstan-ignore-next-line The logger can't be null here
6061
$this->logger->alert(sprintf('Missing product attribute value reader for "%s" type', $productAttributeValue->getType()));
6162

6263
return null;

src/Controller/SearchController.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ public function searchAction(
7171
Request $request,
7272
string $query
7373
): Response {
74-
$documentable = $this->getDocumentable($request->query->get('document_type', null));
74+
$documentType = ((string) $request->query->get('document_type')) ?: null;
75+
$documentable = $this->getDocumentable($documentType);
7576
$requestConfiguration = new RequestConfiguration(
7677
$request,
7778
RequestInterface::SEARCH_TYPE,
@@ -171,6 +172,7 @@ private function getDocumentable(?string $documentType): DocumentableInterface
171172
}
172173

173174
try {
175+
/** @phpstan-ignore-next-line */
174176
return $this->documentableRegistry->get('search.documentable.' . $documentType);
175177
} catch (NonExistingServiceException $exception) {
176178
throw new NotFoundHttpException(sprintf('Documentable "%s" not found', $documentType));

src/Fixture/SearchableFixture.php

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public function getName(): string
4343
*/
4444
protected function configureResourceNode(ArrayNodeDefinition $resourceNode): void
4545
{
46+
/** @phpstan-ignore-next-line */
4647
$resourceNode
4748
->children()
4849
->scalarNode('attribute')->end()

src/Model/Datasource/ProductDatasource.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace MonsieurBiz\SyliusSearchPlugin\Model\Datasource;
1515

1616
use Doctrine\ORM\EntityManagerInterface;
17+
use Doctrine\ORM\EntityRepository;
1718
use Pagerfanta\Doctrine\ORM\QueryAdapter;
1819
use Pagerfanta\Pagerfanta;
1920
use Sylius\Component\Core\Repository\ProductRepositoryInterface;
@@ -30,8 +31,9 @@ public function __construct(EntityManagerInterface $entityManager)
3031

3132
public function getItems(string $sourceClass): iterable
3233
{
34+
/** @phpstan-ignore-next-line */
3335
$repository = $this->entityManager->getRepository($sourceClass);
34-
/** @var ProductRepositoryInterface $repository */
36+
/** @var ProductRepositoryInterface&EntityRepository $repository */
3537
Assert::isInstanceOf($repository, ProductRepositoryInterface::class);
3638

3739
$queryBuilder = $repository->createQueryBuilder('o')

src/Search/Request/InstantSearch.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function getType(): string
5858

5959
public function getDocumentable(): DocumentableInterface
6060
{
61-
/** @var DocumentableInterface $documentable */
61+
/** @phpstan-ignore-next-line */
6262
return $this->documentableRegistry->get('search.documentable.' . $this->documentType);
6363
}
6464

src/Search/Request/Search.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function getType(): string
7777

7878
public function getDocumentable(): DocumentableInterface
7979
{
80-
/** @var DocumentableInterface $documentable */
80+
/** @phpstan-ignore-next-line */
8181
return $this->documentableRegistry->get('search.documentable.' . $this->documentType);
8282
}
8383

src/Search/Request/Taxon.php

+10-5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use MonsieurBiz\SyliusSearchPlugin\Search\Request\PostFilter\PostFilterInterface;
2121
use MonsieurBiz\SyliusSearchPlugin\Search\Request\QueryFilter\QueryFilterInterface;
2222
use MonsieurBiz\SyliusSearchPlugin\Search\Request\Sorting\SorterInterface;
23+
use RuntimeException;
2324
use Sylius\Component\Channel\Context\ChannelContextInterface;
2425
use Sylius\Component\Registry\ServiceRegistryInterface;
2526

@@ -82,30 +83,34 @@ public function getType(): string
8283

8384
public function getDocumentable(): DocumentableInterface
8485
{
85-
/** @var DocumentableInterface $documentable */
86+
/** @phpstan-ignore-next-line */
8687
return $this->documentableRegistry->get('search.documentable.' . $this->documentType);
8788
}
8889

8990
public function getQuery(): Query
9091
{
92+
if (!($configuration = $this->configuration)) {
93+
throw new RuntimeException('Configuration is not set');
94+
}
95+
9196
$qb = new QueryBuilder();
9297

9398
$boolQuery = $qb->query()->bool();
9499
foreach ($this->queryFilters as $queryFilter) {
95-
$queryFilter->apply($boolQuery, $this->configuration);
100+
$queryFilter->apply($boolQuery, $configuration);
96101
}
97102

98103
$query = Query::create($boolQuery);
99104
$postFilter = new Query\BoolQuery();
100105
foreach ($this->postFilters as $postFilterApplier) {
101-
$postFilterApplier->apply($postFilter, $this->configuration);
106+
$postFilterApplier->apply($postFilter, $configuration);
102107
}
103108
$query->setPostFilter($postFilter);
104109

105110
$this->addAggregations($query, $postFilter);
106111

107112
foreach ($this->sorters as $sorter) {
108-
$sorter->apply($query, $this->configuration);
113+
$sorter->apply($query, $configuration);
109114
}
110115

111116
/** @var Query\AbstractQuery $queryObject */
@@ -116,7 +121,7 @@ public function getQuery(): Query
116121
->setScoreMode(Query\FunctionScore::SCORE_MODE_MULTIPLY)
117122
;
118123
foreach ($this->functionScores as $functionScoreClass) {
119-
$functionScoreClass->addFunctionScore($functionScore, $this->configuration);
124+
$functionScoreClass->addFunctionScore($functionScore, $configuration);
120125
}
121126

122127
$query->setQuery($functionScore);

0 commit comments

Comments
 (0)