Skip to content

Commit

Permalink
Fix phpstan v1.10.50 (#2135)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek authored Dec 16, 2023
1 parent 33ec62c commit 492dab9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 49 deletions.
4 changes: 2 additions & 2 deletions docs/view.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ Injection.
Consider the following example:

```
$app->debug = new Logger('log'); // Monolog
$app->logger = new Logger('log'); // Monolog
// next, somewhere in a render tree
$view->getApp()->debug->log('Foo Bar');
$view->getApp()->logger->log('Foo Bar');
```

Agile UI will automatically pass your $app class to all the views.
Expand Down
10 changes: 0 additions & 10 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@ parameters:
- '~^Only booleans are allowed in .+, .+ given( on the (left|right) side)?\.~'
- '~^Variable (static )?(property access|method call) on .+\.~'

# remove once PHPUnit 9.x support is removed
-
path: 'tests/DemosTest.php'
message: '~^Access to constant (STATUS_PASSED|STATUS_INCOMPLETE|STATUS_SKIPPED) on an unknown class PHPUnit\\Runner\\BaseTestRunner\.$~'
count: 3
-
path: 'tests/DemosTest.php'
message: '~^Call to an undefined method Atk4\\Ui\\Tests\\DemosTest::(getName|getStatus)\(\)\.$~'
count: 4

# TODO these rules are generated, this ignores should be fixed in the code
# for level = 2
-
Expand Down
35 changes: 17 additions & 18 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class App
use DynamicMethodTrait;
use HookTrait;

private const UNSUPPRESSEABLE_ERROR_LEVELS = \PHP_MAJOR_VERSION >= 8 ? (\E_ERROR | \E_PARSE | \E_CORE_ERROR | \E_COMPILE_ERROR | \E_USER_ERROR | \E_RECOVERABLE_ERROR) : 0;

public const HOOK_BEFORE_EXIT = self::class . '@beforeExit';
public const HOOK_BEFORE_RENDER = self::class . '@beforeRender';

Expand Down Expand Up @@ -182,7 +184,7 @@ public function __construct(array $defaults = [])
if ($this->catchExceptions) {
set_exception_handler(\Closure::fromCallable([$this, 'caughtException']));
set_error_handler(static function (int $severity, string $msg, string $file, int $line): bool {
if ((error_reporting() & ~(\PHP_MAJOR_VERSION >= 8 ? (\E_ERROR | \E_PARSE | \E_CORE_ERROR | \E_COMPILE_ERROR | \E_USER_ERROR | \E_RECOVERABLE_ERROR) : 0)) === 0) {
if ((error_reporting() & ~self::UNSUPPRESSEABLE_ERROR_LEVELS) === 0) {
$isFirstFrame = true;
foreach (array_slice(debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 10), 1) as $frame) {
// allow to suppress any warning outside Atk4
Expand Down Expand Up @@ -281,7 +283,7 @@ public function callExit(): void
exit;
}

public function caughtException(\Throwable $exception): void
protected function caughtException(\Throwable $exception): void
{
if ($exception instanceof LateOutputError) {
$this->outputLateOutputError($exception);
Expand Down Expand Up @@ -1105,24 +1107,21 @@ public function renderExceptionHtml(\Throwable $exception): string

protected function setupAlwaysRun(): void
{
register_shutdown_function(
function () {
if (!$this->runCalled) {
try {
$this->run();
} catch (ExitApplicationError $e) {
// let the process go and stop on ->callExit below
} catch (\Throwable $e) {
// set_exception_handler does not work in shutdown
// https://github.com/php/php-src/issues/10695
$this->caughtException($e);
}

// call with true to trigger beforeExit event
$this->callBeforeExit();
register_shutdown_function(function () {
if (!$this->runCalled) {
try {
$this->run();
} catch (ExitApplicationError $e) {
// let the process continue and terminate using self::callExit() below
} catch (\Throwable $e) {
// set_exception_handler does not work in shutdown
// https://github.com/php/php-src/issues/10695
$this->caughtException($e);
}

$this->callBeforeExit();
}
);
});
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Behat/MinkSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function __construct(\Behat\Mink\Session $session)
{
$driver = new MinkSeleniumDriver($session->getDriver()); // @phpstan-ignore-line

parent::__construct($driver, $session->getSelectorsHandler());
parent::__construct($driver, $session->getSelectorsHandler()); // @phpstan-ignore-line
}

#[\Override]
Expand Down
18 changes: 0 additions & 18 deletions tests/DemosTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Atk4\Ui\Layout;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
use PHPUnit\Runner\BaseTestRunner;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

Expand All @@ -32,9 +31,6 @@ class DemosTest extends TestCase

private static ?Persistence $_db = null;

/** @var array<string, int> */
private static array $_failedParentTests = [];

#[\Override]
public static function setUpBeforeClass(): void
{
Expand Down Expand Up @@ -77,20 +73,6 @@ protected function setUp(): void
}
}

#[\Override]
protected function _onNotSuccessfulTest(\Throwable $t): void
{
if (self::isPhpunit9x() ? !in_array($this->getStatus(), [BaseTestRunner::STATUS_PASSED, BaseTestRunner::STATUS_SKIPPED, BaseTestRunner::STATUS_INCOMPLETE], true) : !$this->status()->isSuccess() && !$this->status()->isSkipped() && !$this->status()->isIncomplete()) {
if (!isset(self::$_failedParentTests[self::isPhpunit9x() ? $this->getName() : $this->nameWithDataSet()])) {
self::$_failedParentTests[self::isPhpunit9x() ? $this->getName() : $this->nameWithDataSet()] = self::isPhpunit9x() ? $this->getStatus() : $this->status()->asInt();
} else {
self::markTestIncomplete('Test failed, but non-HTTP test failed too, fix it first');
}
}

throw $t;
}

protected function setSuperglobalsFromRequest(RequestInterface $request): void
{
$this->resetSuperglobals();
Expand Down

0 comments on commit 492dab9

Please sign in to comment.