Skip to content

Conversation

@carlos-granados
Copy link
Contributor

Apply several new rules. Most don't need any changes in the code

{
/**
* @var string
* @var Suite
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment was wrong


$this->example = $event->getScenario();
assert($this->example instanceof ExampleNode);
$scenario = $event->getScenario();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to assert that the scenario is an ExampleNode before assigning to the property as the property has the ExampleNode type

$call = $hookCallResult->getCall();
$callee = $call->getCallee();
$hook = (string) $callee;
$hook = $callee->__toString();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

PSalm is not happy with the cast and requires a explicit call to __toString()

Copy link
Member

Choose a reason for hiding this comment

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

I would ignore such rule for now, especially if we migrate to phpstan (as discussed in the Gherking repo), as phpstan does not have such rule in its default config (at least not for stringable types)

Copy link
Member

Choose a reason for hiding this comment

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

Looking into this, it seems like the types don't guarantee that the callee received here is a child of RuntimeHook, which is where __toString is defined (and not in the Callee interface). So Psalm is right about complaining here, but it would also complain about the explicit call to __toString.

Maybe the rule complaining about it is not enabled yet. This is the risk of enabling only some rules instead of a full level, as it could lead to switching to a different error (not reported yet) instead of fixing the root cause.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ran this with the full level 6 enabled and did not get any complains, so maybe it is detected at another level. Let me try to see which is the best way to handle this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have narrowed the types before applying the conversion to string

private $key;
/**
* @var string[]
* @var array<string, string[]>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

doc-block was wrong


/**
* @return null|float
* @return float
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function never returns null

* @author Konstantin Kudryashov <ever.zet@gmail.com>
*/
interface TestworkException
interface TestworkException extends Throwable
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This exception interface needs to extend the Throwable interface so that Psalm accepts that any exception which implements it can be thrown

@carlos-granados carlos-granados merged commit 5e60815 into Behat:master Dec 17, 2024
17 checks passed
@carlos-granados carlos-granados deleted the psalm-level-6-3 branch December 17, 2024 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants