Skip to content

Commit

Permalink
Merge pull request #153 from tighten/drift/2x-update-custom-order-class
Browse files Browse the repository at this point in the history
[2.x] Fix issue with new PHP CS Fixer
  • Loading branch information
driftingly authored Jun 24, 2024
2 parents b12d519 + b99d0b1 commit 7b138e5
Show file tree
Hide file tree
Showing 19 changed files with 11,337 additions and 589 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ jobs:
tools: composer:v2
coverage: none

- name: Install dependencies
run: composer install

- name: Add dev dependencies
run: composer require --dev nunomaduro/larastan pestphp/pest
- name: Install dev dependencies
shell: bash
run: export COMPOSER=composer-dev.json && composer install

- name: Run Duster
run: ./builds/duster lint --using="tlint,phpcodesniffer,phpcsfixer,pint"
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/composer-dev.lock
/vendor
.phpunit.result.cache
.idea
1 change: 1 addition & 0 deletions .phpunit.cache/test-results
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":"pest_2.34.8","defects":[],"times":{"P\\Tests\\Feature\\DusterConfigTest::__pest_evaluable_it_uses_duster_config_file":0.278,"P\\Tests\\Feature\\DusterConfigWildcardTest::__pest_evaluable_it_allows_wildcard_includes_and_excludes":0.042,"P\\Tests\\Feature\\LintCommandTest::__pest_evaluable_it_lints_without_issues":0.03,"P\\Tests\\Feature\\LintCommandTest::__pest_evaluable_it_lints_with_TLint":0.029,"P\\Tests\\Feature\\LintCommandTest::__pest_evaluable_it_lints_with_TLint_when_path_contains_space":0.002,"P\\Tests\\Feature\\LintCommandTest::__pest_evaluable_it_only_lints_with_TLint":0.003,"P\\Tests\\Feature\\LintCommandTest::__pest_evaluable_it_lints_with_PHP__CodeSniffer":0.029,"P\\Tests\\Feature\\LintCommandTest::__pest_evaluable_it_only_lints_with_PHP__CodeSniffer":0.007,"P\\Tests\\Feature\\LintCommandTest::__pest_evaluable_it_lints_with_PHP_CS_Fixer":0.029,"P\\Tests\\Feature\\LintCommandTest::__pest_evaluable_it_only_lints_with_PHP_CS_Fixer":0.01,"P\\Tests\\Feature\\LintCommandTest::__pest_evaluable_it_lints_with_Pint":0.027,"P\\Tests\\Feature\\LintCommandTest::__pest_evaluable_it_only_lints_with_Pint":0.013,"P\\Tests\\Feature\\LintCommandTest::__pest_evaluable_it_only_lints_with_both_TLint_and_Pint":0.015,"P\\Tests\\Feature\\LintCommandTest::__pest_evaluable_it_lints_multiple_provided_files":0.027,"P\\Tests\\Feature\\PhpCodeSnifferConfigOverrideTest::__pest_evaluable_it_lints_with_PHP__CodeSniffer_using_project_config":0.03,"P\\Tests\\Feature\\PhpCsFixerConfigOverrideTest::__pest_evaluable_it_lints_with_PHP_CS_Fixer_using_project_config":0.035,"P\\Tests\\Feature\\PintConfigOverrideTest::__pest_evaluable_it_lints_with_pint_using_project_config":0.031,"P\\Tests\\Feature\\TLintConfigOverrideTest::__pest_evaluable_it_lints_with_tlint_using_project_config":0.038,"P\\Tests\\Unit\\DusterConfigTest::__pest_evaluable_it_provides_config_values":0,"P\\Tests\\Unit\\DusterConfigTest::__pest_evaluable_it_provides_default_exclude_config_values":0,"P\\Tests\\Unit\\DusterConfigTest::__pest_evaluable_it_merges_provided_exclude_with_default_exclude_config_values":0,"P\\Tests\\Fixer\\ClassNotation\\CustomControllerOrder\\CustomControllerOrderFixerTest::__pest_evaluable_it_fixes_controller_class_order#('<?phpnamespace App\\Http\\C\u2026){}}', '<?phpnamespace App\\Http\\C\u2026){}}') #1":0.169,"P\\Tests\\Fixer\\ClassNotation\\CustomControllerOrder\\CustomControllerOrderFixerTest::__pest_evaluable_it_fixes_controller_class_order#('<?phpnamespace App\\Http\\C\u2026){}}', '<?phpnamespace App\\Http\\C\u2026){}}') #2":0.113,"P\\Tests\\Fixer\\ClassNotation\\CustomControllerOrder\\CustomControllerOrderFixerTest::__pest_evaluable_it_fixes_controller_class_order#('<?phpnamespace Some\\Other\u2026){}}', '<?phpnamespace Some\\Other\u2026){}}')":0.115,"P\\Tests\\Fixer\\ClassNotation\\CustomOrderedClassElements\\CustomOrderedClassElementsFixerTest::__pest_evaluable_it_fixes_class_order#('<?phpclass Example_Staff\\\u2026){}}', '<?phpclass Example_Staff\\\u2026){}}')":0.117,"P\\Tests\\Fixer\\ClassNotation\\CustomPhpUnitOrder\\CustomPhpUnitOrderFixerTest::__pest_evaluable_it_fixes_PHPUnit_class_order#('<?phpnamespace Tests\\Feat\u2026 }}', '<?phpnamespace Tests\\Feat\u2026 }}')":0.117,"P\\Tests\\Fixer\\ClassNotation\\CustomPhpUnitOrder\\CustomPhpUnitOrderFixerTest::__pest_evaluable_it_fixes_PHPUnit_class_order#('<?phpnamespace App\\Consol\u2026 }}', '<?phpnamespace App\\Consol\u2026 }}')":0.115}}
20 changes: 20 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,23 @@ When working locally you will need to install the dev dependencies.
```bash
COMPOSER=composer-dev.json composer install
```

