0

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
  • The fuel autoloader aliases all "core" namespaces to the root, to make it easy to create your own version or to overload the core version of the class. Most IDE's have a similar issue, I have a classes.php in the project root that contains lines like class Agent extends Fuel\Core\Agent {} class Arr extends Fuel\Core\Arr {} .... so my IDE can find them. Commented Jun 25, 2022 at 19:58

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.