diff --git a/module/CLI/src/Factory/ApplicationFactory.php b/module/CLI/src/Factory/ApplicationFactory.php index 262238a3..ab716f7e 100644 --- a/module/CLI/src/Factory/ApplicationFactory.php +++ b/module/CLI/src/Factory/ApplicationFactory.php @@ -17,7 +17,7 @@ class ApplicationFactory $appOptions = $container->get(AppOptions::class); $commands = $config['commands'] ?? []; - $app = new CliApp($appOptions->getName(), $appOptions->getVersion()); + $app = new CliApp($appOptions->name, $appOptions->version); $app->setCommandLoader(new ContainerCommandLoader($container, $commands)); return $app; diff --git a/module/Core/config/dependencies.config.php b/module/Core/config/dependencies.config.php index d6cbd72a..54a861e6 100644 --- a/module/Core/config/dependencies.config.php +++ b/module/Core/config/dependencies.config.php @@ -21,7 +21,7 @@ return [ ErrorHandler\NotFoundRedirectHandler::class => ConfigAbstractFactory::class, ErrorHandler\NotFoundTemplateHandler::class => InvokableFactory::class, - Options\AppOptions::class => ConfigAbstractFactory::class, + Options\AppOptions::class => [ValinorConfigFactory::class, 'config.app_options'], Options\DeleteShortUrlsOptions::class => ConfigAbstractFactory::class, Options\NotFoundRedirectOptions::class => ConfigAbstractFactory::class, Options\RedirectOptions::class => ConfigAbstractFactory::class, @@ -86,7 +86,6 @@ return [ Domain\DomainService::class, ], - Options\AppOptions::class => ['config.app_options'], Options\DeleteShortUrlsOptions::class => ['config.delete_short_urls'], Options\NotFoundRedirectOptions::class => ['config.not_found_redirects'], Options\RedirectOptions::class => ['config.redirects'], diff --git a/module/Core/src/Options/AppOptions.php b/module/Core/src/Options/AppOptions.php index e81f9fdb..ec545352 100644 --- a/module/Core/src/Options/AppOptions.php +++ b/module/Core/src/Options/AppOptions.php @@ -4,35 +4,12 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\Options; -use Laminas\Stdlib\AbstractOptions; - use function sprintf; -class AppOptions extends AbstractOptions +final class AppOptions { - private string $name = 'Shlink'; - private string $version = '3.0.0'; - - public function getName(): string + public function __construct(public string $name = 'Shlink', public string $version = '3.0.0') { - return $this->name; - } - - protected function setName(string $name): self - { - $this->name = $name; - return $this; - } - - public function getVersion(): string - { - return $this->version; - } - - protected function setVersion(string $version): self - { - $this->version = $version; - return $this; } public function __toString(): string diff --git a/module/Core/test/EventDispatcher/NotifyVisitToWebHooksTest.php b/module/Core/test/EventDispatcher/NotifyVisitToWebHooksTest.php index 6be8719a..4234a188 100644 --- a/module/Core/test/EventDispatcher/NotifyVisitToWebHooksTest.php +++ b/module/Core/test/EventDispatcher/NotifyVisitToWebHooksTest.php @@ -165,7 +165,7 @@ class NotifyVisitToWebHooksTest extends TestCase ['webhooks' => $webhooks, 'notify_orphan_visits_to_webhooks' => $notifyOrphanVisits], ), new ShortUrlDataTransformer(new ShortUrlStringifier([])), - new AppOptions(['name' => 'Shlink', 'version' => '1.2.3']), + new AppOptions('Shlink', '1.2.3'), ); } } diff --git a/module/Rest/src/Action/HealthAction.php b/module/Rest/src/Action/HealthAction.php index 462eb345..f3bfea98 100644 --- a/module/Rest/src/Action/HealthAction.php +++ b/module/Rest/src/Action/HealthAction.php @@ -42,7 +42,7 @@ class HealthAction extends AbstractRestAction $statusCode = $connected ? self::STATUS_OK : self::STATUS_SERVICE_UNAVAILABLE; return new JsonResponse([ 'status' => $connected ? self::STATUS_PASS : self::STATUS_FAIL, - 'version' => $this->options->getVersion(), + 'version' => $this->options->version, 'links' => [ 'about' => 'https://shlink.io', 'project' => 'https://github.com/shlinkio/shlink', diff --git a/module/Rest/test/Action/HealthActionTest.php b/module/Rest/test/Action/HealthActionTest.php index 8298b2d1..461152a4 100644 --- a/module/Rest/test/Action/HealthActionTest.php +++ b/module/Rest/test/Action/HealthActionTest.php @@ -36,7 +36,7 @@ class HealthActionTest extends TestCase $em = $this->prophesize(EntityManagerInterface::class); $em->getConnection()->willReturn($this->conn->reveal()); - $this->action = new HealthAction($em->reveal(), new AppOptions(['version' => '1.2.3'])); + $this->action = new HealthAction($em->reveal(), new AppOptions(version: '1.2.3')); } /** @test */