## Dependencies

To update dependencies to latest:

```bash
# Production
composer require friendsofphp/php-cs-fixer laravel/pint squizlabs/php_codesniffer tightenco/tlint --dev

# Development
COMPOSER=composer-dev.json composer require friendsofphp/php-cs-fixer laravel/pint squizlabs/php_codesniffer tightenco/tlint --dev
```

## PHPStan

If PHPStan fails locally, try increasing the memory:

```bash
./vendor/bin/phpstan analyze --memory-limit 1G
```
3 changes: 1 addition & 2 deletions app/Actions/Clean.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ class Clean
public function __construct(
protected string $mode,
protected array $tools,
) {
}
) {}

public function execute(): int
{
Expand Down
4 changes: 1 addition & 3 deletions app/Contracts/PintInputInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

use Symfony\Component\Console\Input\InputInterface;

interface PintInputInterface extends InputInterface
{
}
interface PintInputInterface extends InputInterface {}
69 changes: 35 additions & 34 deletions app/Fixer/ClassNotation/CustomControllerOrderFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,6 @@ public function getName(): string
return 'Tighten/custom_controller_order';
}

public function configure(array $configuration): void
{
$configuration['order'] = [
'use_trait',
'property_public_static',
'property_protected_static',
'property_private_static',
'constant_public',
'constant_protected',
'constant_private',
'property_public',
'property_protected',
'property_private',
'construct',
'method:__invoke',
'method_public_static',
'method_protected_static',
'method_private_static',
'method:index',
'method:create',
'method:store',
'method:show',
'method:edit',
'method:update',
'method:destroy',
'method_public',
'method_protected',
'method_private',
'magic',
];

parent::configure($configuration);
}

/**
* {@inheritdoc}
*
Expand Down Expand Up @@ -103,6 +69,41 @@ public function isControllerClass(Tokens $tokens, int $index): bool
return false;
}

/**
* @param array<string, mixed> $configuration
*/
protected function configurePreNormalisation(array &$configuration): void
{
$configuration['order'] = $configuration['order'] ?? [
'use_trait',
'property_public_static',
'property_protected_static',
'property_private_static',
'constant_public',
'constant_protected',
'constant_private',
'property_public',
'property_protected',
'property_private',
'construct',
'method:__invoke',
'method_public_static',
'method_protected_static',
'method_private_static',
'method:index',
'method:create',
'method:store',
'method:show',
'method:edit',
'method:update',
'method:destroy',
'method_public',
'method_protected',
'method_private',
'magic',
];
}

protected function applyFix(SplFileInfo $file, Tokens $tokens): void
{
for ($index = $tokens->count() - 1; $index > 0; $index--) {
Expand Down
Loading

0 comments on commit 7b138e5

Please sign in to comment.