Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PHPStan #195

Draft
wants to merge 2 commits into
base: 2.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,7 @@ jobs:

- name: 'Run PHPUnit tests'
run: vendor/bin/simple-phpunit --testdox --verbose ${{ matrix.code-coverage && '--coverage-text --coverage-clover build/logs/clover.xml' }}

- name: 'Run PHPStan'
run: vendor/bin/phpstan
if: ${{ matrix.mongodb }}
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
"doctrine/dbal": "^3.2",
"doctrine/doctrine-bundle": "^2.5",
"doctrine/orm": "^2.10",
"phpstan/phpstan": "^1.7",
"phpunit/phpunit": "^9.5",
"symfony/browser-kit": "^5.4|^6.0",
"symfony/config": "^5.4|^6.0",
"symfony/dependency-injection": "^5.4.2|^6.0.1",
Expand Down
11 changes: 11 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
includes:
- vendor/phpstan/phpstan/conf/bleedingEdge.neon
parameters:
level: 6
paths:
- src
# - tests
checkGenericClassInNonGenericObjectType: false # https://phpstan.org/blog/generics-in-php-using-phpdocs
reportUnmatchedIgnoredErrors: false
checkMissingIterableValueType: false
treatPhpDocTypesAsCertain: false
3 changes: 3 additions & 0 deletions src/Attribute/EnumCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#[\Attribute(\Attribute::TARGET_CLASS_CONSTANT)]
class EnumCase
{
/**
* @param array<string, mixed> $extras
*/
public function __construct(public readonly ?string $label = null, public readonly array $extras = [])
{
}
Expand Down
13 changes: 12 additions & 1 deletion src/Bridge/Doctrine/Common/AbstractTypesDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@

/**
* @internal
*
* @phpstan-type Type = array{0: class-string<\BackedEnum>, 1: string, 2: string, 3: string|int|null}
*/
abstract class AbstractTypesDumper
{
public function dumpToFile(string $file, array $types)
/**
* @param Type[] $types
*/
public function dumpToFile(string $file, array $types): void
{
file_put_contents($file, $this->dump($types));
}
Expand Down Expand Up @@ -57,6 +62,9 @@ function (array $word): string {
);
}

/**
* @param Type[] $types
*/
private function dump(array $types): string
{
array_walk($types, static function (&$type) {
Expand Down Expand Up @@ -92,6 +100,9 @@ private function dump(array $types): string

abstract protected function getTypeCode(string $classname, string $enumClass, string $type, string $name, \BackedEnum|int|string|null $defaultOnNull = null): string;

/**
* @return array<string, string>
*/
abstract protected static function getSuffixes(): array;

abstract protected static function getMarker(): string;
Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Symfony/Bundle/ElaoEnumBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

class ElaoEnumBundle extends Bundle
{
public function build(ContainerBuilder $container)
public function build(ContainerBuilder $container): void
{
parent::build($container);

Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Symfony/Form/Type/EnumType.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class EnumType extends AbstractType
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
public function configureOptions(OptionsResolver $resolver): void
{
$resolver
// Override the original type logic for label for readable enums.
Expand Down
4 changes: 2 additions & 2 deletions src/Bridge/Symfony/Form/Type/FlagBagType.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
class FlagBagType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
public function buildForm(FormBuilderInterface $builder, array $options): void
{
if (!$options['multiple']) {
throw new InvalidConfigurationException(sprintf(
Expand All @@ -38,7 +38,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
public function configureOptions(OptionsResolver $resolver): void
{
$resolver
->setDefault('multiple', true)
Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Symfony/VarDumper/Caster/FlagBagCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

final class FlagBagCaster
{
public static function cast(FlagBag $bag)
public static function cast(FlagBag $bag): array
{
$a = [];

Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Symfony/VarDumper/Caster/ReadableEnumCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

final class ReadableEnumCaster
{
public static function cast(ReadableEnumInterface $enum, $array)
public static function cast(ReadableEnumInterface $enum, $array): array
{
return $array + [
// Append the readable value;
Expand Down