PHPStan configuration for FuelPHP

218 views Asked by At

I am having a lot of trouble getting PHPStan to see the FuelPHP core classes. It would appear this sort of thing causes it grief:

namespace Fuel\Core;

/**
 * Template Controller class
 *
 * A base controller for easily creating templated output.
 *
 * @package   Fuel
 * @category  Core
 * @author    Fuel Development Team
 */
abstract class Controller_Template extends \Controller
{
    /**
    * @var string page template
    */
    public $template = 'template';

Where Controller is also in the Fuel\Core namespace:

namespace Fuel\Core;

abstract class Controller
{
    /**
     * @var  Request  The current Request object
     */
    public $request;

It looks like PHPStan can's find Controller because it is looking in the root namespace. FuelPHP gets around this (magic? autoloading? aliasing?). Is there a way to get PHPStan to jump on the same bandwagon, or do I need to stub out all the core classes I'm using?

1

There are 1 answers

0
Ondřej Mirtes On

Did you try to follow this guide? PHPStan: Discovering symbols

I helped set up FuelCMS analysis in the past. What worked for that user was this phpstan.neon:

parameters:
    scanDirectories:
      - core/classes

    bootstrapFiles:
      - core/classes/autoloader.php

There's an example repository that works: https://github.com/ondrejmirtes/phpstan_problem/tree/fix

For some reason the phpstan.neon is buried in app/classes/controller while it should definitely be in the root directory. But otherwise it works.