Skip to content

Commit

Permalink
Merge pull request #265 from palantirnet/feature/codestyle
Browse files Browse the repository at this point in the history
Add php-cs-fixer
  • Loading branch information
agentrickard authored Nov 14, 2023
2 parents 2ef08b0 + 5e16a5d commit 4f18bd5
Show file tree
Hide file tree
Showing 152 changed files with 1,269 additions and 1,074 deletions.
15 changes: 10 additions & 5 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
; This file is for unifying the coding style for different editors and IDEs.
; More information at https://editorconfig.org

root = true

# All files.
[*]
end_of_line = LF
indent_style = space
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
indent_size = 4
indent_style = space
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[composer.{json,lock}]
indent_size = 4
24 changes: 24 additions & 0 deletions .github/workflows/codestyle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: php-cs-fixer

# This test will run on every pull request, and on every commit on any branch
on: [push, pull_request]

jobs:
php-cs-fixer:
name: Codestyle checks with php-cs-fixer
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2
with:
php-version: 8.1
coverage: none # disable xdebug, pcov
tools: composer:v2
extensions: zip
# Uncomment to enable SSH access to Github Actions - https://github.com/marketplace/actions/debugging-with-tmate#getting-started
# - name: Debugging with tmate
# uses: mxschmitt/action-tmate@v2
# END: SHARED SETUP

- run: composer install
- run: composer check-style
47 changes: 0 additions & 47 deletions .github/workflows/drupal_rector_sandbox.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ jobs:
# END: SHARED SETUP

- run: composer install
- run: php vendor/bin/phpstan
- run: composer phpstan
2 changes: 1 addition & 1 deletion .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:
coverage: none
tools: composer:v2
- run: composer install
- run: vendor/bin/phpunit --testdox
- run: composer test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Ignore all hidden files exept these.
.*
!/.php-cs-fixer.dist.php
!/.github
!/.gitignore
!/.gitattributes
Expand Down
25 changes: 25 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

$finder = (new PhpCsFixer\Finder())
->in([
__DIR__.'/src',
__DIR__.'/tests',
__DIR__.'/config/drupal-*',
])
;

return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'array_syntax' => ['syntax' => 'short'],
'linebreak_after_opening_tag' => true,
'ordered_imports' => true,
'phpdoc_add_missing_param_annotation' => true,
'phpdoc_order' => true,
'yoda_style' => false,
'no_superfluous_phpdoc_tags' => false,
'declare_strict_types' => true,
])
->setFinder($finder)
;
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"require-dev": {
"php": "^8.1",
"cweagans/composer-patches": "^1.7.2",
"friendsofphp/php-cs-fixer": "^3.38",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^1.0",
"phpstan/phpstan-deprecation-rules": "^1.0",
Expand All @@ -79,6 +80,8 @@
"scripts": {
"docs": "vendor/bin/rule-doc-generator generate src/ --categorize=3",
"test": "vendor/bin/phpunit",
"phpstan": "vendor/bin/phpstan analyse --memory-limit=2G"
"phpstan": "vendor/bin/phpstan analyse --memory-limit=2G",
"check-style": "vendor/bin/php-cs-fixer check",
"fix-style": "vendor/bin/php-cs-fixer fix"
}
}
5 changes: 1 addition & 4 deletions config/drupal-10/drupal-10-all-deprecations.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

use DrupalRector\Set\Drupal10SetList;
use Rector\Config\RectorConfig;
use Rector\PHPUnit\Set\PHPUnitLevelSetList;
use Rector\Symfony\Set\SymfonyLevelSetList;
use Rector\Symfony\Set\TwigLevelSetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->sets([
Expand All @@ -15,6 +12,6 @@
]);

$rectorConfig->bootstrapFiles([
__DIR__ . '/../drupal-phpunit-bootstrap-file.php'
__DIR__.'/../drupal-phpunit-bootstrap-file.php',
]);
};
1 change: 0 additions & 1 deletion config/drupal-10/drupal-10.0-deprecations.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

declare(strict_types=1);

use DrupalRector\Set\Drupal10SetList;
use Rector\Config\RectorConfig;
use Rector\PHPUnit\Set\PHPUnitLevelSetList;
use Rector\Symfony\Set\SymfonyLevelSetList;
Expand Down
2 changes: 1 addition & 1 deletion config/drupal-10/drupal-10.1-deprecations.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

declare(strict_types=1);

use DrupalRector\Rector\Deprecation\FunctionToStaticRector;
use DrupalRector\Drupal10\Rector\Deprecation\WatchdogExceptionRector;
use DrupalRector\Rector\Deprecation\FunctionToStaticRector;
use DrupalRector\Rector\ValueObject\DrupalIntroducedVersionConfiguration;
use DrupalRector\Rector\ValueObject\FunctionToStaticConfiguration;
use Rector\Config\RectorConfig;
Expand Down
3 changes: 1 addition & 2 deletions config/drupal-8/drupal-8-all-deprecations.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Rector\PHPUnit\Set\PHPUnitSetList;

