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

Using @phpstan-type and returning said type in a docblock attempts to load a non-existing class #6834

Open
nesl247 opened this issue Nov 27, 2024 · 3 comments

Comments

@nesl247
Copy link
Contributor

nesl247 commented Nov 27, 2024

API Platform version(s) affected: 3.3.12

Description
When viewing documentation and using @phpstan-type CustomType array{} and @returns CustomType, an error is thrown.

  "@context": "/contexts/Error",
  "@type": "hydra:Error",
  "hydra:title": "An error occurred",
  "hydra:description": "Class \"Satws\\Scarface\\Insight\\Reports\\InsightReportInsights\" does not exist",
  "trace": [
    {
      "namespace": "",
      "short_class": "",
      "class": "",
      "type": "",
      "function": "",
      "file": "/srv/app/vendor/api-platform/core/src/JsonSchema/DefinitionNameFactory.php",
      "line": 35,
      "args": []
    },
    {
      "namespace": "",
      "short_class": "ReflectionClass",
      "class": "ReflectionClass",
      "type": "-\u003E",
      "function": "__construct",
      "file": "/srv/app/vendor/api-platform/core/src/JsonSchema/DefinitionNameFactory.php",
      "line": 35,
      "args": [
        [
          "string",
          "Satws\\Scarface\\Insight\\Reports\\InsightReportInsights"
        ]
      ]
    },

If you use @phpstan-returns instead, the error will go away.

How to reproduce

<?php

#[ApiResource]
/**
* @phpstan-type CustomType array{test: string}
*/
class Test 
{
  /**
   * @returns CustomType
   */
  public function __construct(public array $property) {}
}

Possible Solution

Additional Context

Copy link

stale bot commented Jan 26, 2025

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jan 26, 2025
@nesl247
Copy link
Contributor Author

nesl247 commented Jan 27, 2025

This is still relevant.

@dunglas
Copy link
Member

dunglas commented Jan 27, 2025

This looks like a PHPStan-specific feature. The easiest way to support it would be to support for this in Symfony TypeInfo.

@stale stale bot removed the stale label Jan 27, 2025
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

2 participants