Skip to content

[8.4] Fatal error when using property hooks with enums #242

@ruudk

Description

@ruudk
<?php

declare(strict_types=1);

namespace GraphQL;

enum State: string
{
    case Created = 'created';
    case Pending = 'pending';
}

final class Test
{
    public State $state {
        get => State::from('created');
    }

    public function getState() : State
    {
        return $this->state;
    }
}

produces the following fatal error:

Internal error: Method '$state::get' does not exist in class 'Test'. It emitted usage ofState::Created by ShipMonk\PHPStan\DeadCode\Provider\EnumUsageProvider for node 'PhpParser\Node\Expr\StaticCall'

## /Volumes/CS/www/cosmos/vendor/shipmonk/dead-code-detector/src/Collector/ProvidedUsagesCollector.php(105)
#0 /Volumes/CS/www/cosmos/vendor/shipmonk/dead-code-detector/src/Collector/ProvidedUsagesCollector.php(71): ShipMonk\PHPStan\DeadCode\Collector\ProvidedUsagesCollector->validateUsage(Object(ShipMonk\PHPStan\DeadCode\Graph\ClassConstantUsage), Object(ShipMonk\PHPStan\DeadCode\Provider\EnumUsageProvider), Object(PhpParser\Node\Expr\StaticCall), Object(PHPStan\Analyser\MutatingScope))
#1 phar:///Volumes/CS/www/cosmos/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(158): ShipMonk\PHPStan\DeadCode\Collector\ProvidedUsagesCollector->processNode(Object(PhpParser\Node\Expr\StaticCall), Object(PHPStan\Analyser\MutatingScope))
#2 phar:///Volumes/CS/www/cosmos/vendor/phpstan/phpstan/phpstan.phar/src/Node/ClassStatementsGatherer.php(116): PHPStan\Analyser\FileAnalyser->{closure:PHPStan\Analyser\FileAnalyser::analyseFile():102}(Object(PhpParser\Node\Expr\StaticCall), Object(PHPStan\Analyser\MutatingScope))

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions