Skip to content

Testing - Return types, hints, phpstan #1403

@michalcharvat

Description

@michalcharvat

At the moment there is a mess in the code. How do you want to test code like:

$entityType = \go\core\orm\EntityType::findById($this->entityTypeId);
$className = $entityType->getClassName();

You cant actually use if (!$entityType) {...} because the return type is bool and entityType could be also true. Perhaps all functions returning something byId, by should return ?stratic. Sure you can create hint to fool phpstan but then you would hide real error. For example

public function setFromEntity(string $entityName) {
$e = EntityType::findByName($entityName);
$this->fromEntity = $e->getName();
$this->fromEntityTypeId = $e->getId();
would raise the exception to calling getName on bool

Sometimes phpstan is the hell but it really uncover real errors in the code.

I can help you with that but if I am not wrong my last PR with hints went to trash, so I dont want waste my time with sometime you dont want, need or merge. Please let me know.

Metadata

Metadata

Assignees

Labels

questionFurther information is requested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions