junstyle / vscode-php-cs-fixer

PHP CS Fixer extension for VS Code
https://marketplace.visualstudio.com/items?itemName=junstyle.php-cs-fixer
MIT License
354 stars 42 forks source link

Class not found (happens only with extension) #196

Closed rinart73 closed 1 year ago

rinart73 commented 1 year ago

I have php-cs-fixer installed globally both on Windows and Linux. It works with the following .php-cs-fixer.dist.php just fine:

<?php
declare(strict_types=1);

use CodeIgniter\CodingStandard\CodeIgniter4;
use Nexus\CsConfig\Factory;
use PhpCsFixer\Finder;

$finder = Finder::create()
    ->files()
    ->in([
        __DIR__ . '/src/',
        __DIR__ . '/tests/',
    ])
    ->exclude('build')
    ->append([
        __FILE__,
        __DIR__ . '/rector.php',
    ]);

$overrides = [
    'declare_strict_types' => true,
    'void_return'          => true,
];

$options = [
    'finder'    => $finder,
    'cacheFile' => 'build/.php-cs-fixer.cache',
];

return Factory::create(new CodeIgniter4(), $overrides, $options)->forProjects();

However when I'm trying to save and format a project file with your extension, I get the following:

[
  "fix",
  "--using-cache=no",
  "--format=json",
  "--config=/home/rinart/Documents/Projects/ci4-document-helper/.php-cs-fixer.dist.php",
  "--path-mode=override",
  "/tmp/pcf-tmp0.31012932534822335/ImagesTest.php"
]
PHP Fatal error:  Uncaught Error: Class "Nexus\CsConfig\Factory" not found in /home/rinart/Documents/Projects/ci4-document-helper/.php-cs-fixer.dist.php:31
Stack trace:
#0 phar:///usr/local/bin/php-cs-fixer/src/Console/ConfigurationResolver.php(952): include()
#1 phar:///usr/local/bin/php-cs-fixer/src/Console/ConfigurationResolver.php(264): PhpCsFixer\Console\ConfigurationResolver::separatedContextLessInclude()
#2 phar:///usr/local/bin/php-cs-fixer/src/Console/ConfigurationResolver.php(281): PhpCsFixer\Console\ConfigurationResolver->getConfig()
#3 phar:///usr/local/bin/php-cs-fixer/src/Console/Command/FixCommand.php(262): PhpCsFixer\Console\ConfigurationResolver->getConfigFile()
#4 phar:///usr/local/bin/php-cs-fixer/vendor/symfony/console/Command/Command.php(298): PhpCsFixer\Console\Command\FixCommand->execute()
#5 phar:///usr/local/bin/php-cs-fixer/vendor/symfony/console/Application.php(1040): Symfony\Component\Console\Command\Command->run()
#6 phar:///usr/local/bin/php-cs-fixer/vendor/symfony/console/Application.php(301): Symfony\Component\Console\Application->doRunCommand()
#7 phar:///usr/local/bin/php-cs-fixer/src/Console/Application.php(94): Symfony\Component\Console\Application->doRun()
#8 phar:///usr/local/bin/php-cs-fixer/vendor/symfony/console/Application.php(171): PhpCsFixer\Console\Application->doRun()
#9 /usr/local/bin/php-cs-fixer(102): Symfony\Component\Console\Application->run()
#10 {main}
  thrown in /home/rinart/Documents/Projects/ci4-document-helper/.php-cs-fixer.dist.php on line 31

Since the global version works fine, unless called by the extension, I assume that it's a bug with extension.

I've read #122 and tried the changing use Nexus\CsConfig\Factory; to use \Nexus\CsConfig\Factory;, it didn't work.

What other info that I can give would be useful in solving the issue?

junstyle commented 1 year ago

simple issue, you should make sure php code in '/home/rinart/Documents/Projects/ci4-document-helper/.php-cs-fixer.dist.php` can import Nexus\CsConfig\Factory,

i think you should know how to import class file in php.