Skip to content

Commit

Permalink
[homekit-connector] Refactoring commands (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Dec 16, 2023
1 parent 0dc2d39 commit 1275fd3
Showing 1 changed file with 16 additions and 23 deletions.
39 changes: 16 additions & 23 deletions src/Commands/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,9 @@ private function createConnector(Style\SymfonyStyle $io): void
true,
);

$createRegisters = (bool) $io->askQuestion($question);
$createDevices = (bool) $io->askQuestion($question);

if ($createRegisters) {
if ($createDevices) {
$this->createDevice($io, $connector);
}
}
Expand Down Expand Up @@ -659,13 +659,9 @@ private function listConnectors(Style\SymfonyStyle $io): void
$connectors = $this->connectorsRepository->findAllBy($findConnectorsQuery, Entities\FbMqttConnector::class);
usort(
$connectors,
static function (Entities\FbMqttConnector $a, Entities\FbMqttConnector $b): int {
if ($a->getIdentifier() === $b->getIdentifier()) {
return $a->getName() <=> $b->getName();
}

return $a->getIdentifier() <=> $b->getIdentifier();
},
static fn (Entities\FbMqttConnector $a, Entities\FbMqttConnector $b): int => (
($a->getName() ?? $a->getIdentifier()) <=> ($b->getName() ?? $b->getIdentifier())
),
);

$table = new Console\Helper\Table($io);
Expand Down Expand Up @@ -947,13 +943,9 @@ private function listDevices(Style\SymfonyStyle $io, Entities\FbMqttConnector $c
$devices = $this->devicesRepository->findAllBy($findDevicesQuery, Entities\FbMqttDevice::class);
usort(
$devices,
static function (Entities\FbMqttDevice $a, Entities\FbMqttDevice $b): int {
if ($a->getIdentifier() === $b->getIdentifier()) {
return $a->getName() <=> $b->getName();
}

return $a->getIdentifier() <=> $b->getIdentifier();
},
static fn (Entities\FbMqttDevice $a, Entities\FbMqttDevice $b): int => (
($a->getName() ?? $a->getIdentifier()) <=> ($b->getName() ?? $b->getIdentifier())
),
);

$table = new Console\Helper\Table($io);
Expand Down Expand Up @@ -1341,13 +1333,13 @@ private function askWhichConnector(Style\SymfonyStyle $io): Entities\FbMqttConne
);
usort(
$systemConnectors,
// phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
static fn (Entities\FbMqttConnector $a, Entities\FbMqttConnector $b): int => $a->getIdentifier() <=> $b->getIdentifier()
static fn (Entities\FbMqttConnector $a, Entities\FbMqttConnector $b): int => (
($a->getName() ?? $a->getIdentifier()) <=> ($b->getName() ?? $b->getIdentifier())
),
);

foreach ($systemConnectors as $connector) {
$connectors[$connector->getIdentifier()] = $connector->getIdentifier()
. ($connector->getName() !== null ? ' [' . $connector->getName() . ']' : '');
$connectors[$connector->getIdentifier()] = $connector->getName() ?? $connector->getIdentifier();
}

if (count($connectors) === 0) {
Expand Down Expand Up @@ -1426,12 +1418,13 @@ private function askWhichDevice(
);
usort(
$connectorDevices,
static fn (Entities\FbMqttDevice $a, Entities\FbMqttDevice $b): int => $a->getIdentifier() <=> $b->getIdentifier()
static fn (Entities\FbMqttDevice $a, Entities\FbMqttDevice $b): int => (
($a->getName() ?? $a->getIdentifier()) <=> ($b->getName() ?? $b->getIdentifier())
),
);

foreach ($connectorDevices as $device) {
$devices[$device->getIdentifier()] = $device->getIdentifier()
. ($device->getName() !== null ? ' [' . $device->getName() . ']' : '');
$devices[$device->getIdentifier()] = $device->getName() ?? $device->getIdentifier();
}

if (count($devices) === 0) {
Expand Down

0 comments on commit 1275fd3

Please sign in to comment.