Skip to content

[WIP] feat: Property types from phpdocs#1057

Draft
chrisvanlier2005 wants to merge 2 commits intodedoc:mainfrom
chrisvanlier2005:property-types-from-phpdocs
Draft

[WIP] feat: Property types from phpdocs#1057
chrisvanlier2005 wants to merge 2 commits intodedoc:mainfrom
chrisvanlier2005:property-types-from-phpdocs

Conversation

@chrisvanlier2005
Copy link
Copy Markdown
Contributor

@chrisvanlier2005 chrisvanlier2005 commented Jan 2, 2026

Still work in progress, need to add some tests. Bit i've opened it early to gauge interest


The logic is modularized using a PropertyExtractor interface, allowing for distinct strategies to handle different locations where type information might be defined.

Examples

Here are the specific class scenarios that are now supported with this extension:

Standard Properties with @var

Types are now inferred from the @var annotation above the property definition.

class UserData
{
    /** @var string */
    public $name;

    /** @var \Illuminate\Support\Collection<int, string> */
    public $tags;
}

Magic Properties (@property)

Properties defined in the class DocBlock (common in Laravel Models or fluent objects) are now recognized.

/**
 * @property string $status
 * @property-read int $count
 */
class ServerStats
{
    // ...
}

Constructor Promoted Properties

Types are inferred from the constructor's @param tags when using promoted properties.

class CreateUserRequest
{
    /**
     * @param string $email
     * @param int|null $age
     */
    public function __construct(
        public $email,
        public $age,
    ) {}
}

@chrisvanlier2005 chrisvanlier2005 marked this pull request as draft January 2, 2026 08:25
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

Successfully merging this pull request may close these issues.

1 participant