Skip to content

Commit

Permalink
[connector][ns-panel] NS Panel PRO connector (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Jul 18, 2023
1 parent f1fe82c commit dca9147
Show file tree
Hide file tree
Showing 21 changed files with 83 additions and 83 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"nettrine/orm": "^0.8",
"psr/event-dispatcher": "^1.0",
"react/event-loop": "^1.3",
"react/promise": "~2.2",
"symfony/console": "^5.0|^6.0",
"symfony/event-dispatcher": "^5.4",
"symplify/vendor-patches": "^11.2"
Expand All @@ -69,7 +70,7 @@
"pds/skeleton": "^1.0",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "1.10.11",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-doctrine": "^1.3",
"phpstan/phpstan-nette": "^1.1",
Expand Down
6 changes: 1 addition & 5 deletions src/Commands/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ class Connector extends Console\Command\Command implements EventDispatcher\Event
/** @var SplObjectStorage<Connectors\ConnectorFactory, string> */
private SplObjectStorage $factories;

private Log\LoggerInterface $logger;

private EventLoop\TimerInterface|null $databaseRefreshTimer = null;

/**
Expand All @@ -92,12 +90,10 @@ public function __construct(
private readonly EventLoop\LoopInterface $eventLoop,
private readonly array $exchangeFactories = [],
private readonly PsrEventDispatcher\EventDispatcherInterface|null $dispatcher = null,
Log\LoggerInterface|null $logger = null,
private readonly Log\LoggerInterface $logger = new Log\NullLogger(),
string|null $name = null,
)
{
$this->logger = $logger ?? new Log\NullLogger();

$this->factories = new SplObjectStorage();

parent::__construct($name);
Expand Down
6 changes: 1 addition & 5 deletions src/Commands/Exchange.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ final class Exchange extends Console\Command\Command

public const NAME = 'fb:devices-module:exchange';

private Log\LoggerInterface $logger;

/**
* @param array<ExchangeExchange\Factory> $exchangeFactories
*/
Expand All @@ -58,13 +56,11 @@ public function __construct(
private readonly ExchangeConsumers\Container $consumer,
private readonly array $exchangeFactories = [],
private readonly EventDispatcher\EventDispatcherInterface|null $dispatcher = null,
Log\LoggerInterface|null $logger = null,
private readonly Log\LoggerInterface $logger = new Log\NullLogger(),
string|null $name = null,
)
{
parent::__construct($name);

$this->logger = $logger ?? new Log\NullLogger();
}

/**
Expand Down
6 changes: 1 addition & 5 deletions src/Commands/Initialize.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,11 @@ class Initialize extends Console\Command\Command

public const NAME = 'fb:devices-module:initialize';

private Log\LoggerInterface $logger;

public function __construct(
Log\LoggerInterface|null $logger = null,
private readonly Log\LoggerInterface $logger = new Log\NullLogger(),
string|null $name = null,
)
{
$this->logger = $logger ?? new Log\NullLogger();

parent::__construct($name);
}

Expand Down
5 changes: 1 addition & 4 deletions src/Consumers/Sockets.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,12 @@
final class Sockets implements ExchangeConsumer\Consumer
{

private Log\LoggerInterface $logger;

public function __construct(
private readonly WebSockets\Router\LinkGenerator $linkGenerator,
private readonly WebSocketsWAMP\Topics\IStorage $topicsStorage,
Log\LoggerInterface|null $logger = null,
private readonly Log\LoggerInterface $logger = new Log\NullLogger(),
)
{
$this->logger = $logger ?? new Log\NullLogger();
}

public function consume(
Expand Down
6 changes: 1 addition & 5 deletions src/Controllers/ExchangeV1.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@
final class ExchangeV1 extends WebSockets\Application\Controller\Controller
{

private Log\LoggerInterface $logger;

public function __construct(
private readonly Models\Connectors\Properties\PropertiesRepository $connectorPropertiesRepository,
private readonly Models\Devices\Properties\PropertiesRepository $devicePropertiesRepository,
Expand All @@ -63,12 +61,10 @@ public function __construct(
private readonly MetadataLoaders\SchemaLoader $schemaLoader,
private readonly MetadataSchemas\Validator $jsonValidator,
private readonly ExchangeEntities\EntityFactory $entityFactory,
Log\LoggerInterface|null $logger = null,
private readonly Log\LoggerInterface $logger = new Log\NullLogger(),
)
{
parent::__construct();

$this->logger = $logger ?? new Log\NullLogger();
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Entities/Channels/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public function __construct(
Uuid\UuidInterface|null $id = null,
)
{
// @phpstan-ignore-next-line
$this->id = $id ?? Uuid\Uuid::uuid4();

$this->device = $device;
Expand Down
2 changes: 0 additions & 2 deletions src/Entities/Channels/Controls/Control.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ class Control implements Entities\Entity,

public function __construct(string $name, Entities\Channels\Channel $channel)
{
$this->id = Uuid\Uuid::uuid4();

$this->name = $name;
$this->channel = $channel;

Expand Down
1 change: 1 addition & 0 deletions src/Entities/Connectors/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public function __construct(
Uuid\UuidInterface|null $id = null,
)
{
// @phpstan-ignore-next-line
$this->id = $id ?? Uuid\Uuid::uuid4();

$this->identifier = $identifier;
Expand Down
2 changes: 0 additions & 2 deletions src/Entities/Connectors/Controls/Control.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ class Control implements Entities\Entity,

public function __construct(string $name, Entities\Connectors\Connector $connector)
{
$this->id = Uuid\Uuid::uuid4();

$this->name = $name;
$this->connector = $connector;

Expand Down
2 changes: 0 additions & 2 deletions src/Entities/Devices/Controls/Control.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ class Control implements Entities\Entity,

public function __construct(string $name, Entities\Devices\Device $device)
{
$this->id = Uuid\Uuid::uuid4();

$this->name = $name;
$this->device = $device;

Expand Down
1 change: 1 addition & 0 deletions src/Entities/Devices/Device.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public function __construct(
Uuid\UuidInterface|null $id = null,
)
{
// @phpstan-ignore-next-line
$this->id = $id ?? Uuid\Uuid::uuid4();

$this->identifier = $identifier;
Expand Down
3 changes: 2 additions & 1 deletion src/Entities/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public function __construct(
Uuid\UuidInterface|null $id = null,
)
{
// @phpstan-ignore-next-line
$this->id = $id ?? Uuid\Uuid::uuid4();

$this->identifier = $identifier;
Expand Down Expand Up @@ -288,7 +289,7 @@ public function setFormat(array|string|null $format): void
return implode(
'|',
array_map(
static fn ($part): string|int|float => is_array($part) ? strval($part) : $part,
static fn ($part): string|int|float => is_array($part) ? implode($part) : $part,
(array) $item,
),
);
Expand Down
2 changes: 1 addition & 1 deletion src/Hydrators/Properties/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ protected function hydrateFormatAttribute(JsonAPIDocument\Objects\IStandardObjec
return implode(
'|',
array_map(
static fn ($part): string|int|float => is_array($part) ? strval($part) : $part,
static fn ($part): string|int|float => is_array($part) ? implode($part) : $part,
(array) $item,
),
);
Expand Down
20 changes: 10 additions & 10 deletions src/Models/Devices/DevicesRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public function __construct(
/**
* @template T of Entities\Devices\Device
*
* @phpstan-param Queries\FindDevices<T> $queryObject
* @phpstan-param class-string<T> $type
* @param Queries\FindDevices<T> $queryObject
* @param class-string<T> $type
*
* @throws Exceptions\InvalidState
*/
Expand All @@ -69,10 +69,10 @@ public function findOneBy(
/**
* @template T of Entities\Devices\Device
*
* @phpstan-param Queries\FindDevices<T> $queryObject
* @phpstan-param class-string<T> $type
* @param Queries\FindDevices<T> $queryObject
* @param class-string<T> $type
*
* @phpstan-return array<T>
* @return array<T>
*
* @throws Exceptions\InvalidState
*/
Expand Down Expand Up @@ -102,10 +102,10 @@ function () use ($queryObject, $type): array {
/**
* @template T of Entities\Devices\Device
*
* @phpstan-param Queries\FindDevices<T> $queryObject
* @phpstan-param class-string<T> $type
* @param Queries\FindDevices<T> $queryObject
* @param class-string<T> $type
*
* @phpstan-return DoctrineOrmQuery\ResultSet<T>
* @return DoctrineOrmQuery\ResultSet<T>
*
* @throws Exceptions\InvalidState
*/
Expand All @@ -130,9 +130,9 @@ function () use ($queryObject, $type): DoctrineOrmQuery\ResultSet {
/**
* @template T of Entities\Devices\Device
*
* @phpstan-param class-string<T> $type
* @param class-string<T> $type
*
* @phpstan-return ORM\EntityRepository<T>
* @return ORM\EntityRepository<T>
*/
private function getRepository(string $type): ORM\EntityRepository
{
Expand Down
12 changes: 10 additions & 2 deletions src/Queries/FindChannels.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,16 @@ public function forDevice(Entities\Devices\Device $device): void
public function byDeviceId(Uuid\UuidInterface $deviceId): void
{
$this->filter[] = static function (ORM\QueryBuilder $qb) use ($deviceId): void {
$qb->andWhere('device.id = :device')
->setParameter('device', $deviceId, Uuid\Doctrine\UuidBinaryType::NAME);
$qb->andWhere('device.id = :deviceId')
->setParameter('deviceId', $deviceId, Uuid\Doctrine\UuidBinaryType::NAME);
};
}

public function byDeviceIdentifier(string $deviceIdentifier): void
{
$this->filter[] = static function (ORM\QueryBuilder $qb) use ($deviceIdentifier): void {
$qb->andWhere('device.identifier = :deviceIdentifier')
->setParameter('deviceIdentifier', $deviceIdentifier);
};
}

Expand Down
5 changes: 1 addition & 4 deletions src/Utilities/ChannelPropertiesStates.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,13 @@ final class ChannelPropertiesStates

use Nette\SmartObject;

private Log\LoggerInterface $logger;

public function __construct(
private readonly Models\Channels\Properties\PropertiesRepository $channelPropertiesRepository,
private readonly Models\States\ChannelPropertiesRepository $channelPropertyStateRepository,
private readonly Models\States\ChannelPropertiesManager $channelPropertiesStatesManager,
Log\LoggerInterface|null $logger = null,
private readonly Log\LoggerInterface $logger = new Log\NullLogger(),
)
{
$this->logger = $logger ?? new Log\NullLogger();
}

/**
Expand Down
5 changes: 1 addition & 4 deletions src/Utilities/ConnectorPropertiesStates.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,12 @@ final class ConnectorPropertiesStates

use Nette\SmartObject;

private Log\LoggerInterface $logger;

public function __construct(
private readonly Models\States\ConnectorPropertiesRepository $connectorPropertyStateRepository,
private readonly Models\States\ConnectorPropertiesManager $connectorPropertiesStatesManager,
Log\LoggerInterface|null $logger = null,
private readonly Log\LoggerInterface $logger = new Log\NullLogger(),
)
{
$this->logger = $logger ?? new Log\NullLogger();
}

/**
Expand Down
5 changes: 1 addition & 4 deletions src/Utilities/DevicePropertiesStates.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,13 @@ final class DevicePropertiesStates

use Nette\SmartObject;

private Log\LoggerInterface $logger;

public function __construct(
private readonly Models\Devices\Properties\PropertiesRepository $devicePropertiesRepository,
private readonly Models\States\DevicePropertiesRepository $devicePropertyStateRepository,
private readonly Models\States\DevicePropertiesManager $devicePropertiesStatesManager,
Log\LoggerInterface|null $logger = null,
private readonly Log\LoggerInterface $logger = new Log\NullLogger(),
)
{
$this->logger = $logger ?? new Log\NullLogger();
}

/**
Expand Down
Loading

0 comments on commit dca9147

Please sign in to comment.