soullivaneuh / php-cs-fixer-styleci-bridge

[DEPRECATED] Replaced by a new project =>
https://flintci.io
MIT License
40 stars 7 forks source link

PHP Fatal error: Uncaught Error: Call to undefined method PhpCsFixer\Config::finder() in [...]vendor/sllh/php-cs-fixer-styleci-bridge/src/ConfigBridge.php:136 #75

Open robfrawley opened 7 years ago

robfrawley commented 7 years ago

After my most recent composer update I am getting a fatal error when running bin/php-cs-fixer with the bridge.

bin/php-cs-fixer -vvv --dry-run fix
Fixer "short_array_syntax" does not exist, skipping.
Fixer "no_spaces_inside_offset" does not exist, skipping.
Fixer "no_tab_indentation" does not exist, skipping.
Fixer "unalign_double_arrow" does not exist, skipping.
Fixer "unalign_equals" does not exist, skipping.
Fixer "unix_line_endings" does not exist, skipping.
PHP Fatal error:  Uncaught Error: Call to undefined method PhpCsFixer\Config::finder() in /home/rmf/repos/composer/augustus-log-library/vendor/sllh/php-cs-fixer-styleci-bridge/src/ConfigBridge.php:136
Stack trace:
#0 /home/rmf/repos/composer/augustus-log-library/.php_cs.dist(27): SLLH\StyleCIBridge\ConfigBridge::create()
#1 /home/rmf/repos/composer/augustus-log-library/vendor/friendsofphp/php-cs-fixer/src/Console/ConfigurationResolver.php(179): include('/home/rmf/repos...')
#2 /home/rmf/repos/composer/augustus-log-library/vendor/friendsofphp/php-cs-fixer/src/Console/ConfigurationResolver.php(443): PhpCsFixer\Console\ConfigurationResolver->getConfig()
#3 /home/rmf/repos/composer/augustus-log-library/vendor/friendsofphp/php-cs-fixer/src/Console/ConfigurationResolver.php(262): PhpCsFixer\Console\ConfigurationResolver->getFormat()
#4 /home/rmf/repos/composer/augustus-log-library/vendor/friendsofphp/php-cs-fixer/src/Console/Command/FixCommand.php(321): PhpCsFixer\Console\ConfigurationResolver->getReporter()
#5 /home/rmf/repos/compo in /home/rmf/repos/composer/augustus-log-library/vendor/sllh/php-cs-fixer-styleci-bridge/src/ConfigBridge.php on line 136

With the following dependencies:

"require-dev": {
  "friendsofphp/php-cs-fixer": "~2.0",
  "sllh/php-cs-fixer-styleci-bridge": "~2.1"
}

And the following .php_cs.dist

<?php

use SLLH\StyleCIBridge\ConfigBridge;

require_once __DIR__.'/vendor/autoload.php';

$headerString = <<<EOF
[...] removed for brevity [...]
EOF;

$headerConfig = [ 'header_comment' => [ 'header' => $headerString ] ];

$config = ConfigBridge::create();
$config->setRules(array_merge($config->getRules(), $headerConfig));

return $config;

And the following .styleci.yml

---

preset: symfony

enabled:
  - combine_consecutive_unsets
  - linebreak_after_opening_tag
  - no_short_echo_tag
  - ordered_imports
  - phpdoc_order
  - php_unit_construct
  - php_unit_dedicate_assert
  - php_unit_strict
  - short_array_syntax

disabled:
  - simplified_null_return

finder :
  name    : [ "*.php", "*.twig" ]
  exclude : [ "vendor", "var" ]
  path    : [ "lib", "test" ]

...
robfrawley commented 7 years ago

This incompatibility occurred somewhere between the release of v2.0.0alpha and v2.0.0beta of php-cs-fixer.

Diff between d0d76b4 and 962b2c5 contains the affected changed...somewhere.

sstok commented 7 years ago

@Soullivaneuh The PHP-CS-Fixer 2.0 is stable now and we are unable to upgrade.

GrahamCampbell commented 7 years ago

This is really my fault because there are 54 fixer alises and 26 virtual fixers in StyleCI, so it's actually impossible to map to php-cs-fixer with ease.

GrahamCampbell commented 7 years ago

The mapping class StyleCI has is 278 lines long, and that deals with the virtual fixers only. The other config class it has to deal with presets, aliases, and conflicts is 842 lines long. These remain closed source though I'm afraid, because they're of high value.


I think it would be a good idea to expose a styleci.yml to php-cs-fixer config config converter on the API. Well, expose a partial version, that is, that takes the risky setting along with the preset and enabled/disabled lists, then generates a list of php-cs-fixers and their config, in the same format as for that tool.

GrahamCampbell commented 7 years ago

Ok, I've done that then, similar to the "validate" endpoint, just pass the config file as the "config" parameter. For example: https://api.styleci.io/rules?config=preset:%20psr2. Unlike the validate endpoint, empty config is supported. The design decision with not permitting this on the other endpoint was because it was targeted at validation, so we wanted to be sure people weren't accidently passing nothing. On this endpoint, nothing is treated like the empty config file, you get all the rules generated from the recommended preset with risky enabled.

GrahamCampbell commented 3 years ago

Replaced by https://github.com/StyleCI/CLI.