diff --git a/config/config.default.php b/config/config.default.php index 0183731c..8e0cb314 100644 --- a/config/config.default.php +++ b/config/config.default.php @@ -26,7 +26,7 @@ return [ 'environment' => env('ENVIRONMENT', 'production'), // Application URL and base path to use instead of the auto-detected one - 'url' => env('APP_URL', null), + 'url' => env('APP_URL'), // Header links // Available link placeholders: %lang% @@ -61,7 +61,7 @@ return [ ], // Text displayed on the FAQ page, rendered as markdown - 'faq_text' => env('FAQ_TEXT', null), + 'faq_text' => env('FAQ_TEXT'), // Link to documentation/help 'documentation_url' => env('DOCUMENTATION_URL', 'https://engelsystem.de/doc/'), @@ -79,20 +79,20 @@ return [ 'host' => env('MAIL_HOST', 'localhost'), 'port' => env('MAIL_PORT', 587), // If tls transport encryption should be used - 'tls' => env('MAIL_TLS', null), + 'tls' => env('MAIL_TLS'), 'username' => env('MAIL_USERNAME'), 'password' => env('MAIL_PASSWORD'), 'sendmail' => env('MAIL_SENDMAIL', '/usr/sbin/sendmail -bs'), ], // Your privacy@ contact address - 'privacy_email' => env('PRIVACY_EMAIL', null), + 'privacy_email' => env('PRIVACY_EMAIL'), // Show opt in to save some personal data after the event on user profile and registration pages 'enable_email_goody' => (bool) env('ENABLE_EMAIL_GOODY', true), // Initial admin password - 'setup_admin_password' => env('SETUP_ADMIN_PASSWORD', null), + 'setup_admin_password' => env('SETUP_ADMIN_PASSWORD'), 'oauth' => [ // '[name]' => [config] @@ -364,7 +364,7 @@ return [ 'shifts_per_voucher' => env('SHIFTS_PER_VOUCHER', 0), 'hours_per_voucher' => env('HOURS_PER_VOUCHER', 2), // 'Y-m-d' formatted - 'voucher_start' => env('VOUCHER_START', null) ?: null, + 'voucher_start' => env('VOUCHER_START') ?: null, ], // Enables Driving License @@ -374,8 +374,7 @@ return [ 'ifsg_enabled' => (bool) env('IFSG_ENABLED', false), # Instruction only onsite in accordance with § 43 Para. 1 of the German Infection Protection Act (IfSG) - 'ifsg_light_enabled' => (bool) env('IFSG_LIGHT_ENABLED', false) - && env('IFSG_ENABLED', false), + 'ifsg_light_enabled' => env('IFSG_LIGHT_ENABLED', false) && env('IFSG_ENABLED', false), // Available locales in /resources/lang/ // To disable a locale in the config.php, you can set its value to null @@ -404,7 +403,7 @@ return [ ], // T-shirt Size-Guide link - 'tshirt_link' => env('TSHIRT_LINK', null), + 'tshirt_link' => env('TSHIRT_LINK'), // Whether to show the current day of the event (-2, -1, 0, 1, 2…) in footer and on the dashboard. // The event start date has to be set for it to appear. diff --git a/db/migrations/2018_12_21_000000_change_users_contact_dect_field_size.php b/db/migrations/2018_12_21_000000_change_users_contact_dect_field_size.php index 8bf68433..64c4fe61 100644 --- a/db/migrations/2018_12_21_000000_change_users_contact_dect_field_size.php +++ b/db/migrations/2018_12_21_000000_change_users_contact_dect_field_size.php @@ -9,7 +9,6 @@ use Illuminate\Database\Schema\Blueprint; class ChangeUsersContactDectFieldSize extends Migration { - /** @var array */ protected array $tables = [ 'AngelTypes' => 'contact_dect', 'users_contact' => 'dect', diff --git a/includes/controller/shift_entries_controller.php b/includes/controller/shift_entries_controller.php index 0951a8a5..0fb81faa 100644 --- a/includes/controller/shift_entries_controller.php +++ b/includes/controller/shift_entries_controller.php @@ -307,9 +307,8 @@ function shift_entry_load() if (!$request->has('shift_entry_id') || !test_request_int('shift_entry_id')) { throw_redirect(url('/user-shifts')); } - $shiftEntry = ShiftEntry::findOrFail($request->input('shift_entry_id')); - return $shiftEntry; + return ShiftEntry::findOrFail($request->input('shift_entry_id')); } /** diff --git a/includes/controller/shifts_controller.php b/includes/controller/shifts_controller.php index 0097071a..6ebd1d4b 100644 --- a/includes/controller/shifts_controller.php +++ b/includes/controller/shifts_controller.php @@ -195,7 +195,7 @@ function shift_edit_controller() htmlspecialchars($angeltype_name), $needed_angel_types[$angeltype_id], [], - ScheduleShift::whereShiftId($shift->id)->first() ? true : false, + (bool) ScheduleShift::whereShiftId($shift->id)->first(), ); } diff --git a/includes/engelsystem.php b/includes/engelsystem.php index 0c368dc8..05b6d870 100644 --- a/includes/engelsystem.php +++ b/includes/engelsystem.php @@ -4,6 +4,7 @@ * Bootstrap application */ +use Engelsystem\Application; use Engelsystem\Http\UrlGeneratorInterface; require __DIR__ . '/application.php'; @@ -18,7 +19,7 @@ require __DIR__ . '/includes.php'; /** * Check for maintenance */ -/** @var \Engelsystem\Application $app */ +/** @var Application $app */ if ($app->get('config')->get('maintenance')) { http_response_code(503); $url = $app->get(UrlGeneratorInterface::class); diff --git a/includes/helper/legacy_helper.php b/includes/helper/legacy_helper.php index 220a6268..1bf719bd 100644 --- a/includes/helper/legacy_helper.php +++ b/includes/helper/legacy_helper.php @@ -14,9 +14,6 @@ function theme_id(): int return $globals['themeId']; } -/** - * @return array - */ function theme(): array { $theme_id = theme_id(); diff --git a/includes/pages/admin_shifts.php b/includes/pages/admin_shifts.php index 0d195ad0..5f11288d 100644 --- a/includes/pages/admin_shifts.php +++ b/includes/pages/admin_shifts.php @@ -45,7 +45,7 @@ function admin_shifts() $location_array = $locations->pluck('name', 'id')->toArray(); // Load angeltypes - /** @var AngelType[] $types */ + /** @var AngelType[]|Collection $types */ $types = AngelType::all(); $no_angeltypes = $types->isEmpty(); $needed_angel_types = []; diff --git a/includes/sys_form.php b/includes/sys_form.php index 4edeccc6..8db8c856 100644 --- a/includes/sys_form.php +++ b/includes/sys_form.php @@ -20,8 +20,9 @@ function form_hidden($name, $value) * * @param string $name * @param string $label - * @param int $value - * @param array $data_attributes + * @param int $value + * @param array $data_attributes + * @param bool $isDisabled * @return string */ function form_spinner(string $name, string $label, int $value, array $data_attributes = [], bool $isDisabled = false) @@ -139,8 +140,9 @@ function form_info($label, $text = '') * @param string $name * @param string $label * @param string $class - * @param bool $wrapForm + * @param bool $wrapForm * @param string $buttonType + * @param string $title * @param array $dataAttributes * @return string */ diff --git a/includes/sys_page.php b/includes/sys_page.php index 70aa7f93..374e364b 100644 --- a/includes/sys_page.php +++ b/includes/sys_page.php @@ -116,7 +116,7 @@ function check_date($input, $error_message = null, $null_allowed = false, $time_ } else { $time = Carbon::createFromFormat('Y-m-d', $trimmed_input); } - } catch (InvalidArgumentException $e) { + } catch (InvalidArgumentException) { $time = null; } diff --git a/includes/view/ShiftCalendarRenderer.php b/includes/view/ShiftCalendarRenderer.php index 63ab6cc7..272f958e 100644 --- a/includes/view/ShiftCalendarRenderer.php +++ b/includes/view/ShiftCalendarRenderer.php @@ -302,7 +302,7 @@ class ShiftCalendarRenderer */ private function calcBlocksPerSlot() { - return ceil( + return (int) ceil( ($this->getLastBlockEndTime() - $this->getFirstBlockStartTime()) / ShiftCalendarRenderer::SECONDS_PER_ROW ); diff --git a/resources/assets/themes/barchart.scss b/resources/assets/themes/barchart.scss index 097bac2d..e8e2d933 100644 --- a/resources/assets/themes/barchart.scss +++ b/resources/assets/themes/barchart.scss @@ -18,7 +18,6 @@ &-40 { // >= 40 bars - --barchart-bar-margin: 1px; --barchart-bar-margin: 0.5px; --barchart-group-margin: 0.5%; } diff --git a/src/Config/ConfigServiceProvider.php b/src/Config/ConfigServiceProvider.php index 18e3c2b8..fc691a7d 100644 --- a/src/Config/ConfigServiceProvider.php +++ b/src/Config/ConfigServiceProvider.php @@ -74,7 +74,7 @@ class ConfigServiceProvider extends ServiceProvider try { /** @var EventConfig[] $values */ $values = $this->eventConfig->newQuery()->get(['name', 'value']); - } catch (QueryException $e) { + } catch (QueryException) { return; } diff --git a/src/Controllers/DesignController.php b/src/Controllers/DesignController.php index a8ff1f0b..c0c251eb 100644 --- a/src/Controllers/DesignController.php +++ b/src/Controllers/DesignController.php @@ -5,6 +5,8 @@ declare(strict_types=1); namespace Engelsystem\Controllers; use Carbon\CarbonImmutable; +use DateInterval; +use DateTimeImmutable; use Engelsystem\Config\Config; use Engelsystem\Helpers\BarChart; use Engelsystem\Http\Response; @@ -60,26 +62,26 @@ class DesignController extends BaseController } $themes = $this->config->get('themes'); - $date = new \DateTimeImmutable(); + $date = new DateTimeImmutable(); $data = [ 'demo_user' => $demoUser, 'demo_user_2' => $demoUser2, 'themes' => $themes, 'bar_chart' => BarChart::render(...BarChart::generateChartDemoData(23)), - 'timestamp30m' => $date->add(new \DateInterval('PT30M')), - 'timestamp59m' => $date->add(new \DateInterval('PT59M')), - 'timestamp1h' => $date->add(new \DateInterval('PT1H')), - 'timestamp1h30m' => $date->add(new \DateInterval('PT1H30M')), - 'timestamp1h31m' => $date->add(new \DateInterval('PT1H31M')), - 'timestamp2h' => $date->add(new \DateInterval('PT2H')), - 'timestamp2d' => $date->add(new \DateInterval('P2D')), - 'timestamp3m' => $date->add(new \DateInterval('P3M')), - 'timestamp22y' => $date->add(new \DateInterval('P22Y')), - 'timestamp30s' => $date->add(new \DateInterval('PT30S')), + 'timestamp30m' => $date->add(new DateInterval('PT30M')), + 'timestamp59m' => $date->add(new DateInterval('PT59M')), + 'timestamp1h' => $date->add(new DateInterval('PT1H')), + 'timestamp1h30m' => $date->add(new DateInterval('PT1H30M')), + 'timestamp1h31m' => $date->add(new DateInterval('PT1H31M')), + 'timestamp2h' => $date->add(new DateInterval('PT2H')), + 'timestamp2d' => $date->add(new DateInterval('P2D')), + 'timestamp3m' => $date->add(new DateInterval('P3M')), + 'timestamp22y' => $date->add(new DateInterval('P22Y')), + 'timestamp30s' => $date->add(new DateInterval('PT30S')), - 'timestamp30mago' => $date->sub(new \DateInterval('PT30M')), - 'timestamp45mago' => $date->sub(new \DateInterval('PT45M')), + 'timestamp30mago' => $date->sub(new DateInterval('PT30M')), + 'timestamp45mago' => $date->sub(new DateInterval('PT45M')), 'selectOptions' => $selectOptions, 'dateSelectOptions' => $dateSelectOptions, ]; diff --git a/src/Controllers/Metrics/Controller.php b/src/Controllers/Metrics/Controller.php index f050bc08..cd3cf4a1 100644 --- a/src/Controllers/Metrics/Controller.php +++ b/src/Controllers/Metrics/Controller.php @@ -48,7 +48,7 @@ class Controller extends BaseController $oauthProviders = $this->config->get('oauth'); foreach ($userOauth as $key => $oauth) { $provider = $oauth['labels']['provider']; - $name = isset($oauthProviders[$provider]['name']) ? $oauthProviders[$provider]['name'] : $provider; + $name = $oauthProviders[$provider]['name'] ?? $provider; $userOauth[$key]['labels']['name'] = $name; } @@ -200,7 +200,7 @@ class Controller extends BaseController $data['scrape_memory_bytes'] = [ 'type' => 'gauge', 'help' => 'Memory usage of the current request', - memory_get_usage(false), + memory_get_usage(), ]; return $this->response @@ -215,7 +215,7 @@ class Controller extends BaseController $data = [ 'user_count' => $this->stats->usersState() + $this->stats->usersState(null, false), 'arrived_user_count' => $this->stats->usersState(), - 'done_work_hours' => round($this->stats->workSeconds(true) / 60 / 60, 0), + 'done_work_hours' => round($this->stats->workSeconds(true) / 60 / 60), 'users_in_action' => $this->stats->currentlyWorkingUsers(), ]; diff --git a/src/Controllers/Metrics/MetricsEngine.php b/src/Controllers/Metrics/MetricsEngine.php index 4ce0ad46..9999dd57 100644 --- a/src/Controllers/Metrics/MetricsEngine.php +++ b/src/Controllers/Metrics/MetricsEngine.php @@ -79,7 +79,7 @@ class MetricsEngine implements EngineInterface ); } - $sum = isset($row['sum']) ? $row['sum'] : 'NaN'; + $sum = $row['sum'] ?? 'NaN'; $count = $row['value']['+Inf']; $return[] = $this->formatData($name . '_sum', $data + ['value' => $sum]); $return[] = $this->formatData($name . '_count', $data + ['value' => $count]); diff --git a/src/Controllers/NewsController.php b/src/Controllers/NewsController.php index 8c001e4a..9da5279b 100644 --- a/src/Controllers/NewsController.php +++ b/src/Controllers/NewsController.php @@ -156,9 +156,6 @@ class NewsController extends BaseController ); } - /** - * @param array $data - */ protected function renderView(string $page, array $data): Response { return $this->response->withView($page, $data); diff --git a/src/Controllers/SettingsController.php b/src/Controllers/SettingsController.php index 8a6d34e1..e091419e 100644 --- a/src/Controllers/SettingsController.php +++ b/src/Controllers/SettingsController.php @@ -424,7 +424,7 @@ class SettingsController extends BaseController protected function checkOauthHidden(): bool { foreach (config('oauth') as $config) { - if (empty($config['hidden']) || !$config['hidden']) { + if (empty($config['hidden'])) { return false; } } diff --git a/src/Exceptions/Handler.php b/src/Exceptions/Handler.php index 0b00610f..4fc992fa 100644 --- a/src/Exceptions/Handler.php +++ b/src/Exceptions/Handler.php @@ -53,8 +53,7 @@ class Handler $this->request = new Request(); } - $handler = isset($this->handler[$this->environment->value]) - ? $this->handler[$this->environment->value] : new Legacy(); + $handler = $this->handler[$this->environment->value] ?? new Legacy(); $handler->report($e); ob_start(); $handler->render($this->request, $e); @@ -65,7 +64,12 @@ class Handler return $output; } - http_response_code(500); + if (!headers_sent()) { + // @codeCoverageIgnoreStart + http_response_code(500); + // @codeCoverageIgnoreEnd + } + ob_end_flush(); $this->terminateApplicationImmediately(); diff --git a/src/Exceptions/Handlers/Legacy.php b/src/Exceptions/Handlers/Legacy.php index dbd830c0..c121872d 100644 --- a/src/Exceptions/Handlers/Legacy.php +++ b/src/Exceptions/Handlers/Legacy.php @@ -40,7 +40,7 @@ class Legacy implements HandlerInterface try { $this->log->critical('', ['exception' => $e]); - } catch (Throwable $e) { + } catch (Throwable) { } } diff --git a/src/Exceptions/Handlers/NullHandler.php b/src/Exceptions/Handlers/NullHandler.php index 5d9a6b2e..d89ad649 100644 --- a/src/Exceptions/Handlers/NullHandler.php +++ b/src/Exceptions/Handlers/NullHandler.php @@ -11,6 +11,5 @@ class NullHandler extends Legacy { public function render(Request $request, Throwable $e): void { - return; } } diff --git a/src/Helpers/Carbon.php b/src/Helpers/Carbon.php index 931a74a8..4d73f8b3 100644 --- a/src/Helpers/Carbon.php +++ b/src/Helpers/Carbon.php @@ -41,7 +41,7 @@ class Carbon extends \Carbon\Carbon public static function createTimestampFromDatetime(string $value): ?int { $carbon = self::createFromDateTime($value); - return $carbon === null ? null : $carbon->timestamp; + return $carbon?->timestamp; } /** diff --git a/src/Helpers/DayOfEvent.php b/src/Helpers/DayOfEvent.php index a7f84801..1ae8640a 100644 --- a/src/Helpers/DayOfEvent.php +++ b/src/Helpers/DayOfEvent.php @@ -7,7 +7,7 @@ namespace Engelsystem\Helpers; class DayOfEvent { /** - * @return ?int The current day of the event. + * @return ?int The current day of the event. * If `event_has_day0` is set to true in config, the first day of the event will be 0, else 1. * Returns null if "event_start" is not set. */ diff --git a/src/Helpers/Translation/Translator.php b/src/Helpers/Translation/Translator.php index aff0cc7f..cd27a1a2 100644 --- a/src/Helpers/Translation/Translator.php +++ b/src/Helpers/Translation/Translator.php @@ -59,7 +59,7 @@ class Translator try { $translated = call_user_func_array([$translator, $type], $parameters); break; - } catch (TranslationNotFound $e) { + } catch (TranslationNotFound) { } } diff --git a/src/Http/Request.php b/src/Http/Request.php index af60695a..a858e9c8 100644 --- a/src/Http/Request.php +++ b/src/Http/Request.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace Engelsystem\Http; +use InvalidArgumentException; use Nyholm\Psr7\UploadedFile; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\UploadedFileInterface; @@ -124,7 +125,7 @@ class Request extends SymfonyRequest implements ServerRequestInterface * * @param string $method Case-sensitive method. * @return static - * @throws \InvalidArgumentException for invalid HTTP methods. + * @throws InvalidArgumentException for invalid HTTP methods. */ public function withMethod(mixed $method): static { @@ -309,7 +310,7 @@ class Request extends SymfonyRequest implements ServerRequestInterface * * @param array $uploadedFiles An array tree of UploadedFileInterface instances. * @return static - * @throws \InvalidArgumentException if an invalid structure is provided. + * @throws InvalidArgumentException if an invalid structure is provided. */ public function withUploadedFiles(array $uploadedFiles): static { @@ -381,7 +382,7 @@ class Request extends SymfonyRequest implements ServerRequestInterface * @param null|array|object $data The deserialized body data. This will * typically be in an array or object. * @return static - * @throws \InvalidArgumentException if an unsupported argument type is + * @throws InvalidArgumentException if an unsupported argument type is * provided. */ public function withParsedBody(mixed $data): static diff --git a/src/Http/UrlGenerator.php b/src/Http/UrlGenerator.php index 7fd3b4f1..9681caa4 100644 --- a/src/Http/UrlGenerator.php +++ b/src/Http/UrlGenerator.php @@ -42,8 +42,6 @@ class UrlGenerator implements UrlGeneratorInterface /** * Prepend the auto-detected or configured app base path and domain - * - * @param $path */ protected function generateUrl(string $path): string { diff --git a/src/Http/Validation/ValidatesRequest.php b/src/Http/Validation/ValidatesRequest.php index 12a1e20f..f393b88c 100644 --- a/src/Http/Validation/ValidatesRequest.php +++ b/src/Http/Validation/ValidatesRequest.php @@ -9,7 +9,7 @@ use Engelsystem\Http\Request; trait ValidatesRequest { - protected Validator $validator; + protected ?Validator $validator; protected function validate(Request $request, array $rules): array { diff --git a/src/Http/Validation/Validator.php b/src/Http/Validation/Validator.php index 2bb4a859..9efbfa6a 100644 --- a/src/Http/Validation/Validator.php +++ b/src/Http/Validation/Validator.php @@ -34,7 +34,7 @@ class Validator $v = new RespectValidator(); $v->with('\\Engelsystem\\Http\\Validation\\Rules', true); - $value = isset($data[$key]) ? $data[$key] : null; + $value = $data[$key] ?? null; $values = explode('|', $values); // Rules that have side effects on others like inverting the result with not and making them optional diff --git a/src/Middleware/ErrorHandler.php b/src/Middleware/ErrorHandler.php index ee844287..ab08a747 100644 --- a/src/Middleware/ErrorHandler.php +++ b/src/Middleware/ErrorHandler.php @@ -65,14 +65,14 @@ class ErrorHandler implements MiddlewareInterface if ($request instanceof Request) { $response->withInput(Arr::except($request->request->all(), $this->formIgnore)); } - } catch (ModelNotFoundException $e) { + } catch (ModelNotFoundException) { $response = $this->createResponse('', 404); } $statusCode = $response->getStatusCode(); $contentType = $response->getHeader('content-type'); $contentType = array_shift($contentType); - if (!$contentType && strpos($response->getBody()?->getContents() ?? '', 'getBody()?->getContents() ?? '', ' $title, 'content' => msg() . $content, ] - ), - 200 + ) ); } } diff --git a/src/Models/EventConfig.php b/src/Models/EventConfig.php index a236dc28..dba924ad 100644 --- a/src/Models/EventConfig.php +++ b/src/Models/EventConfig.php @@ -91,6 +91,6 @@ class EventConfig extends BaseModel */ protected function getValueCast(string $value): ?string { - return isset($this->valueCasts[$value]) ? $this->valueCasts[$value] : null; + return $this->valueCasts[$value] ?? null; } } diff --git a/src/Renderer/EngineInterface.php b/src/Renderer/EngineInterface.php index acf3c312..883ae8f2 100644 --- a/src/Renderer/EngineInterface.php +++ b/src/Renderer/EngineInterface.php @@ -13,9 +13,14 @@ interface EngineInterface */ public function get(string $path, array $data = []): string; + /** + * Check if the engine can render the specified template + */ public function canRender(string $path): bool; /** + * Add shared variables + * * @param string|mixed[] $key */ public function share(string|array $key, mixed $value = null): void; diff --git a/src/Renderer/HtmlEngine.php b/src/Renderer/HtmlEngine.php index 70084188..d4dc368a 100644 --- a/src/Renderer/HtmlEngine.php +++ b/src/Renderer/HtmlEngine.php @@ -16,10 +16,8 @@ class HtmlEngine extends Engine $data = array_replace_recursive($this->sharedData, $data); $template = file_get_contents($path); - if (is_array($data)) { - foreach ($data as $name => $content) { - $template = str_replace('%' . $name . '%', $content, $template); - } + foreach ($data as $name => $content) { + $template = str_replace('%' . $name . '%', $content, $template); } return $template; diff --git a/src/Renderer/Renderer.php b/src/Renderer/Renderer.php index 3697a337..55994c8d 100644 --- a/src/Renderer/Renderer.php +++ b/src/Renderer/Renderer.php @@ -28,9 +28,7 @@ class Renderer return $renderer->get($template, $data); } - if ($this->logger) { - $this->logger->critical('Unable to find a renderer for template file "{file}"', ['file' => $template]); - } + $this->logger?->critical('Unable to find a renderer for template file "{file}"', ['file' => $template]); return ''; } diff --git a/tests/Unit/ApplicationTest.php b/tests/Unit/ApplicationTest.php index f929acf6..f2bc80a0 100644 --- a/tests/Unit/ApplicationTest.php +++ b/tests/Unit/ApplicationTest.php @@ -160,7 +160,6 @@ class ApplicationTest extends TestCase ->willReturnOnConsecutiveCalls([$serviceProvider], $middleware); $property = (new ReflectionClass($app))->getProperty('serviceProviders'); - $property->setAccessible(true); $property->setValue($app, [$serviceProvider]); $app->bootstrap($config); diff --git a/tests/Unit/Config/RoutesFileTest.php b/tests/Unit/Config/RoutesFileTest.php index 377f5d39..fe9626fb 100644 --- a/tests/Unit/Config/RoutesFileTest.php +++ b/tests/Unit/Config/RoutesFileTest.php @@ -22,7 +22,6 @@ class RoutesFileTest extends TestCase ->onlyMethods(['addRoute']) ->getMock(); - $this->doesNotPerformAssertions(); /** @see RouteCollector::addRoute */ $route->expects($this->any()) ->method('addRoute') diff --git a/tests/Unit/Controllers/Admin/FaqControllerTest.php b/tests/Unit/Controllers/Admin/FaqControllerTest.php index 7ac661db..84d1ba12 100644 --- a/tests/Unit/Controllers/Admin/FaqControllerTest.php +++ b/tests/Unit/Controllers/Admin/FaqControllerTest.php @@ -13,7 +13,6 @@ use Engelsystem\Test\Unit\Controllers\ControllerTest; class FaqControllerTest extends ControllerTest { - /** @var array */ protected array $data = [ 'question' => 'Foo?', 'text' => 'Bar!', diff --git a/tests/Unit/Controllers/Admin/NewsControllerTest.php b/tests/Unit/Controllers/Admin/NewsControllerTest.php index ca40cd40..d8f23730 100644 --- a/tests/Unit/Controllers/Admin/NewsControllerTest.php +++ b/tests/Unit/Controllers/Admin/NewsControllerTest.php @@ -21,7 +21,6 @@ class NewsControllerTest extends ControllerTest protected Authenticator|MockObject $auth; protected EventDispatcher|MockObject $eventDispatcher; - /** @var array */ protected array $data = [ [ 'title' => 'Foo', diff --git a/tests/Unit/Controllers/Admin/UserShirtControllerTest.php b/tests/Unit/Controllers/Admin/UserShirtControllerTest.php index 0c6a9fb2..6626d64e 100644 --- a/tests/Unit/Controllers/Admin/UserShirtControllerTest.php +++ b/tests/Unit/Controllers/Admin/UserShirtControllerTest.php @@ -136,7 +136,7 @@ class UserShirtControllerTest extends ControllerTest try { $controller->saveShirt($request); self::fail('Expected exception was not raised'); - } catch (ValidationException $e) { + } catch (ValidationException) { // ignore } $user = User::find(1); diff --git a/tests/Unit/Controllers/AuthControllerTest.php b/tests/Unit/Controllers/AuthControllerTest.php index f518ac70..0996927b 100644 --- a/tests/Unit/Controllers/AuthControllerTest.php +++ b/tests/Unit/Controllers/AuthControllerTest.php @@ -99,7 +99,7 @@ class AuthControllerTest extends ControllerTest try { $controller->postLogin($request); $this->fail('Login without credentials possible'); - } catch (ValidationException $e) { + } catch (ValidationException) { } // Missing password @@ -107,7 +107,7 @@ class AuthControllerTest extends ControllerTest try { $controller->postLogin($request); $this->fail('Login without password possible'); - } catch (ValidationException $e) { + } catch (ValidationException) { } // No user found diff --git a/tests/Unit/Controllers/NewsControllerTest.php b/tests/Unit/Controllers/NewsControllerTest.php index 864335d1..9ebfdc8d 100644 --- a/tests/Unit/Controllers/NewsControllerTest.php +++ b/tests/Unit/Controllers/NewsControllerTest.php @@ -23,7 +23,6 @@ class NewsControllerTest extends ControllerTest protected Authenticator|MockObject $auth; - /** @var array */ protected array $data = [ [ 'title' => 'Foo', diff --git a/tests/Unit/Controllers/OAuthControllerTest.php b/tests/Unit/Controllers/OAuthControllerTest.php index 70a114b0..4fe31135 100644 --- a/tests/Unit/Controllers/OAuthControllerTest.php +++ b/tests/Unit/Controllers/OAuthControllerTest.php @@ -459,10 +459,10 @@ class OAuthControllerTest extends TestCase $this->assertEquals(4242424242, $this->session->get('oauth2_expires_at')->unix()); $this->assertFalse($this->session->get('oauth2_enable_password')); $this->assertEquals(null, $this->session->get('oauth2_allow_registration')); - $this->assertEquals($this->session->get('form-data-username'), 'username'); - $this->assertEquals($this->session->get('form-data-email'), 'foo.bar@localhost'); - $this->assertEquals($this->session->get('form-data-firstname'), 'Foo'); - $this->assertEquals($this->session->get('form-data-lastname'), 'Bar'); + $this->assertEquals('username', $this->session->get('form-data-username')); + $this->assertEquals('foo.bar@localhost', $this->session->get('form-data-email')); + $this->assertEquals('Foo', $this->session->get('form-data-firstname')); + $this->assertEquals('Bar', $this->session->get('form-data-lastname')); $this->config->set('registration_enabled', false); $this->expectException(HttpNotFound::class); @@ -539,10 +539,10 @@ class OAuthControllerTest extends TestCase $this->setExpects($controller, 'getProvider', ['testprovider'], $provider, $this->atLeastOnce()); $controller->index($request); - $this->assertEquals($this->session->get('form-data-username'), 'testuser'); - $this->assertEquals($this->session->get('form-data-email'), 'foo.bar@localhost'); - $this->assertEquals($this->session->get('form-data-firstname'), 'Test'); - $this->assertEquals($this->session->get('form-data-lastname'), 'Tester'); + $this->assertEquals('testuser', $this->session->get('form-data-username')); + $this->assertEquals('foo.bar@localhost', $this->session->get('form-data-email')); + $this->assertEquals('Test', $this->session->get('form-data-firstname')); + $this->assertEquals('Tester', $this->session->get('form-data-lastname')); } diff --git a/tests/Unit/Controllers/PasswordResetControllerTest.php b/tests/Unit/Controllers/PasswordResetControllerTest.php index d714177c..9628d370 100644 --- a/tests/Unit/Controllers/PasswordResetControllerTest.php +++ b/tests/Unit/Controllers/PasswordResetControllerTest.php @@ -30,7 +30,6 @@ class PasswordResetControllerTest extends ControllerTest use ArraySubsetAsserts; use HasDatabase; - /** @var array */ protected array $args = []; /** diff --git a/tests/Unit/Controllers/RegistrationControllerTest.php b/tests/Unit/Controllers/RegistrationControllerTest.php index 85e88c25..ed75f66b 100644 --- a/tests/Unit/Controllers/RegistrationControllerTest.php +++ b/tests/Unit/Controllers/RegistrationControllerTest.php @@ -188,7 +188,6 @@ final class RegistrationControllerTest extends ControllerTest public function testViewRegistrationDisabled(): void { $this->config->set('registration_enabled', false); - $request = $this->request->withParsedBody([]); // Assert the controller does not call createFromData $this->userFactory @@ -201,7 +200,7 @@ final class RegistrationControllerTest extends ControllerTest ->method('redirectTo') ->with('http://localhost/', 302); - $this->subject->view($request); + $this->subject->view(); // Assert that the error notification is there self::assertEquals( diff --git a/tests/Unit/Controllers/SettingsControllerTest.php b/tests/Unit/Controllers/SettingsControllerTest.php index 9a3af7cb..ae56eae1 100644 --- a/tests/Unit/Controllers/SettingsControllerTest.php +++ b/tests/Unit/Controllers/SettingsControllerTest.php @@ -773,8 +773,8 @@ class SettingsControllerTest extends ControllerTest $this->controller->saveIfsgCertificate($this->request); - $this->assertEquals(true, $this->user->license->ifsg_certificate_light); - $this->assertEquals(false, $this->user->license->ifsg_certificate); + $this->assertTrue($this->user->license->ifsg_certificate_light); + $this->assertFalse($this->user->license->ifsg_certificate); } /** @@ -803,8 +803,8 @@ class SettingsControllerTest extends ControllerTest $this->controller->saveIfsgCertificate($this->request); - $this->assertEquals(false, $this->user->license->ifsg_certificate_light); - $this->assertEquals(false, $this->user->license->ifsg_certificate); + $this->assertFalse($this->user->license->ifsg_certificate_light); + $this->assertFalse($this->user->license->ifsg_certificate); } /** @@ -831,8 +831,8 @@ class SettingsControllerTest extends ControllerTest $this->controller->saveIfsgCertificate($this->request); - $this->assertEquals(false, $this->user->license->ifsg_certificate_light); - $this->assertEquals(true, $this->user->license->ifsg_certificate); + $this->assertFalse($this->user->license->ifsg_certificate_light); + $this->assertTrue($this->user->license->ifsg_certificate); } /** @@ -859,8 +859,8 @@ class SettingsControllerTest extends ControllerTest $this->controller->saveIfsgCertificate($this->request); - $this->assertEquals(false, $this->user->license->ifsg_certificate_light); - $this->assertEquals(true, $this->user->license->ifsg_certificate); + $this->assertFalse($this->user->license->ifsg_certificate_light); + $this->assertTrue($this->user->license->ifsg_certificate); } /** diff --git a/tests/Unit/Database/Migration/MigrateTest.php b/tests/Unit/Database/Migration/MigrateTest.php index 957c9871..6068f8be 100644 --- a/tests/Unit/Database/Migration/MigrateTest.php +++ b/tests/Unit/Database/Migration/MigrateTest.php @@ -154,7 +154,7 @@ class MigrateTest extends TestCase $this->setExpects($migration, 'getMigrations', null, collect([ ['migration' => '1234_01_23_123456_init_foo', 'path' => '/foo'], ])); - $this->setExpects($migration, 'getMigrated', null, collect([])); + $this->setExpects($migration, 'getMigrated', null, collect()); $migration->expects($this->once()) ->method('migrate') ->willReturnCallback(function (): void { diff --git a/tests/Unit/Events/EventDispatcherTest.php b/tests/Unit/Events/EventDispatcherTest.php index f0521c9e..8b72270b 100644 --- a/tests/Unit/Events/EventDispatcherTest.php +++ b/tests/Unit/Events/EventDispatcherTest.php @@ -9,7 +9,6 @@ use Engelsystem\Test\Unit\TestCase; class EventDispatcherTest extends TestCase { - /** @var array */ protected array $firedEvents = []; /** diff --git a/tests/Unit/Helpers/Schedule/XmlParserTest.php b/tests/Unit/Helpers/Schedule/XmlParserTest.php index cfb5b110..7b6e2915 100644 --- a/tests/Unit/Helpers/Schedule/XmlParserTest.php +++ b/tests/Unit/Helpers/Schedule/XmlParserTest.php @@ -72,7 +72,6 @@ class XmlParserTest extends TestCase $this->assertEquals('Testing', $tracks[0]->getName()); $this->assertEquals('#dead55', $tracks[0]->getColor()); $this->assertEquals('testing', $tracks[0]->getSlug()); - ; /** @var Day $day */ $day = Arr::first($schedule->getDays()); diff --git a/tests/Unit/Helpers/Stub/UserModelImplementation.php b/tests/Unit/Helpers/Stub/UserModelImplementation.php index d0c7117c..660dff7a 100644 --- a/tests/Unit/Helpers/Stub/UserModelImplementation.php +++ b/tests/Unit/Helpers/Stub/UserModelImplementation.php @@ -17,7 +17,11 @@ class UserModelImplementation extends User public static ?string $apiKey = null; - public function find(mixed $id, array $columns = ['*']): ?User + /** + * @param mixed $id + * @param array $columns + */ + public function find($id, $columns = ['*']): ?User // phpcs:ignore { if ($id != static::$id) { throw new InvalidArgumentException('Wrong user ID searched'); @@ -29,9 +33,9 @@ class UserModelImplementation extends User /** * @return User[]|Collection|QueryBuilder */ - public static function whereApiKey(string $apiKey): array|Collection|QueryBuilder + public static function whereApiKey(string $value): array|Collection|QueryBuilder { - if ($apiKey != static::$apiKey) { + if ($value != static::$apiKey) { throw new InvalidArgumentException('Wrong api key searched'); } diff --git a/tests/Unit/Http/Validation/Rules/ShirtSizeTest.php b/tests/Unit/Http/Validation/Rules/ShirtSizeTest.php index 9186d31d..02b4e031 100644 --- a/tests/Unit/Http/Validation/Rules/ShirtSizeTest.php +++ b/tests/Unit/Http/Validation/Rules/ShirtSizeTest.php @@ -26,7 +26,7 @@ class ShirtSizeTest extends ServiceProviderTest */ public function provideTestValidateData(): array { - $data = [ + return [ 'empty string' => ['', false], 'null' => [null, false], '0' => [0, false], @@ -34,8 +34,6 @@ class ShirtSizeTest extends ServiceProviderTest '"M" (known value)' => ['M', true], '"L" (unknown value)' => ['L', false], ]; - - return $data; } /** diff --git a/tests/Unit/Mail/MailerServiceProviderTest.php b/tests/Unit/Mail/MailerServiceProviderTest.php index f5e2b946..b4c7e30e 100644 --- a/tests/Unit/Mail/MailerServiceProviderTest.php +++ b/tests/Unit/Mail/MailerServiceProviderTest.php @@ -20,7 +20,6 @@ use Symfony\Component\Mailer\Transport\TransportInterface; class MailerServiceProviderTest extends ServiceProviderTest { - /** @var array */ protected array $defaultConfig = [ 'app_name' => 'Engelsystem App', 'email' => [ @@ -33,7 +32,6 @@ class MailerServiceProviderTest extends ServiceProviderTest ], ]; - /** @var array */ protected array $smtpConfig = [ 'email' => [ 'driver' => 'smtp', diff --git a/tests/Unit/Middleware/DispatcherTest.php b/tests/Unit/Middleware/DispatcherTest.php index 3fca06b6..64bde79d 100644 --- a/tests/Unit/Middleware/DispatcherTest.php +++ b/tests/Unit/Middleware/DispatcherTest.php @@ -36,7 +36,6 @@ class DispatcherTest extends TestCase $reflection = new Reflection(get_class($dispatcher)); $property = $reflection->getProperty('container'); - $property->setAccessible(true); $this->assertEquals($container, $property->getValue($dispatcher)); } @@ -66,7 +65,6 @@ class DispatcherTest extends TestCase $reflection = new Reflection(get_class($dispatcher)); $property = $reflection->getProperty('next'); - $property->setAccessible(true); $this->assertEquals($handler, $property->getValue($dispatcher)); } @@ -113,7 +111,6 @@ class DispatcherTest extends TestCase $reflection = new Reflection(get_class($dispatcher)); $property = $reflection->getProperty('next'); - $property->setAccessible(true); $property->setValue($dispatcher, $handler); $return = $dispatcher->handle($request); @@ -193,7 +190,6 @@ class DispatcherTest extends TestCase $reflection = new Reflection(get_class($middleware)); $property = $reflection->getProperty('container'); - $property->setAccessible(true); $this->assertEquals($container, $property->getValue($middleware)); } diff --git a/tests/Unit/Middleware/RequestHandlerTest.php b/tests/Unit/Middleware/RequestHandlerTest.php index ae8fb3d5..f629f722 100644 --- a/tests/Unit/Middleware/RequestHandlerTest.php +++ b/tests/Unit/Middleware/RequestHandlerTest.php @@ -33,7 +33,6 @@ class RequestHandlerTest extends TestCase $reflection = new Reflection(get_class($handler)); $property = $reflection->getProperty('container'); - $property->setAccessible(true); $this->assertEquals($container, $property->getValue($handler)); } diff --git a/tests/Unit/Models/EventConfigTest.php b/tests/Unit/Models/EventConfigTest.php index d51dd83f..ca8ae9e5 100644 --- a/tests/Unit/Models/EventConfigTest.php +++ b/tests/Unit/Models/EventConfigTest.php @@ -93,8 +93,6 @@ class EventConfigTest extends ModelTest { $model = new EventConfig(['name' => 'foo', 'value' => 'bar']); $this->assertEquals('bar', $model->value); - - return; } /** diff --git a/tests/Unit/Models/NewsCommentsTest.php b/tests/Unit/Models/NewsCommentsTest.php index 1769e340..22b90114 100644 --- a/tests/Unit/Models/NewsCommentsTest.php +++ b/tests/Unit/Models/NewsCommentsTest.php @@ -17,7 +17,6 @@ class NewsCommentsTest extends ModelTest private News $news; - /** @var array */ private array $newsCommentData; /** diff --git a/tests/Unit/Models/NewsTest.php b/tests/Unit/Models/NewsTest.php index e64f0d7b..1330d02f 100644 --- a/tests/Unit/Models/NewsTest.php +++ b/tests/Unit/Models/NewsTest.php @@ -12,7 +12,6 @@ use Engelsystem\Models\User\User; */ class NewsTest extends ModelTest { - /** @var array */ private array $newsData; private User $user; diff --git a/tests/Unit/Renderer/Twig/Extensions/ExtensionTest.php b/tests/Unit/Renderer/Twig/Extensions/ExtensionTest.php index f876b57e..6ae3c078 100644 --- a/tests/Unit/Renderer/Twig/Extensions/ExtensionTest.php +++ b/tests/Unit/Renderer/Twig/Extensions/ExtensionTest.php @@ -9,6 +9,7 @@ use Engelsystem\Test\Unit\TestCase; use Exception; use PHPUnit\Framework\MockObject\MockObject; use Twig\Node\Node as TwigNode; +use Twig\TwigFilter; use Twig\TwigFunction; abstract class ExtensionTest extends TestCase @@ -35,9 +36,9 @@ abstract class ExtensionTest extends TestCase } /** - * Assert that a twig function was registered + * Assert that a twig function or filter was registered * - * @param TwigFunction[] $functions + * @param TwigFunction[]|TwigFilter[] $functions * @throws Exception */ protected function assertExtensionExists( diff --git a/tests/Unit/Renderer/TwigLoaderTest.php b/tests/Unit/Renderer/TwigLoaderTest.php index bcf18f12..aac0e2e3 100644 --- a/tests/Unit/Renderer/TwigLoaderTest.php +++ b/tests/Unit/Renderer/TwigLoaderTest.php @@ -19,7 +19,6 @@ class TwigLoaderTest extends TestCase $reflection = new Reflection(get_class($loader)); $property = $reflection->getProperty('cache'); - $property->setAccessible(true); $realPath = __DIR__ . '/Stub/foo.twig'; $property->setValue($loader, ['Stub/foo.twig' => $realPath]); diff --git a/tests/Unit/Renderer/TwigServiceProviderTest.php b/tests/Unit/Renderer/TwigServiceProviderTest.php index 37d1f50c..16bacf1d 100644 --- a/tests/Unit/Renderer/TwigServiceProviderTest.php +++ b/tests/Unit/Renderer/TwigServiceProviderTest.php @@ -197,7 +197,6 @@ class TwigServiceProviderTest extends ServiceProviderTest $reflection = new Reflection(get_class($serviceProvider)); $property = $reflection->getProperty('extensions'); - $property->setAccessible(true); $property->setValue($serviceProvider, $extensions); }