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

Use FQN in PHPDoc #10

Closed
Sweetchuck opened this issue Feb 17, 2022 · 0 comments
Closed

Use FQN in PHPDoc #10

Sweetchuck opened this issue Feb 17, 2022 · 0 comments

Comments

@Sweetchuck
Copy link
Contributor

Sweetchuck commented Feb 17, 2022

Currently relative class names are used in PHPDoc type hints.

https://github.com/Codeception/lib-asserts/blob/master/src/Codeception/Util/Shared/InheritedAsserts.php#L5-25

/**
 * @param array|ArrayAccess $array
 */

When it is used it becomes like this:

<?php 
namespace MyVendor\MyProject\Tests\_generated;

// This class was automatically generated by build task
// You should not change it manually as it will be overwritten on next build
// @codingStandardsIgnoreFile

trait UnitTesterActions
{
    /**
     * [!] Method is generated. Documentation taken from corresponding module.
     *
     * Asserts that an array has a specified key.
     *
     * @param int|string $key
     * @param array|ArrayAccess $array
     * @see \Codeception\Module\AbstractAsserts::assertArrayHasKey()
     */
    public function assertArrayHasKey($key, $array, string $message = "") {
        return $this->getScenario()->runStep(new \Codeception\Step\Action('assertArrayHasKey', func_get_args()));
    }
}

☝️ it is still relative.

Using the ::assertArrayHasKey() trough the tester:
$this->tester->assertArrayHasKey('foo', $myArrayOrArrayAccess);

PHPStorm highlights this line with an error, because:

Expected parameter of type 'array|\MyVendor\MyProject\Tests\_generated\ArrayAccess', '\MyVendor\MyProject\Foo' provided.

Recommended soulution

Use Fully Qualified Names for classes, traits and interfaces in PHPDoc type hints.

Sweetchuck added a commit to Sweetchuck/codeception-lib-asserts that referenced this issue Feb 17, 2022
Naktibalda added a commit that referenced this issue Feb 10, 2023
Issue #10 - Use FQN in PHPDoc type hints for classes and interfaces
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

No branches or pull requests

1 participant