-
-
Notifications
You must be signed in to change notification settings - Fork 288
[Feature] autofixer #337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[Feature] autofixer #337
Changes from 23 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
c6e479a
Autofix sniffs
Jibbarth 3cafce5
Exclude Typehint declaration on custom sniff to avoid breaking compat…
Jibbarth cbbb3ac
Autofix issues from php-cs-fixer
Jibbarth d1355d7
Set concrete configuration class in testCase
Jibbarth 80ac7e5
Add fix composer script
Jibbarth 9a92dbb
Clear command definition and add definition for fix command
Jibbarth aefc243
Add display output for fix
Jibbarth 58cf6bb
Add fix command
Jibbarth 7745216
Exclude weird rules with phpstan in ConfigResolver
Jibbarth 52a60b4
Display fixed insights with PhpCsFixer
Jibbarth 02a31c7
Merge branch 'master' into feature/autofixer
Jibbarth 93dbd8d
Update some suppressWarnings
Jibbarth a499471
Use errorOutput to display hint message
Jibbarth 7da4c00
Add docs
Jibbarth 1b62927
Add tests to assert fix work as expected
Jibbarth a198ab4
Create a DefinitionBinder
Jibbarth dc258bb
Enable fix option for laravel
Jibbarth a96e69b
Always show recap of fixed issues
Jibbarth d5c3f25
Change description for fix option
Jibbarth a261990
Merge branch 'master' into feature/autofixer
Jibbarth 61bfa12
Fix after merges
Jibbarth b045ce4
Increase .phpcs memory_limit override
Jibbarth 05da8e0
Add total fixed in Json Formatter
Jibbarth 3b5091a
Update src/Application/Adapters/Laravel/Commands/InsightsCommand.php
Jibbarth f20fd19
Configuration : update function to know if fix is enabled
Jibbarth b38f576
Change enableFix function in File
Jibbarth d2ac381
Create a trait FixPerFileCollector and use it in SniffDecorator and F…
Jibbarth 56bb87e
Fix fixture for test SniffDecorator Fix
Jibbarth 73fcdfd
Merge branch 'master' into feature/autofixer
Jibbarth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace NunoMaduro\PhpInsights\Application\Console\Commands; | ||
|
||
use NunoMaduro\PhpInsights\Application\Console\Formatters\Console; | ||
use NunoMaduro\PhpInsights\Application\Console\OutputDecorator; | ||
use NunoMaduro\PhpInsights\Domain\Configuration; | ||
use NunoMaduro\PhpInsights\Domain\Insights\InsightCollectionFactory; | ||
use NunoMaduro\PhpInsights\Domain\MetricsFinder; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class FixCommand | ||
{ | ||
/** | ||
* @var \NunoMaduro\PhpInsights\Domain\Insights\InsightCollectionFactory | ||
*/ | ||
private $collectionFactory; | ||
/** | ||
* @var \NunoMaduro\PhpInsights\Domain\Configuration | ||
*/ | ||
private $config; | ||
|
||
public function __construct( | ||
InsightCollectionFactory $collectionFactory, | ||
Configuration $config | ||
) { | ||
$this->collectionFactory = $collectionFactory; | ||
$this->config = $config; | ||
} | ||
|
||
public function __invoke(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$metrics = MetricsFinder::find(); | ||
$collection = $this->collectionFactory->get($metrics, $output); | ||
|
||
$output = OutputDecorator::decorate($output); | ||
$formatter = new Console($input, $output); | ||
|
||
$formatter->formatFix($collection, $this->config->getDirectory(), $metrics); | ||
|
||
return 0; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace NunoMaduro\PhpInsights\Application\Console\Definitions; | ||
|
||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputDefinition; | ||
use Symfony\Component\Console\Input\InputOption; | ||
|
||
/** | ||
* Minimum definition for each of our commands. | ||
* | ||
* @internal | ||
*/ | ||
abstract class BaseDefinition | ||
{ | ||
public static function get(): InputDefinition | ||
{ | ||
return new InputDefinition([ | ||
new InputArgument( | ||
'directory', | ||
InputArgument::OPTIONAL, | ||
'The directory to analyse' | ||
), | ||
new InputOption( | ||
'config-path', | ||
'c', | ||
InputOption::VALUE_OPTIONAL, | ||
'The configuration file path' | ||
), | ||
]); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace NunoMaduro\PhpInsights\Application\Console\Definitions; | ||
|
||
use Symfony\Component\Console\Application; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class DefinitionBinder | ||
Jibbarth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
public static function bind(InputInterface $input): void | ||
{ | ||
// merge application default definition with current command definition. | ||
$definition = (new Application())->getDefinition(); | ||
|
||
$commandDefinition = BaseDefinition::get(); | ||
if ($input->getFirstArgument() !== 'fix') { | ||
$commandDefinition = AnalyseDefinition::get(); | ||
} | ||
|
||
$definition->addArguments($commandDefinition->getArguments()); | ||
$definition->addOptions($commandDefinition->getOptions()); | ||
|
||
$input->bind($definition); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace NunoMaduro\PhpInsights\Application\Console\Definitions; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class FixDefinition extends BaseDefinition | ||
{ | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.