1

Even though I think I specified the right AUTOLOAD_PATHS to rector.php, I keep getting the same error: Class Bake\View\Helper not found.

I'm attempting to convert a CakePHP 3.10.1 plugin to CakePHP 4.0.

$ bin/cake upgrade rector --rules cakephp40 ../my_app/plugins/WetKit/src

 [ERROR] Could not process "View/Helper/BakeHelper.php" file, due to:
         "Analyze error: "Class Bake\View\Helper not found.". Include your files in
         "$parameters->set(Option::AUTOLOAD_PATHS, [...]);" in "rector.php" config.
         See https://github.com/rectorphp/rector#configuration".

rector.php

<?php
declare(strict_types=1);

use Rector\Core\Configuration\Option;
use Rector\Php74\Rector\Property\TypedPropertyRector;
use Rector\Set\ValueObject\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
    // get parameters
    $parameters = $containerConfigurator->parameters();
    $parameters->set(Option::PATHS, [
        __DIR__ . '/src'
    ]);

    $parameters->set(Option::AUTOLOAD_PATHS, [
        '/c/Users/me/Downloads/xampp/htdocs/my_app/vendor/cakephp/bake/src/View/Helper/BakeHelper.php'
    ]);

    // Define what rule sets will be applied
    $containerConfigurator->import(SetList::DEAD_CODE);

    // get services (needed for register a single rule)
    // $services = $containerConfigurator->services();

    // register a single rule
    // $services->set(TypedPropertyRector::class);
};

my_app/plugins/WetKit/src/View/Helper/BakeHelper.php

<?php
namespace WetKit\View\Helper;

use Bake\Utility\Model\AssociationFilter;
use Cake\Core\Configure;
use Cake\Core\ConventionsTrait;
use Cake\Utility\Inflector;
use Cake\View\Helper;
use Cake\Datasource\ConnectionManager;

use Bake\View\Helper as WetKitHelper;

/**
 * Bake helper
 */
class BakeHelper extends WetKitHelper
{
    //code here
}
TechFanDan
  • 3,329
  • 6
  • 46
  • 89
  • 1
    You shouldn't need any custom rector configuration, the rector command provided by the upgrade plugin will detect the composer autoloader automatically and pass that information over to rector. That being said, there is no such thing as a class named `\Bake\View\Helper`, that's only a namespace, bake has two helpers, `\Bake\View\Helper\BakeHelper` and `\Bake\View\Helper\DocBlockHelper`. – ndm Jan 20 '22 at 16:06
  • Then, my class definition is wrong? I changed it to `use Bake\View\Helper\BakeHelper` and rector worked. I still need to confirm that the plugin will work when baking, with this change. – TechFanDan Jan 20 '22 at 16:55
  • 1
    If you want to extend `BakeHelper`, then that would be the correct `use` statement, yes. Of course you'd still need to alias it, or just use that fully qualified name in the `extends` statement. – ndm Jan 20 '22 at 20:25
  • FYI, in both cases, it works! Thanks. Now going through the rest of the exceptions that are present after having gone through Rector. – TechFanDan Jan 20 '22 at 20:30

0 Answers0