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

Psalm 4 #486

Merged
merged 1 commit into from
Apr 23, 2022
Merged

Psalm 4 #486

merged 1 commit into from
Apr 23, 2022

Conversation

franmomu
Copy link
Member

Subject

Raises Psalm to level 4 fixing some types on the way

I am targeting this branch, because fixes some phpdoc types.

Changelog

### Fixed
- Fixed some phpdoc types

@franmomu franmomu added the patch label Apr 23, 2022
@@ -308,7 +308,7 @@ private function getOriginalEntityData(object $entity): array
}

/**
* @return string|int
* @return string|int|false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you're returning false, it means you're setting false to the property too.

Also false doesn't seems to be a supported return type because it's later use as a param in the query.

Maybe we should throw an exception if the value is false ?

@@ -571,7 +571,7 @@ public function findRevisions($className, $id)
* @throws NotAuditedException
* @throws Exception
*
* @return int|string
* @return int|string|false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we prefer null ?
or throw an exception in next major ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do that

@@ -122,7 +122,7 @@ public function __construct(AuditReader $auditReader, $class, ClassMetadataInfo
}

/**
* @return bool
* @return true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change ? this method return nothing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 19 to 21
* @var string[]
*
* @phpstan-var class-string[]
* @phpstan-var array<class-string, int|string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

array<class-string, int|string> is not fully compatible with string[], so maybe the @var need to be updated too.

*/
private $auditedEntities = [];

/**
* @phpstan-param array<class-string, mixed> $auditedEntities
* @phpstan-param class-string[] $auditedEntities
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is something weird according to phpstan

$this->auditedEntities = array_flip(array_filter($auditedEntities, static function ($record): bool {
return \is_string($record) || \is_int($record);
}));
$this->auditedEntities = array_flip($auditedEntities);
Copy link
Member Author

@franmomu franmomu Apr 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently this was done in #143 because of SonataDoctrineORMAdminBundle, but looking at the tests there, looks like there are no null values. We could still add an array_filter call just in case, but if there are null values, we should fix it in the doctrine orm admin bundle.

@franmomu franmomu force-pushed the fix_types branch 4 times, most recently from 891c66b to f492703 Compare April 23, 2022 14:36
@franmomu franmomu merged commit 0e7b80f into sonata-project:1.x Apr 23, 2022
@franmomu franmomu deleted the fix_types branch April 23, 2022 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants