Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/otobank/phpstan-doctrine-criteria
https://github.com/otobank/phpstan-doctrine-criteria
Last synced: 9 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/otobank/phpstan-doctrine-criteria
- Owner: otobank
- License: mit
- Created: 2019-02-24T07:22:37.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-04-06T15:49:38.000Z (over 1 year ago)
- Last Synced: 2024-08-08T16:13:29.286Z (3 months ago)
- Language: PHP
- Size: 45.9 KB
- Stars: 2
- Watchers: 14
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Doctrine Criteria extensions for PHPStan
This extension provides following features:
* Validates entity fields to which criteria is applied.
* Depends on [phpstan-doctrine](https://github.com/phpstan/phpstan-doctrine), and includes its features.## Usage
```
composer require otobank/doctrine-target-aware-criteria
composer require --dev otobank/phpstan-doctrine-criteria
``````yaml
includes:
- vendor/otobank/phpstan-doctrine-criteria/extension.neon
- vendor/otobank/phpstan-doctrine-criteria/rules.neon
```## Configuration
```yaml
parameters:
doctrine:
objectManagerLoader: bootstrap/phpstan_doctrine_manager.php
```See: https://github.com/phpstan/phpstan-doctrine
## You must use custom criteria.
`FooCriteria`
```php
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`
```php
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 - [email protected] - https://github.com/kalibora
## License
Licensed under the MIT License - see the [LICENSE](LICENSE) file for details
----
OTOBANK Inc.