Skip to content

Use FQN in PHPDoc #10

Closed
Closed

Description

@Sweetchuck

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.

Activity

  1. added a commit that references this issue on Feb 17, 2022
  2. added a commit that references this issue on Feb 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions