Coder recently started flagging @param \stdClass $foo as wrong in doxygen and suggests @param object $foo.

However, phpstorm wants the doxygen and real typehint to match. As of php 7.2 object can be used, but coder also fails that:

 478 | ERROR | Unknown type hint "object" found for $row

We should be able to use that.

CommentFileSizeAuthor
#8 3059698-8.patch3.69 KBpwolanin
#2 3059698-0.patch1006 bytespwolanin

Comments

pwolanin created an issue. See original summary.

pwolanin’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new1006 bytes

Here's a first pass at a patch

klausi’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Thanks for reporting and the patch!

I think we should not check the current PHP version and simply allow object also as type hint.

Can you file a pull request against https://github.com/pfrenssen/coder and add a test case?

pwolanin’s picture

I couldn’t find easily the api within phpcs to determine the targeted php version - it would likely be better to use that than the actual current version. There is a flag: --config-set php_version

Since object as a type hint would fail in php < 7.2 I'm not sure I agree it should be supported unconditionally. I guess the code would fail, so maybe it's fine?

klausi’s picture

Yep, Coder is only a coding standards checker and does not support valid PHP checks in different versions :)

pwolanin’s picture

There is some related code already in squizlabs:

squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php

                if ($this->phpVersion >= 70200) {
                    if ($suggestedName === 'object') {
                        $suggestedTypeHint = 'object';
                    }
                }
pwolanin’s picture

pwolanin’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new3.69 KB

Here's a patch from the PR. It does have an added test case

  • klausi committed 070c727 on 8.x-3.x authored by pwolanin
    fix(FunctionComment): Allow object as a function param typehint (#...
klausi’s picture

Status: Needs review » Fixed

Committed a simpler version, thanks!

klausi’s picture

Issue tags: +DevDaysTransylvania

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.