Skip to content

Commit

Permalink
literal-string in QueryBuilder::where()
Browse files Browse the repository at this point in the history
* Start implementing literal-string checks with bleedingEdge

* Use array<mixed> for where() for now

* Use original stub whe not using bleedingEdge

* Preserve QueryBuilder methods from original stub

* Move stubs to a bleedingEdge sub-folder

* Add 'use function' for phpcs
  • Loading branch information
craigfrancis committed Feb 9, 2022
1 parent aefeca7 commit 5a5454c
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
8 changes: 7 additions & 1 deletion extension.neon
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ parameters:
- stubs/Collections/ArrayCollection.stub
- stubs/Collections/Collection.stub
- stubs/Collections/Selectable.stub
- stubs/ORM/QueryBuilder.stub
- stubs/ORM/AbstractQuery.stub
- stubs/ORM/Mapping/ClassMetadata.stub
- stubs/ORM/Mapping/ClassMetadataInfo.stub
Expand Down Expand Up @@ -151,6 +150,13 @@ services:
descendIntoOtherMethods: %doctrine.searchOtherMethodsForQueryBuilderBeginning%
parser: @defaultAnalysisParser

-
class: PHPStan\Stubs\Doctrine\StubFilesExtensionLoader
tags:
- phpstan.stubFilesExtension
arguments:
bleedingEdge: %featureToggles.bleedingEdge%

doctrineQueryBuilderArgumentsProcessor:
class: PHPStan\Type\Doctrine\ArgumentsProcessor
autowired: false
Expand Down
34 changes: 34 additions & 0 deletions src/Stubs/Doctrine/StubFilesExtensionLoader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php declare(strict_types = 1);

namespace PHPStan\Stubs\Doctrine;

use PHPStan\PhpDoc\StubFilesExtension;
use function dirname;

class StubFilesExtensionLoader implements StubFilesExtension
{

/** @var bool */
private $bleedingEdge;

public function __construct(
bool $bleedingEdge
)
{
$this->bleedingEdge = $bleedingEdge;
}

public function getFiles(): array
{
$path = dirname(dirname(dirname(__DIR__))) . '/stubs';

if ($this->bleedingEdge === true) {
$path .= '/bleedingEdge';
}

return [
$path . '/ORM/QueryBuilder.stub',
];
}

}
33 changes: 33 additions & 0 deletions stubs/bleedingEdge/ORM/QueryBuilder.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Doctrine\ORM;

class QueryBuilder
{

/**
* @return Query<mixed>
*/
public function getQuery()
{
}

/**
* @param \Doctrine\Common\Collections\ArrayCollection<array-key, mixed>|array<mixed> $parameters
* @return static
*/
public function setParameters($parameters)
{

}

/**
* @param literal-string|object|array<mixed> $predicates
* @return $this
*/
public function where($predicates)
{

}

}

0 comments on commit 5a5454c

Please sign in to comment.