Skip to content

bug: Can't get a type for Services #38

@neznaika0

Description

@neznaika0

PHP Version

8.2

PHPStan CodeIgniter Version

1.5.4

PHPStan Version

2.1.17

What happened?

Property Acme\Main\Controllers\AbstractController::$toasts (Acme\Toasts) does not accept  
         object.                                                                                                                 
         🪪 assign.propertyType  

Minimum Reproduction Script

Added to phpstan.neon.dist:

parameters:
	codeigniter:
		additionalConfigNamespaces:
			- Acme\Main\Config
		additionalServices:
			- Acme\Main\Config\Services

In controller:

    public function __construct()
    {
        \PHPStan\dumpType(service('toasts')); // Dumped type: object
        \PHPStan\dumpType(service('session')); // Dumped type: CodeIgniter\Session\Session
        $this->session = service('session');
        $this->toasts  = service('toasts');
    }

Acme\Main\Config\Services:

class Services extends BaseService
{
    public static function toasts(bool $getShared = true): Toasts
    {
        if ($getShared) {
            return static::getSharedInstance('toasts');
        }

        return new Toasts();
    }
}

Expected Output

The correct type must be returned.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions