From d4104850be0428d7fa84aed1999728032a88f5dd Mon Sep 17 00:00:00 2001 From: Thomas Rupprecht Date: Sat, 1 Apr 2023 14:39:25 +0200 Subject: [PATCH] phpstan fixes (partial level 3) (#1091) --- includes/pages/admin_rooms.php | 0 src/Controllers/Metrics/MetricsEngine.php | 2 +- src/Controllers/Metrics/Stats.php | 3 -- src/Exceptions/Handlers/Whoops.php | 6 +--- src/Helpers/BarChart.php | 6 ++-- src/Helpers/Schedule/CalculatesTime.php | 2 +- src/Helpers/Schedule/Event.php | 2 +- .../Unit/Controllers/OAuthControllerTest.php | 2 +- .../Controllers/SettingsControllerTest.php | 2 -- .../Stub/ControllerImplementation.php | 2 +- tests/Unit/Helpers/ShiftsTest.php | 2 +- .../Models/Stub/BaseModelImplementation.php | 32 ------------------- .../Unit/Renderer/TwigServiceProviderTest.php | 2 +- 13 files changed, 11 insertions(+), 52 deletions(-) delete mode 100644 includes/pages/admin_rooms.php delete mode 100644 tests/Unit/Models/Stub/BaseModelImplementation.php diff --git a/includes/pages/admin_rooms.php b/includes/pages/admin_rooms.php deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Controllers/Metrics/MetricsEngine.php b/src/Controllers/Metrics/MetricsEngine.php index ef2cd319..4ce0ad46 100644 --- a/src/Controllers/Metrics/MetricsEngine.php +++ b/src/Controllers/Metrics/MetricsEngine.php @@ -60,7 +60,7 @@ class MetricsEngine implements EngineInterface } /** - * @return array[] + * @return string[] */ protected function formatHistogram(array $row, string $name): array { diff --git a/src/Controllers/Metrics/Stats.php b/src/Controllers/Metrics/Stats.php index 9e4fbbb6..e412c28e 100644 --- a/src/Controllers/Metrics/Stats.php +++ b/src/Controllers/Metrics/Stats.php @@ -174,9 +174,6 @@ class Stats ->get(); } - /** - * @param string|null $vehicle - */ public function licenses(string $vehicle): int { $mapping = [ diff --git a/src/Exceptions/Handlers/Whoops.php b/src/Exceptions/Handlers/Whoops.php index f5d4d9a2..1d3365e5 100644 --- a/src/Exceptions/Handlers/Whoops.php +++ b/src/Exceptions/Handlers/Whoops.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace Engelsystem\Exceptions\Handlers; use Engelsystem\Application; -use Engelsystem\Container\Container; use Engelsystem\Helpers\Authenticator; use Engelsystem\Http\Request; use Throwable; @@ -15,14 +14,11 @@ use Whoops\Run as WhoopsRunner; class Whoops extends Legacy implements HandlerInterface { - protected Application $app; - /** * Whoops constructor. */ - public function __construct(Container $app) + public function __construct(protected Application $app) { - $this->app = $app; } public function render(Request $request, Throwable $e): void diff --git a/src/Helpers/BarChart.php b/src/Helpers/BarChart.php index 526d529a..3f718f16 100644 --- a/src/Helpers/BarChart.php +++ b/src/Helpers/BarChart.php @@ -89,7 +89,7 @@ class BarChart /** * @param int $max Max Y value - * @return array + * @return array */ private static function calculateYLabels(int $max): array { @@ -98,7 +98,7 @@ class BarChart for ($y = 0; $y <= $max; $y += $step) { $yLabels[] = [ - 'label' => $y, + 'label' => (string) $y, 'bottom' => $max === 0 ? '0%' : ($y / $max * 100) . '%', ]; } @@ -148,7 +148,7 @@ class BarChart 'count' => $step, 'sum' => $step * $count, ]; - $current = $current->addDay(1); + $current = $current->addDay(); $count++; } diff --git a/src/Helpers/Schedule/CalculatesTime.php b/src/Helpers/Schedule/CalculatesTime.php index 7c4275c3..2c0aa29d 100644 --- a/src/Helpers/Schedule/CalculatesTime.php +++ b/src/Helpers/Schedule/CalculatesTime.php @@ -12,7 +12,7 @@ trait CalculatesTime $duration = explode(':', $time); foreach (array_slice($duration, 0, 2) as $key => $times) { - $seconds += [60 * 60, 60][$key] * $times; + $seconds += [60 * 60, 60][$key] * (int) $times; } return $seconds; diff --git a/src/Helpers/Schedule/Event.php b/src/Helpers/Schedule/Event.php index cd5a47de..2fd566fc 100644 --- a/src/Helpers/Schedule/Event.php +++ b/src/Helpers/Schedule/Event.php @@ -42,7 +42,7 @@ class Event protected array $persons = [], protected ?string $language = null, protected ?string $description = null, - protected string $recording = '', + protected ?string $recording = '', protected array $links = [], protected array $attachments = [], protected ?string $url = null, diff --git a/tests/Unit/Controllers/OAuthControllerTest.php b/tests/Unit/Controllers/OAuthControllerTest.php index 43976e98..4c058421 100644 --- a/tests/Unit/Controllers/OAuthControllerTest.php +++ b/tests/Unit/Controllers/OAuthControllerTest.php @@ -116,7 +116,7 @@ class OAuthControllerTest extends TestCase ); $this->setExpects($provider, 'getResourceOwner', [$accessToken], $resourceOwner, $this->atLeastOnce()); - /** @var EventDispatcher|MockObject $event */ + /** @var EventDispatcher|MockObject $dispatcher */ $dispatcher = $this->createMock(EventDispatcher::class); $this->app->instance('events.dispatcher', $dispatcher); $this->setExpects($dispatcher, 'dispatch', ['oauth2.login'], $dispatcher, 4); diff --git a/tests/Unit/Controllers/SettingsControllerTest.php b/tests/Unit/Controllers/SettingsControllerTest.php index 847e170a..f9b1bb11 100644 --- a/tests/Unit/Controllers/SettingsControllerTest.php +++ b/tests/Unit/Controllers/SettingsControllerTest.php @@ -375,8 +375,6 @@ class SettingsControllerTest extends ControllerTest /** * @covers \Engelsystem\Controllers\SettingsController::savePassword * @dataProvider savePasswordValidationProvider - * @param string $new_password - * @param string $new_password2 */ public function testSavePasswordValidation( ?string $password, diff --git a/tests/Unit/Controllers/Stub/ControllerImplementation.php b/tests/Unit/Controllers/Stub/ControllerImplementation.php index dfdd0457..c3a6af55 100644 --- a/tests/Unit/Controllers/Stub/ControllerImplementation.php +++ b/tests/Unit/Controllers/Stub/ControllerImplementation.php @@ -8,7 +8,7 @@ use Engelsystem\Controllers\BaseController; class ControllerImplementation extends BaseController { - /** @var array */ + /** @var string[]|string[][] */ protected array $permissions = [ 'foo', 'lorem' => [ diff --git a/tests/Unit/Helpers/ShiftsTest.php b/tests/Unit/Helpers/ShiftsTest.php index 869c3fd1..f6c00c91 100644 --- a/tests/Unit/Helpers/ShiftsTest.php +++ b/tests/Unit/Helpers/ShiftsTest.php @@ -32,7 +32,7 @@ class ShiftsTest extends TestCase } /** - * @return array[][] + * @return array{0: Carbon, 1: Carbon, 2: boolean}[] */ public function nightShiftData(): array { diff --git a/tests/Unit/Models/Stub/BaseModelImplementation.php b/tests/Unit/Models/Stub/BaseModelImplementation.php deleted file mode 100644 index fc103c66..00000000 --- a/tests/Unit/Models/Stub/BaseModelImplementation.php +++ /dev/null @@ -1,32 +0,0 @@ - */ - protected $fillable = ['foo']; // phpcs:ignore - - public int $saveCount = 0; - - public static ?QueryBuilder $queryBuilder = null; - - public function save(array $options = []): bool - { - $this->saveCount++; - return true; - } - - public static function query(): QueryBuilder - { - return self::$queryBuilder; - } -} diff --git a/tests/Unit/Renderer/TwigServiceProviderTest.php b/tests/Unit/Renderer/TwigServiceProviderTest.php index 5f1e94ff..37d1f50c 100644 --- a/tests/Unit/Renderer/TwigServiceProviderTest.php +++ b/tests/Unit/Renderer/TwigServiceProviderTest.php @@ -111,7 +111,7 @@ class TwigServiceProviderTest extends ServiceProviderTest */ public function testRegisterTwigEngine(): void { - /** @var TwigEngine|MockObject $htmlEngine */ + /** @var TwigEngine|MockObject $twigEngine */ $twigEngine = $this->createMock(TwigEngine::class); /** @var TwigLoader|MockObject $twigLoader */ $twigLoader = $this->createMock(TwigLoader::class);