diff --git a/src/Command/CreateAdminCommand.php b/src/Command/CreateAdminCommand.php index f17dba8e..a014973b 100644 --- a/src/Command/CreateAdminCommand.php +++ b/src/Command/CreateAdminCommand.php @@ -6,6 +6,7 @@ use Buddy\Repman\Message\Admin\ChangeConfig; use Buddy\Repman\Message\User\CreateUser; +use Buddy\Repman\Service\Config; use Buddy\Repman\Service\Telemetry; use Ramsey\Uuid\Uuid; use Symfony\Component\Console\Command\Command; @@ -67,7 +68,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int if ($this->getHelper('question')->ask($input, $output, $question) === true) { $this->bus->dispatch(new ChangeConfig([ - 'telemetry' => 'enabled', + Config::TELEMETRY => Config::TELEMETRY_ENABLED, ])); } diff --git a/src/Controller/Admin/ConfigController.php b/src/Controller/Admin/ConfigController.php index 2338d626..af3eee94 100644 --- a/src/Controller/Admin/ConfigController.php +++ b/src/Controller/Admin/ConfigController.php @@ -50,7 +50,9 @@ public function toggleTelemetry(Request $request): Response { $this->telemetry->generateInstanceId(); $this->dispatchMessage(new ChangeConfig([ - 'telemetry' => $request->isMethod(Request::METHOD_POST) ? 'enable' : 'disable', + Config::TELEMETRY => $request->isMethod(Request::METHOD_POST) + ? Config::TELEMETRY_ENABLED + : Config::TELEMETRY_DISABLED, ])); return $this->redirectToRoute('index'); diff --git a/src/Form/Type/Admin/ConfigType.php b/src/Form/Type/Admin/ConfigType.php index ce781178..18e914d2 100644 --- a/src/Form/Type/Admin/ConfigType.php +++ b/src/Form/Type/Admin/ConfigType.php @@ -4,6 +4,7 @@ namespace Buddy\Repman\Form\Type\Admin; +use Buddy\Repman\Service\Config; use Buddy\Repman\Service\Telemetry; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; @@ -53,10 +54,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'data-style' => 'btn-secondary', ], ]) - ->add('telemetry', ChoiceType::class, [ + ->add(Config::TELEMETRY, ChoiceType::class, [ 'choices' => [ - 'enabled' => 'enabled', - 'disabled' => 'disabled', + Config::TELEMETRY_ENABLED => Config::TELEMETRY_ENABLED, + Config::TELEMETRY_DISABLED => Config::TELEMETRY_DISABLED, ], 'help' => "Enable collecting and sending anonymous usage data (telemetry->docsUrl()}\" target=\"_blank\" rel=\"noopener noreferrer\">more info)", 'attr' => [ diff --git a/src/Service/Config.php b/src/Service/Config.php index 99e62238..576c8b6c 100644 --- a/src/Service/Config.php +++ b/src/Service/Config.php @@ -10,6 +10,9 @@ final class Config { const CACHE_KEY = 'values'; + const TELEMETRY = 'telemetry'; + const TELEMETRY_ENABLED = 'enabled'; + const TELEMETRY_DISABLED = 'disabled'; private ConfigQuery $configQuery; private CacheInterface $cache; @@ -54,7 +57,7 @@ public function userRegistrationEnabled(): bool public function telemetryEnabled(): bool { - return $this->get('telemetry') === 'enabled'; + return $this->get('telemetry') === self::TELEMETRY_ENABLED; } /** diff --git a/tests/Functional/Command/SendTelemetryCommandTest.php b/tests/Functional/Command/SendTelemetryCommandTest.php index 68c1e055..e00fcb39 100644 --- a/tests/Functional/Command/SendTelemetryCommandTest.php +++ b/tests/Functional/Command/SendTelemetryCommandTest.php @@ -5,6 +5,7 @@ namespace Buddy\Repman\Tests\Functional\Command; use Buddy\Repman\Command\SendTelemetryCommand; +use Buddy\Repman\Service\Config; use Buddy\Repman\Service\Telemetry\TelemetryEndpoint; use Buddy\Repman\Tests\Functional\FunctionalTestCase; use Ramsey\Uuid\Uuid; @@ -26,7 +27,7 @@ public function testSendTelemetryWithoutInstanceIdFile(): void public function testSendTelemetryWithTelemetryDisabled(): void { $this->generateInstanceIdFile(); - $this->fixtures->changeConfig('telemetry', 'disabled'); + $this->fixtures->changeConfig(Config::TELEMETRY, Config::TELEMETRY_DISABLED); $commandTester = new CommandTester( $this->container()->get(SendTelemetryCommand::class) @@ -40,7 +41,7 @@ public function testSendTelemetry(): void $this->fixtures->createPackage(Uuid::uuid4()->toString()); $this->generateInstanceIdFile(); - $this->fixtures->changeConfig('telemetry', 'enabled'); + $this->fixtures->changeConfig(Config::TELEMETRY, Config::TELEMETRY_ENABLED); $commandTester = new CommandTester( $this->container()->get(SendTelemetryCommand::class)