Просмотр исходного кода

fix: `ExecutorWithoutErrorHandler` - remove invalid PHP 7.4 type (#7845)

Kuba Werłos 1 год назад
Родитель
Сommit
0edbfb9762

+ 2 - 0
.php-cs-fixer.php-lowest.php

@@ -26,6 +26,8 @@ $config->getFinder()->notPath([
     'src/DocBlock/Annotation.php',
     'src/Doctrine/Annotation/Tokens.php',
     'src/Tokenizer/Tokens.php',
+    // @TODO add `mixed` return type to `ExecutorWithoutErrorHandler::execute` when PHP 8.0+ is required and remove the exception from this list
+    'src/ExecutorWithoutErrorHandler.php',
 ]);
 
 $config->setRules([

+ 1 - 1
src/ExecutorWithoutErrorHandler.php

@@ -32,7 +32,7 @@ final class ExecutorWithoutErrorHandler
      *
      * @throws ExecutorWithoutErrorHandlerException
      */
-    public static function execute(callable $callback): mixed
+    public static function execute(callable $callback)
     {
         /** @var ?string */
         $error = null;

+ 0 - 2
tests/AutoReview/ProjectCodeTest.php

@@ -27,7 +27,6 @@ use PhpCsFixer\Documentation\DocumentationLocator;
 use PhpCsFixer\Documentation\FixerDocumentGenerator;
 use PhpCsFixer\Documentation\RstUtils;
 use PhpCsFixer\Documentation\RuleSetDocumentationGenerator;
-use PhpCsFixer\ExecutorWithoutErrorHandler;
 use PhpCsFixer\ExecutorWithoutErrorHandlerException;
 use PhpCsFixer\Fixer\AbstractPhpUnitFixer;
 use PhpCsFixer\Fixer\PhpUnit\PhpUnitNamespacedFixer;
@@ -81,7 +80,6 @@ final class ProjectCodeTest extends TestCase
         DocLexer::class,
         DocumentationCommand::class,
         DocumentationLocator::class,
-        ExecutorWithoutErrorHandler::class,
         ExecutorWithoutErrorHandlerException::class,
         FileCachingLintingIterator::class,
         FixerDocumentGenerator::class,

+ 43 - 0
tests/ExecutorWithoutErrorHandlerTest.php

@@ -0,0 +1,43 @@
+<?php
+
+declare(strict_types=1);
+
+/*
+ * This file is part of PHP CS Fixer.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *     Dariusz Rumiński <dariusz.ruminski@gmail.com>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace PhpCsFixer\Tests;
+
+use PhpCsFixer\ExecutorWithoutErrorHandler;
+use PhpCsFixer\ExecutorWithoutErrorHandlerException;
+
+/**
+ * @internal
+ *
+ * @covers \PhpCsFixer\ExecutorWithoutErrorHandler
+ */
+final class ExecutorWithoutErrorHandlerTest extends TestCase
+{
+    public function testWithError(): void
+    {
+        $this->expectException(ExecutorWithoutErrorHandlerException::class);
+        $this->expectExceptionMessageMatches('/preg_match\(\): Delimiter must not be alphanumeric/');
+
+        // @phpstan-ignore-next-line
+        ExecutorWithoutErrorHandler::execute(static fn () => preg_match('bad pattern', ''));
+    }
+
+    public function testWithoutError(): void
+    {
+        self::assertSame(
+            1,
+            ExecutorWithoutErrorHandler::execute(static fn () => preg_match('/./', 'a'))
+        );
+    }
+}