deptrac icon indicating copy to clipboard operation
deptrac copied to clipboard

Deptrac does not recognize type aliases

Open patrickkusebauch opened this issue 2 years ago • 4 comments

Both PhpStan and Psalm allow users to define type aliases:

  • PhpStan - https://phpstan.org/writing-php-code/phpdoc-types#local-type-aliases
  • Psalm - https://psalm.dev/docs/annotating_code/type_syntax/utility_types/#type-aliases

However, Deptrac does not recognize them and assumes there exists a class with the name of the alias. This results in Deptrac complaining about an uncovered dependency on a class that does not exist.

patrickkusebauch avatar Jan 26 '24 21:01 patrickkusebauch

What a coincidence, only encountered this just now as well :) Thanks for reporting it.

MetalArend avatar Jan 27 '24 07:01 MetalArend

I saw #849. Here is a fairly simple example to trigger the uncovered type found in a @phpstan-type annotation.

<?php

namespace App;

/**
 * @phpstan-type TestType array<mixed>
 */
final class Test
{
    /**
     * @param TestType $content
     */
    private function __construct(private readonly array $content)
    {
    }
}
parameters:
  paths:
    - ./src/App
  layers:
    - name: App
      collectors:
        - type: directory
          value: src/App/.*
  ruleset:
    App: ~

MetalArend avatar Jan 27 '24 07:01 MetalArend

I confirm this issue (and https://github.com/qossmic/deptrac/issues/849).

javaDeveloperKid avatar Feb 06 '24 15:02 javaDeveloperKid