otobank / phpstan-doctrine-criteria
Doctrine Criteria extensions for PHPStan
Installs: 37 926
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 14
Forks: 1
Open Issues: 1
Requires
- php: ^7.2
- doctrine/collections: ^1.8
- doctrine/persistence: ^2.5
- nikic/php-parser: ^4.13
- otobank/doctrine-target-aware-criteria: ^0.3
- phpstan/phpstan: ^1.10
- phpstan/phpstan-doctrine: ^1.3
Requires (Dev)
- doctrine/common: ^3.4
- doctrine/dbal: ^2.7.1
- doctrine/orm: ^2.7.5
- friendsofphp/php-cs-fixer: ^2.14
- phpstan/phpstan-phpunit: ^1.1
- phpunit/phpunit: ^8
- symfony/cache: ^5.4
README
This extension provides following features:
- Validates entity fields to which criteria is applied.
- Depends on phpstan-doctrine, and includes its features.
Usage
composer require otobank/doctrine-target-aware-criteria
composer require --dev otobank/phpstan-doctrine-criteria
includes: - vendor/otobank/phpstan-doctrine-criteria/extension.neon - vendor/otobank/phpstan-doctrine-criteria/rules.neon
Configuration
parameters: doctrine: objectManagerLoader: bootstrap/phpstan_doctrine_manager.php
See: https://github.com/phpstan/phpstan-doctrine
You must use custom criteria.
FooCriteria
namespace App\Criteria; use App\Entity\Foo; use Otobank\PHPStan\Doctrine\Criteria; class FooCriteria extends Criteria { public static function getTargetClass() : string { return Foo::class; } }
Use FooCriteria
namespace App\Entity; use App\Criteria\FooCriteria; class Bar { /** * @var \Doctrine\Common\Collections\Collection * * @ORM\OneToMany(targetEntity="Foo", mappedBy="bar") */ private $foos; public function getFilteredFoos() { $criteria = FooCriteria::create(); $criteria = $criteria ->where($criteria->expr()->eq('fieldX', 1)) // Check if fieldX is defined in Foo class ; return $this->foos->matching($criteria); } }
Author
Toshiyuki Fujita - tfujita@otobank.co.jp - https://github.com/kalibora
License
Licensed under the MIT License - see the LICENSE file for details
OTOBANK Inc.