return static function (RectorConfig $rectorConfig): void {

$rectorConfig->sets([
PHPUnitSetList::PHPUNIT_60,
PHPUnitSetList::PHPUNIT_70,
Expand All @@ -30,6 +29,6 @@
]);

$rectorConfig->bootstrapFiles([
__DIR__ . '/../drupal-phpunit-bootstrap-file.php'
__DIR__.'/../drupal-phpunit-bootstrap-file.php',
]);
};
8 changes: 3 additions & 5 deletions config/drupal-8/drupal-8.0-deprecations.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
use DrupalRector\Drupal8\Rector\Deprecation\EntityLoadRector;
use DrupalRector\Drupal8\Rector\Deprecation\EntityManagerRector;
use DrupalRector\Drupal8\Rector\Deprecation\EntityViewRector;
use DrupalRector\Rector\Deprecation\FunctionToServiceRector;
use DrupalRector\Drupal8\Rector\Deprecation\LinkGeneratorTraitLRector;
use DrupalRector\Rector\Deprecation\MethodToMethodWithCheckRector;
use DrupalRector\Drupal8\Rector\Deprecation\SafeMarkupFormatRector;
use DrupalRector\Drupal8\Rector\ValueObject\DBConfiguration;
use DrupalRector\Drupal8\Rector\ValueObject\EntityLoadConfiguration;
use DrupalRector\Rector\Deprecation\FunctionToServiceRector;
use DrupalRector\Rector\Deprecation\MethodToMethodWithCheckRector;
use DrupalRector\Rector\ValueObject\FunctionToServiceConfiguration;
use DrupalRector\Rector\ValueObject\MethodToMethodWithCheckConfiguration;
use DrupalRector\Services\AddCommentService;
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->singleton(AddCommentService::class, function() {
$rectorConfig->singleton(AddCommentService::class, function () {
return new AddCommentService();
});

Expand All @@ -41,7 +41,6 @@
$rectorConfig->rule(EntityCreateRector::class);
$rectorConfig->rule(EntityDeleteMultipleRector::class);


$rectorConfig->ruleWithConfiguration(FunctionToServiceRector::class, [
// https://www.drupal.org/node/2418133
new FunctionToServiceConfiguration('drupal_realpath', 'file_system', 'realpath'),
Expand All @@ -51,7 +50,6 @@
new FunctionToServiceConfiguration('drupal_render_root', 'renderer', 'renderRoot'),
// https://www.drupal.org/node/1876852
new FunctionToServiceConfiguration('format_date', 'date.formatter', 'format'),

]);

$rectorConfig->rule(EntityInterfaceLinkRector::class);
Expand Down
2 changes: 1 addition & 1 deletion config/drupal-8/drupal-8.1-deprecations.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->singleton(AddCommentService::class, function() {
$rectorConfig->singleton(AddCommentService::class, function () {
return new AddCommentService();
});
};
2 changes: 1 addition & 1 deletion config/drupal-8/drupal-8.2-deprecations.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->singleton(AddCommentService::class, function() {
$rectorConfig->singleton(AddCommentService::class, function () {
return new AddCommentService();
});
// https://www.drupal.org/node/2802569
Expand Down
2 changes: 1 addition & 1 deletion config/drupal-8/drupal-8.3-deprecations.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->singleton(AddCommentService::class, function() {
$rectorConfig->singleton(AddCommentService::class, function () {
return new AddCommentService();
});
$rectorConfig->rule(RequestTimeConstRector::class);
Expand Down
2 changes: 1 addition & 1 deletion config/drupal-8/drupal-8.4-deprecations.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->singleton(AddCommentService::class, function() {
$rectorConfig->singleton(AddCommentService::class, function () {
return new AddCommentService();
});
// https://www.drupal.org/node/2907725
Expand Down
4 changes: 2 additions & 2 deletions config/drupal-8/drupal-8.5-deprecations.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->singleton(AddCommentService::class, function() {
$rectorConfig->singleton(AddCommentService::class, function () {
return new AddCommentService();
});
$rectorConfig->rule(DrupalSetMessageRector::class);

/**
/*
* Replaces deprecated DATETIME_DATE_STORAGE_FORMAT, DATETIME_DATETIME_STORAGE_FORMAT, DATETIME_STORAGE_TIMEZONE constant use.
*
* See https://www.drupal.org/node/2912980 for change record.
Expand Down
2 changes: 1 addition & 1 deletion config/drupal-8/drupal-8.6-deprecations.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->singleton(AddCommentService::class, function() {
$rectorConfig->singleton(AddCommentService::class, function () {
return new AddCommentService();
});
$rectorConfig->ruleWithConfiguration(\DrupalRector\Drupal8\Rector\Deprecation\StaticToFunctionRector::class, [
Expand Down
5 changes: 2 additions & 3 deletions config/drupal-8/drupal-8.7-deprecations.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
declare(strict_types=1);

use DrupalRector\Drupal8\Rector\Deprecation\ConstantToClassConstantRector;
use DrupalRector\Rector\Deprecation\FunctionToServiceRector;
use DrupalRector\Drupal8\Rector\ValueObject\ConstantToClassConfiguration;
use DrupalRector\Rector\Deprecation\FunctionToServiceRector;
use DrupalRector\Rector\ValueObject\FunctionToServiceConfiguration;
use DrupalRector\Services\AddCommentService;
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->singleton(AddCommentService::class, function() {
$rectorConfig->singleton(AddCommentService::class, function () {
return new AddCommentService();
});
$rectorConfig->ruleWithConfiguration(FunctionToServiceRector::class, [
Expand All @@ -20,7 +20,6 @@
new FunctionToServiceConfiguration('file_unmanaged_save_data', 'file_system', 'saveData'),
]);


/**
* Replaces deprecated FILE_CREATE_DIRECTORY constant use.
*
Expand Down
32 changes: 16 additions & 16 deletions config/drupal-8/drupal-8.8-deprecations.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

declare(strict_types=1);

use DrupalRector\Rector\Deprecation\MethodToMethodWithCheckRector;
use DrupalRector\Drupal8\Rector\Deprecation\FileDefaultSchemeRector;
use DrupalRector\Drupal8\Rector\Deprecation\DrupalServiceRenameRector;
use DrupalRector\Rector\Deprecation\FunctionToServiceRector;
use DrupalRector\Drupal8\Rector\Deprecation\FileDefaultSchemeRector;
use DrupalRector\Drupal8\Rector\ValueObject\DrupalServiceRenameConfiguration;
use DrupalRector\Rector\Deprecation\FunctionToServiceRector;
use DrupalRector\Rector\Deprecation\MethodToMethodWithCheckRector;
use DrupalRector\Rector\ValueObject\FunctionToServiceConfiguration;
use DrupalRector\Rector\ValueObject\MethodToMethodWithCheckConfiguration;
use DrupalRector\Services\AddCommentService;
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->singleton(AddCommentService::class, function() {
$rectorConfig->singleton(AddCommentService::class, function () {
return new AddCommentService();
});
$rectorConfig->ruleWithConfiguration(DrupalServiceRenameRector::class, [
Expand All @@ -27,18 +27,18 @@
$rectorConfig->rule(FileDefaultSchemeRector::class);

$rectorConfig->ruleWithConfiguration(FunctionToServiceRector::class,
[
// https://www.drupal.org/node/2835616
new FunctionToServiceConfiguration('entity_get_display', 'entity_display.repository', 'getViewDisplay'),
// https://www.drupal.org/node/2835616
new FunctionToServiceConfiguration('entity_get_form_display', 'entity_display.repository', 'getFormDisplay'),
// https://www.drupal.org/node/3039255
new FunctionToServiceConfiguration('file_directory_temp', 'file_system', 'getTempDirectory'),
// https://www.drupal.org/node/3038437
new FunctionToServiceConfiguration('file_scan_directory', 'file_system', 'scanDirectory'),
// https://www.drupal.org/node/3035273
new FunctionToServiceConfiguration('file_uri_target', 'stream_wrapper_manager', 'getTarget'),
]);
[
// https://www.drupal.org/node/2835616
new FunctionToServiceConfiguration('entity_get_display', 'entity_display.repository', 'getViewDisplay'),
// https://www.drupal.org/node/2835616
new FunctionToServiceConfiguration('entity_get_form_display', 'entity_display.repository', 'getFormDisplay'),
// https://www.drupal.org/node/3039255
new FunctionToServiceConfiguration('file_directory_temp', 'file_system', 'getTempDirectory'),
// https://www.drupal.org/node/3038437
new FunctionToServiceConfiguration('file_scan_directory', 'file_system', 'scanDirectory'),
// https://www.drupal.org/node/3035273
new FunctionToServiceConfiguration('file_uri_target', 'stream_wrapper_manager', 'getTarget'),
]);

$rectorConfig->ruleWithConfiguration(MethodToMethodWithCheckRector::class, [
// https://www.drupal.org/node/3075567
Expand Down
Loading

0 comments on commit 4f18bd5

Please sign in to comment.