From 3f9cd0ab3c142f2a25b796499bdce9f40f109f3c Mon Sep 17 00:00:00 2001 From: Jean-Yves <7360784+docjyJ@users.noreply.github.com> Date: Wed, 2 Oct 2024 14:09:29 +0200 Subject: [PATCH] nextcloud/coding-standard Signed-off-by: Jean-Yves <7360784+docjyJ@users.noreply.github.com> --- .github/workflows/lint-php-cs.yml | 52 +++++++++++ .gitignore | 3 +- php/.php-cs-fixer.dist.php | 18 ++++ php/composer.json | 6 +- php/composer.lock | 142 +++++++++++++++++++++++++++++- 5 files changed, 218 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/lint-php-cs.yml create mode 100644 php/.php-cs-fixer.dist.php diff --git a/.github/workflows/lint-php-cs.yml b/.github/workflows/lint-php-cs.yml new file mode 100644 index 00000000000..d27ad5774f3 --- /dev/null +++ b/.github/workflows/lint-php-cs.yml @@ -0,0 +1,52 @@ +# This workflow is provided via the organization template repository +# +# https://github.com/nextcloud/.github +# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization +# +# SPDX-FileCopyrightText: 2021-2024 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: MIT + +name: Lint php-cs + +on: + pull_request: + paths: + - 'php/**' + push: + branches: + - main + paths: + - 'php/**' + +permissions: + contents: read + +concurrency: + group: lint-php-cs-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + lint: + runs-on: ubuntu-latest + strategy: + matrix: + php-versions: [ "8.3" ] + + name: php-cs + + steps: + - name: Checkout + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + + - name: Set up php ${{ matrix.php-versions }} + uses: shivammathur/setup-php@a4e22b60bbb9c1021113f2860347b0759f66fe5d # v2 + with: + php-version: ${{ matrix.php-versions }} + coverage: none + ini-file: development + + - name: Install dependencies + run: cd php && composer i + + - name: Lint + run: cd php && composer run cs:check || ( echo 'Please run `composer run cs:fix` to format your code' && exit 1 ) diff --git a/.gitignore b/.gitignore index a9ac8d70383..bd811a40919 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,8 @@ /php/session/* !/php/data/.gitkeep !/php/session/.gitkeep -/php/vendor +/php/vendor/ +/php/.php-cs-fixer.cache /manual-install/*.conf !/manual-install/sample.conf diff --git a/php/.php-cs-fixer.dist.php b/php/.php-cs-fixer.dist.php new file mode 100644 index 00000000000..ff5670b7eb5 --- /dev/null +++ b/php/.php-cs-fixer.dist.php @@ -0,0 +1,18 @@ +getFinder() + ->ignoreVCSIgnored(true) + ->notPath('data') + ->notPath('session') + ->notPath('public') + ->notPath('vendor') + ->in(__DIR__); +return $config; diff --git a/php/composer.json b/php/composer.json index 3ac4ea36220..87fd97ac777 100644 --- a/php/composer.json +++ b/php/composer.json @@ -21,7 +21,9 @@ "require-dev": { "sserbin/twig-linter": "@dev", "vimeo/psalm": "^5.25", - "wapmorgan/php-deprecation-detector": "dev-master" + "wapmorgan/php-deprecation-detector": "dev-master", + "nextcloud/coding-standard": "^1.3", + "friendsofphp/php-cs-fixer": "^3" }, "scripts": { "dev": [ @@ -32,6 +34,8 @@ "psalm:update-baseline": "psalm --threads=1 --monochrome --no-progress --output-format=text --update-baseline", "lint": "php -l src/*.php src/**/*.php public/index.php", "lint:twig": "twig-linter lint ./templates", + "cs:check": "php-cs-fixer fix --dry-run --diff", + "cs:fix": "php-cs-fixer fix", "php-deprecation-detector": "phpdd scan -n -t 8.3 src/*.php src/**/*.php public/index.php" } } diff --git a/php/composer.lock b/php/composer.lock index a272206ef46..c2754261114 100644 --- a/php/composer.lock +++ b/php/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "0e1d24f3fa776163acefdebc91da39d3", + "content-hash": "b8bd0cb88d1582f9c4118112a24ac215", "packages": [ { "name": "guzzlehttp/guzzle", @@ -2416,6 +2416,52 @@ ], "time": "2024-08-06T10:04:20+00:00" }, + { + "name": "kubawerlos/php-cs-fixer-custom-fixers", + "version": "v3.22.0", + "source": { + "type": "git", + "url": "https://github.com/kubawerlos/php-cs-fixer-custom-fixers.git", + "reference": "8701394f0c7cd450ac4fa577d24589122c1d5d5e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/kubawerlos/php-cs-fixer-custom-fixers/zipball/8701394f0c7cd450ac4fa577d24589122c1d5d5e", + "reference": "8701394f0c7cd450ac4fa577d24589122c1d5d5e", + "shasum": "" + }, + "require": { + "ext-filter": "*", + "ext-tokenizer": "*", + "friendsofphp/php-cs-fixer": "^3.61.1", + "php": "^7.4 || ^8.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.6.4 || ^10.5.29" + }, + "type": "library", + "autoload": { + "psr-4": { + "PhpCsFixerCustomFixers\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kuba Werłos", + "email": "werlos@gmail.com" + } + ], + "description": "A set of custom fixers for PHP CS Fixer", + "support": { + "issues": "https://github.com/kubawerlos/php-cs-fixer-custom-fixers/issues", + "source": "https://github.com/kubawerlos/php-cs-fixer-custom-fixers/tree/v3.22.0" + }, + "time": "2024-08-16T20:44:35+00:00" + }, { "name": "netresearch/jsonmapper", "version": "v4.5.0", @@ -2467,6 +2513,48 @@ }, "time": "2024-09-08T10:13:13+00:00" }, + { + "name": "nextcloud/coding-standard", + "version": "v1.3.1", + "source": { + "type": "git", + "url": "https://github.com/nextcloud/coding-standard.git", + "reference": "e88acb0df6217b808d1632286ddfec9267a102e4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nextcloud/coding-standard/zipball/e88acb0df6217b808d1632286ddfec9267a102e4", + "reference": "e88acb0df6217b808d1632286ddfec9267a102e4", + "shasum": "" + }, + "require": { + "kubawerlos/php-cs-fixer-custom-fixers": "^3.22", + "php": "^7.3|^8.0", + "php-cs-fixer/shim": "^3.17" + }, + "type": "library", + "autoload": { + "psr-4": { + "Nextcloud\\CodingStandard\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Christoph Wurst", + "email": "christoph@winzerhof-wurst.at" + } + ], + "description": "Nextcloud coding standards for the php cs fixer", + "support": { + "issues": "https://github.com/nextcloud/coding-standard/issues", + "source": "https://github.com/nextcloud/coding-standard/tree/v1.3.1" + }, + "time": "2024-09-19T09:07:10+00:00" + }, { "name": "nikic/php-parser", "version": "v4.19.4", @@ -2523,6 +2611,58 @@ }, "time": "2024-09-29T15:01:53+00:00" }, + { + "name": "php-cs-fixer/shim", + "version": "v3.64.0", + "source": { + "type": "git", + "url": "https://github.com/PHP-CS-Fixer/shim.git", + "reference": "81ccfd24baf3a10810dab1152c403981a790b837" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHP-CS-Fixer/shim/zipball/81ccfd24baf3a10810dab1152c403981a790b837", + "reference": "81ccfd24baf3a10810dab1152c403981a790b837", + "shasum": "" + }, + "require": { + "ext-json": "*", + "ext-tokenizer": "*", + "php": "^7.4 || ^8.0" + }, + "replace": { + "friendsofphp/php-cs-fixer": "self.version" + }, + "suggest": { + "ext-dom": "For handling output formats in XML", + "ext-mbstring": "For handling non-UTF8 characters." + }, + "bin": [ + "php-cs-fixer", + "php-cs-fixer.phar" + ], + "type": "application", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Dariusz Rumiński", + "email": "dariusz.ruminski@gmail.com" + } + ], + "description": "A tool to automatically fix PHP code style", + "support": { + "issues": "https://github.com/PHP-CS-Fixer/shim/issues", + "source": "https://github.com/PHP-CS-Fixer/shim/tree/v3.64.0" + }, + "time": "2024-08-30T23:10:11+00:00" + }, { "name": "phpdocumentor/reflection-common", "version": "2.2.0",