From 7b0ccb91bf91119e823bed68d7fa322350703d60 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Thu, 21 Aug 2025 19:43:46 +0200 Subject: [PATCH] [TASK] Add `thecodingmachine/safe` (#1453) Safe-PHP https://github.com/thecodingmachine/safe provides rewrites of PHP functions to throw an exception instead of returning `false` when an error is encountered. This will allow us to drop out custom `preg_*` wrapper class and to increase type safety in our codebase. Also drop the PHP-CS-Fixer rule that adds a trailing backslash to calls to native PHP functions (as this would change the Safe-PHP calls back to their unsafe versions). The actual code changes will come in subsequent commits. Part of #1168 --- .github/dependabot.yml | 1 + composer.json | 3 ++- config/php-cs-fixer.php | 1 - 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 48f2db4f5..ae39e76b9 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -21,6 +21,7 @@ updates: - dependency-name: "phpunit/phpunit" versions: [ ">= 9.0.0" ] - dependency-name: "rector/rector" + - dependency-name: "thecodingmachine/safe" versioning-strategy: "increase" commit-message: prefix: "[Dependabot] " diff --git a/composer.json b/composer.json index d431ad43c..8a1c49a36 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,8 @@ "homepage": "https://www.sabberworm.com/blog/2010/6/10/php-css-parser", "require": { "php": "^7.2.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0", - "ext-iconv": "*" + "ext-iconv": "*", + "thecodingmachine/safe": "^1.3 || ^2.5 || ^3.3" }, "require-dev": { "php-parallel-lint/php-parallel-lint": "1.4.0", diff --git a/config/php-cs-fixer.php b/config/php-cs-fixer.php index 96b39bbbe..c10bf59ae 100644 --- a/config/php-cs-fixer.php +++ b/config/php-cs-fixer.php @@ -40,7 +40,6 @@ 'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false], // function notation - 'native_function_invocation' => ['include' => ['@all']], 'nullable_type_declaration_for_default_null_value' => true, // import