From b5b673552927822fe604986b586e7f7b81b7f4f2 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 22 May 2026 17:20:50 +0200 Subject: [PATCH 1/3] Migrate form PHP_CodeSniffer to Mago for code linting and formatting --- .gitattributes | 2 +- CHANGELOG.md | 17 ++++++++++++ composer.json | 12 ++++++--- mago.toml | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++ phpcs.xml | 14 ---------- 5 files changed, 98 insertions(+), 19 deletions(-) create mode 100644 mago.toml delete mode 100644 phpcs.xml diff --git a/.gitattributes b/.gitattributes index ec03375..d486550 100644 --- a/.gitattributes +++ b/.gitattributes @@ -6,5 +6,5 @@ CHANGELOG.md export-ignore docker-compose.override.yml.dist export-ignore docker-compose.yml export-ignore indocker export-ignore -phpcs.xml export-ignore +mago.toml export-ignore phpstan.neon export-ignore diff --git a/CHANGELOG.md b/CHANGELOG.md index d7629f6..3f8ce35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org). +## [Unreleased] +### Added +* *Nothing* + +### Changed +* Migrate form PHP_CodeSniffer to Mago for code linting and formatting. + +### Deprecated +* *Nothing* + +### Removed +* *Nothing* + +### Fixed +* *Nothing* + + ## [1.3.0] - 2026-01-07 ### Added * *Nothing* diff --git a/composer.json b/composer.json index 3b01a89..5c43601 100644 --- a/composer.json +++ b/composer.json @@ -15,9 +15,9 @@ "php": "^8.4" }, "require-dev": { + "carthage-software/mago": "^1.28", "phpstan/phpstan": "^2.1", - "roave/security-advisories": "dev-master", - "shlinkio/php-coding-standard": "~2.5.0" + "roave/security-advisories": "dev-master" }, "autoload": { "files": [ @@ -29,8 +29,12 @@ "@cs", "@stan" ], - "cs": "phpcs", - "cs:fix": "phpcbf", + "lint": "mago lint", + "lint:fix": "mago lint --fix", + "format": "mago format", + "format:check": "mago format --check", + "cs": ["@lint", "@format:check"], + "cs:fix": ["@lint:fix", "@format"], "stan": "phpstan analyse" }, "scripts-descriptions": { diff --git a/mago.toml b/mago.toml new file mode 100644 index 0000000..2c19c9e --- /dev/null +++ b/mago.toml @@ -0,0 +1,72 @@ +#:schema https://mago.carthage.software/1.27.1/schema.json +# Welcome to Mago! +# For full documentation, see https://mago.carthage.software/tools/overview +version = "1" +php-version = "8.4.0" + +[source] +workspace = "." +paths = ["config", "functions", "src", "test"] +excludes = ["vendor"] + +[source.glob] +literal-separator = true + +[formatter] +print-width = 120 +tab-width = 4 +use-tabs = false +null-type-hint = "null_pipe_last" +space-before-arrow-function-parameter-list-parenthesis = true +break-promoted-properties-list = false +parameter-attribute-on-new-line = false +preserve-breaking-member-access-chain = true +preserve-breaking-argument-list = true +preserve-breaking-array-like = true +preserve-breaking-parameter-list = true +preserve-breaking-attribute-list = true +preserve-breaking-conditional-expression = true +preserve-breaking-condition-expression = true +preserve-redundant-logical-binary-expression-parentheses = true + +[linter] +integrations = ["phpunit"] + +[linter.rules] +no-literal-password = { exclude = ["test"] } +no-empty-catch-clause = { exclude = ["test"] } +no-empty-loop = { exclude = ["test"] } + +prefer-static-closure = { level = "warning" } +array-style = { level = "warning" } +prefer-early-continue = { max_allowed_statements = 2 } +no-fully-qualified-global-class-like = { enabled = true, level = "warning" } +no-fully-qualified-global-constant = { enabled = true, level = "warning" } +no-fully-qualified-global-function = { enabled = true, level = "warning" } +ambiguous-constant-access = { enabled = true, level = "warning" } +ambiguous-function-call = { enabled = true, level = "warning" } + +no-multi-assignments = { enabled = false } +no-assign-in-condition = { enabled = false } +literal-named-argument = { enabled = false } +tagged-fixme = { enabled = false } +tagged-todo = { enabled = false } +no-boolean-flag-parameter = { enabled = false } +no-else-clause = { enabled = false } +no-isset = { enabled = false } +no-empty = { enabled = false } +no-shorthand-ternary = { enabled = false } +no-ini-set = { enabled = false } +too-many-enum-cases = { enabled = false } +function-name = { enabled = false } + +# TODO Fine tune these +too-many-methods = { enabled = false } +too-many-properties = { enabled = false } +excessive-parameter-list = { enabled = false } +cyclomatic-complexity = { enabled = false } +kan-defect = { enabled = false } +halstead = { effort-threshold = 7000, enabled = false } + +# TODO Enable this +sensitive-parameter = { enabled = false } diff --git a/phpcs.xml b/phpcs.xml deleted file mode 100644 index 9d280bb..0000000 --- a/phpcs.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - Coding standard - - - - - - - - - - functions - From 8dc9916b4fc55b14568f119c1db17ffc81f280c0 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 22 May 2026 17:22:21 +0200 Subject: [PATCH 2/3] Remove roave/security-advisories --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 5c43601..7e9b8b4 100644 --- a/composer.json +++ b/composer.json @@ -16,8 +16,7 @@ }, "require-dev": { "carthage-software/mago": "^1.28", - "phpstan/phpstan": "^2.1", - "roave/security-advisories": "dev-master" + "phpstan/phpstan": "^2.1" }, "autoload": { "files": [ From 402d335b54d342f79c9104bd8fb9f76f7f05924f Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 22 May 2026 18:06:41 +0200 Subject: [PATCH 3/3] Extend mago config from shlinkio/shlink-mago-config --- composer.json | 3 ++- mago.toml | 55 +-------------------------------------------------- 2 files changed, 3 insertions(+), 55 deletions(-) diff --git a/composer.json b/composer.json index 7e9b8b4..c5f7161 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,8 @@ }, "require-dev": { "carthage-software/mago": "^1.28", - "phpstan/phpstan": "^2.1" + "phpstan/phpstan": "^2.1", + "shlinkio/shlink-mago-config": "^1.0" }, "autoload": { "files": [ diff --git a/mago.toml b/mago.toml index 2c19c9e..66a18da 100644 --- a/mago.toml +++ b/mago.toml @@ -3,6 +3,7 @@ # For full documentation, see https://mago.carthage.software/tools/overview version = "1" php-version = "8.4.0" +extends = "vendor/shlinkio/shlink-mago-config/mago.toml" [source] workspace = "." @@ -12,61 +13,7 @@ excludes = ["vendor"] [source.glob] literal-separator = true -[formatter] -print-width = 120 -tab-width = 4 -use-tabs = false -null-type-hint = "null_pipe_last" -space-before-arrow-function-parameter-list-parenthesis = true -break-promoted-properties-list = false -parameter-attribute-on-new-line = false -preserve-breaking-member-access-chain = true -preserve-breaking-argument-list = true -preserve-breaking-array-like = true -preserve-breaking-parameter-list = true -preserve-breaking-attribute-list = true -preserve-breaking-conditional-expression = true -preserve-breaking-condition-expression = true -preserve-redundant-logical-binary-expression-parentheses = true - -[linter] -integrations = ["phpunit"] - [linter.rules] no-literal-password = { exclude = ["test"] } no-empty-catch-clause = { exclude = ["test"] } no-empty-loop = { exclude = ["test"] } - -prefer-static-closure = { level = "warning" } -array-style = { level = "warning" } -prefer-early-continue = { max_allowed_statements = 2 } -no-fully-qualified-global-class-like = { enabled = true, level = "warning" } -no-fully-qualified-global-constant = { enabled = true, level = "warning" } -no-fully-qualified-global-function = { enabled = true, level = "warning" } -ambiguous-constant-access = { enabled = true, level = "warning" } -ambiguous-function-call = { enabled = true, level = "warning" } - -no-multi-assignments = { enabled = false } -no-assign-in-condition = { enabled = false } -literal-named-argument = { enabled = false } -tagged-fixme = { enabled = false } -tagged-todo = { enabled = false } -no-boolean-flag-parameter = { enabled = false } -no-else-clause = { enabled = false } -no-isset = { enabled = false } -no-empty = { enabled = false } -no-shorthand-ternary = { enabled = false } -no-ini-set = { enabled = false } -too-many-enum-cases = { enabled = false } -function-name = { enabled = false } - -# TODO Fine tune these -too-many-methods = { enabled = false } -too-many-properties = { enabled = false } -excessive-parameter-list = { enabled = false } -cyclomatic-complexity = { enabled = false } -kan-defect = { enabled = false } -halstead = { effort-threshold = 7000, enabled = false } - -# TODO Enable this -sensitive-parameter = { enabled = false }