php - PHPCS - Type Hint with alias


I am using phpcs with Squiz_Sniffs_Commenting_FunctionCommentSniff, and I get a message error "Expected type hint 'My\Namespace\Interface'; found 'AliasInterface' for $var at position 1.

I declare namespace at top of class adding alias and the method that receives this dependency has type hint using alias. So phpcs show an error about that.

Is there a way to phpcs validation considering alias?




This reported issue is probably related:

Essentially, the sniff doesn't actually look at your imported namespaces. It just checks to ensure the type hint is the same as the type you've declared in the docblock.

In this case of the reported issue, the fully qualified name was being used in the docblock but the alias was being used in the type hint. Maybe you are doing the same thing here.

There is no way to get around this right now. The only way to stop that specific sniff complaining is to ensure the type hint and docblock match. I'm not aware of any other commenting sniffs that will check the same things but support namespace aliasing.

People are also looking for solutions to the problem: php - How to do a WHERE statement with XPath?


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.