diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3c6aba3..c72e808 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,6 +41,8 @@ jobs: - run: php bin/phpspec run -f dot -n + - run: php bin/phpstan + ci: runs-on: ubuntu-latest strategy: diff --git a/composer.json b/composer.json index aa7a48e..16ade5d 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,10 @@ }, "require-dev": { "phpspec/phpspec": "^7.2", - "friendsofphp/php-cs-fixer": "^3.8" + "friendsofphp/php-cs-fixer": "^3.8", + "phpstan/phpstan": "^1.6", + "phpstan/phpstan-strict-rules": "^1.2", + "phpstan/phpstan-symfony": "^1.1" }, "minimum-stability": "beta", "autoload": { diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000..dbcb87b --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,31 @@ +parameters: + ignoreErrors: + - + message: "#^Parameter \\#2 \\$eventName of method Symfony\\\\Contracts\\\\EventDispatcher\\\\EventDispatcherInterface\\:\\:dispatch\\(\\) expects string\\|null, mixed given\\.$#" + count: 1 + path: src/Client/Client.php + + - + message: "#^Parameter \\#1 \\$callback of function array_map expects \\(callable\\(mixed\\)\\: mixed\\)\\|null, Closure\\(Yproximite\\\\Bundle\\\\InfluxDbPresetBundle\\\\Point\\\\PointPreset\\)\\: array\\\\|string\\> given\\.$#" + count: 1 + path: src/DataCollector/ClientRequest.php + + - + message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeDefinition\\:\\:children\\(\\)\\.$#" + count: 4 + path: src/DependencyInjection/Configuration.php + + - + message: "#^Parameter \\#1 \\$config of method Yproximite\\\\Bundle\\\\InfluxDbPresetBundle\\\\DependencyInjection\\\\YproximiteInfluxDbPresetExtension\\:\\:registerEvents\\(\\) expects array\\{profiles\\: array\\, fields\\: array\\\\}\\>\\}\\>\\}, array given\\.$#" + count: 1 + path: src/DependencyInjection/YproximiteInfluxDbPresetExtension.php + + - + message: "#^Parameter \\#1 \\$config of method Yproximite\\\\Bundle\\\\InfluxDbPresetBundle\\\\DependencyInjection\\\\YproximiteInfluxDbPresetExtension\\:\\:registerExtensions\\(\\) expects array\\{default_profile_name\\: string, extensions\\: array\\\\}, array given\\.$#" + count: 1 + path: src/DependencyInjection/YproximiteInfluxDbPresetExtension.php + + - + message: "#^Parameter \\#1 \\$config of method Yproximite\\\\Bundle\\\\InfluxDbPresetBundle\\\\DependencyInjection\\\\YproximiteInfluxDbPresetExtension\\:\\:registerProfiles\\(\\) expects array\\{profiles\\: array\\, fields\\: array\\\\}\\>, connections\\: array\\\\}\\>\\}, array given\\.$#" + count: 1 + path: src/DependencyInjection/YproximiteInfluxDbPresetExtension.php diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..e8d0920 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,13 @@ +includes: + - vendor/phpstan/phpstan-strict-rules/rules.neon + - vendor/phpstan/phpstan-symfony/extension.neon + - vendor/phpstan/phpstan-symfony/rules.neon + - phpstan-baseline.neon + +parameters: + level: max + + paths: + - src + + inferPrivatePropertyTypeFromConstructor: true diff --git a/src/Client/Client.php b/src/Client/Client.php index a5386c9..86c2e5e 100644 --- a/src/Client/Client.php +++ b/src/Client/Client.php @@ -19,9 +19,6 @@ use Yproximite\InfluxDbBundle\Events\HttpEvent; use Yproximite\InfluxDbBundle\Events\UdpEvent; -/** - * Class Client - */ class Client implements ClientInterface { /** @@ -53,9 +50,9 @@ public function sendPoint( string $profileName, string $presetName, float $value, - \DateTimeInterface $dateTime = null - ) { - if (!$dateTime) { + ?\DateTimeInterface $dateTime = null + ): void { + if (null === $dateTime) { $dateTime = new \DateTime(); } @@ -77,13 +74,12 @@ private function buildPoint(PointPresetInterface $preset, float $value, \DateTim $builder ->setPreset($preset) ->setValue($value) - ->setDateTime($dateTime) - ; + ->setDateTime($dateTime); return $builder->build(); } - private function sendPointUsingConnection(Point $point, ConnectionInterface $connection) + private function sendPointUsingConnection(Point $point, ConnectionInterface $connection): void { $class = $this->getEventClassName($connection); $event = new $class([$point], Database::PRECISION_SECONDS, $connection->getName()); diff --git a/src/Client/ClientInterface.php b/src/Client/ClientInterface.php index cbaa881..6d6cab1 100644 --- a/src/Client/ClientInterface.php +++ b/src/Client/ClientInterface.php @@ -4,15 +4,12 @@ namespace Yproximite\Bundle\InfluxDbPresetBundle\Client; -/** - * Interface ClientInterface - */ interface ClientInterface { public function sendPoint( string $profileName, string $presetName, float $value, - \DateTimeInterface $dateTime = null - ); + ?\DateTimeInterface $dateTime = null + ): void; } diff --git a/src/Connection/Connection.php b/src/Connection/Connection.php index 845a850..871d8e8 100644 --- a/src/Connection/Connection.php +++ b/src/Connection/Connection.php @@ -4,9 +4,6 @@ namespace Yproximite\Bundle\InfluxDbPresetBundle\Connection; -/** - * Class Connection - */ class Connection implements ConnectionInterface { /** diff --git a/src/Connection/ConnectionFactory.php b/src/Connection/ConnectionFactory.php index 66d0443..eda75d7 100644 --- a/src/Connection/ConnectionFactory.php +++ b/src/Connection/ConnectionFactory.php @@ -4,9 +4,6 @@ namespace Yproximite\Bundle\InfluxDbPresetBundle\Connection; -/** - * Class ConnectionFactory - */ class ConnectionFactory implements ConnectionFactoryInterface { public function create(): ConnectionInterface diff --git a/src/Connection/ConnectionFactoryInterface.php b/src/Connection/ConnectionFactoryInterface.php index d23b356..89d4dec 100644 --- a/src/Connection/ConnectionFactoryInterface.php +++ b/src/Connection/ConnectionFactoryInterface.php @@ -4,12 +4,12 @@ namespace Yproximite\Bundle\InfluxDbPresetBundle\Connection; -/** - * Interface ConnectionFactoryInterface - */ interface ConnectionFactoryInterface { public function create(): ConnectionInterface; + /** + * @param array{ name:string, protocol:string, deferred:bool } $config + */ public function createFromConfig(array $config): ConnectionInterface; } diff --git a/src/Connection/ConnectionInterface.php b/src/Connection/ConnectionInterface.php index eecb26e..91fee5c 100644 --- a/src/Connection/ConnectionInterface.php +++ b/src/Connection/ConnectionInterface.php @@ -4,9 +4,6 @@ namespace Yproximite\Bundle\InfluxDbPresetBundle\Connection; -/** - * Interface ConnectionInterface - */ interface ConnectionInterface { public const PROTOCOL_UDP = 'udp'; diff --git a/src/DataCollector/ClientRequest.php b/src/DataCollector/ClientRequest.php index 5b52f6c..f24b3de 100644 --- a/src/DataCollector/ClientRequest.php +++ b/src/DataCollector/ClientRequest.php @@ -11,10 +11,7 @@ use Yproximite\Bundle\InfluxDbPresetBundle\Profile\Profile; use Yproximite\Bundle\InfluxDbPresetBundle\Profile\ProfileInterface; -/** - * Class ClientRequest - */ -class ClientRequest implements \Serializable +class ClientRequest { /** * @var ProfileInterface @@ -68,9 +65,12 @@ public function getDateTime(): \DateTimeInterface return $this->dateTime; } - public function serialize() + /** + * @return array|null> + */ + public function __serialize(): array { - return serialize([ + return [ $this->value, $this->dateTime, $this->profile->getName(), @@ -81,12 +81,22 @@ public function serialize() return $this->serializePointPreset($pointPreset); }, $this->profile->getPointPresets()), $this->serializePointPreset($this->pointPreset), - ]); + ]; } - public function unserialize($serialized) + /** + * @param array{ + * 0:float, + * 1:\DateTimeInterface, + * 2:string, + * 3:array, + * 4:array, 2:string, 3:array }>, + * 5:array{ 0:string, 1:array, 2:string, 3:array } + * } $serialized + */ + public function __unserialize(array $serialized): void { - list($this->value, $this->dateTime, $profileName, $profileConnections, $profilePointPresets, $pointPreset) = unserialize($serialized); + [$this->value, $this->dateTime, $profileName, $profileConnections, $profilePointPresets, $pointPreset] = $serialized; $this->pointPreset = $this->unserializePointPreset($pointPreset); @@ -97,11 +107,14 @@ public function unserialize($serialized) $this->profile->addConnection($this->unserializeConnection($connection)); } - foreach ($profilePointPresets as $pointPreset) { - $this->profile->addPointPreset($this->unserializePointPreset($pointPreset)); + foreach ($profilePointPresets as $profilePointPreset) { + $this->profile->addPointPreset($this->unserializePointPreset($profilePointPreset)); } } + /** + * @return array> + */ protected function serializePointPreset(PointPresetInterface $pointPreset): array { return [ @@ -112,6 +125,9 @@ protected function serializePointPreset(PointPresetInterface $pointPreset): arra ]; } + /** + * @param array{ 0:string, 1:array, 2:string, 3:array } $pointPreset + */ protected function unserializePointPreset(array $pointPreset): PointPresetInterface { $newPointPreset = new PointPreset(); @@ -124,6 +140,9 @@ protected function unserializePointPreset(array $pointPreset): PointPresetInterf return $newPointPreset; } + /** + * @return array + */ protected function serializeConnection(ConnectionInterface $connection): array { return [ @@ -133,6 +152,9 @@ protected function serializeConnection(ConnectionInterface $connection): array ]; } + /** + * @param array{ 0:string, 1:string, 2:bool } $connection + */ protected function unserializeConnection(array $connection): ConnectionInterface { $newConnection = new Connection(); diff --git a/src/DataCollector/InfluxDbPresetDataCollector.php b/src/DataCollector/InfluxDbPresetDataCollector.php index 245f1b5..db67a8c 100644 --- a/src/DataCollector/InfluxDbPresetDataCollector.php +++ b/src/DataCollector/InfluxDbPresetDataCollector.php @@ -27,7 +27,7 @@ public function __construct(ProfilePoolInterface $profilePool) $this->profilePool = $profilePool; } - public function onClientRequest(ClientRequestEvent $event) + public function onClientRequest(ClientRequestEvent $event): void { $profile = $this->profilePool->getProfileByName($event->getProfileName()); $preset = $profile->getPointPresetByName($event->getPresetName()); @@ -35,7 +35,7 @@ public function onClientRequest(ClientRequestEvent $event) $this->requests[] = new ClientRequest($profile, $preset, $event->getValue(), $event->getDateTime()); } - public function collect(Request $request, Response $response, \Throwable $exception = null) + public function collect(Request $request, Response $response, \Throwable $exception = null): void { $this->data = [ 'requests' => $this->requests, @@ -45,7 +45,7 @@ public function collect(Request $request, Response $response, \Throwable $except /** * Resets this data collector to its initial state. */ - public function reset() + public function reset(): void { $this->data = []; } @@ -58,7 +58,7 @@ public function getRequests(): array return $this->data['requests']; } - public function getName() + public function getName(): string { return 'yproximite.influxdb_preset'; } diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index a955ac4..9b225b1 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -8,23 +8,17 @@ use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; -/** - * Class Configuration - */ class Configuration implements ConfigurationInterface { /** - * @var array + * @var array */ private static $protocols = ['http', 'udp']; - /** - * {@inheritdoc} - */ - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('yproximite_influx_db_preset'); - $rootNode = method_exists($treeBuilder, 'getRootNode') ? $treeBuilder->getRootNode() : $treeBuilder->root('yproximite_influx_db_preset'); + $rootNode = $treeBuilder->getRootNode(); $this->addProfilesSection($rootNode); $this->addExtensionsSection($rootNode); @@ -32,7 +26,7 @@ public function getConfigTreeBuilder() return $treeBuilder; } - private function addProfilesSection(NodeDefinition $rootNode) + private function addProfilesSection(NodeDefinition $rootNode): void { $profiles = $rootNode ->children() @@ -51,7 +45,7 @@ private function addProfilesSection(NodeDefinition $rootNode) ; } - private function addConnectionsSection(NodeDefinition $rootNode) + private function addConnectionsSection(NodeDefinition $rootNode): void { $rootNode ->children() @@ -64,7 +58,7 @@ private function addConnectionsSection(NodeDefinition $rootNode) ->isRequired() ->validate() ->ifTrue(function ($value) { - return !\in_array($value, self::$protocols); + return !\in_array($value, self::$protocols, true); }) ->thenInvalid( sprintf( @@ -82,7 +76,7 @@ private function addConnectionsSection(NodeDefinition $rootNode) ; } - private function addPresetsSection(NodeDefinition $rootNode) + private function addPresetsSection(NodeDefinition $rootNode): void { $rootNode ->children() @@ -104,7 +98,7 @@ private function addPresetsSection(NodeDefinition $rootNode) ; } - private function addExtensionsSection(NodeDefinition $rootNode) + private function addExtensionsSection(NodeDefinition $rootNode): void { $rootNode ->children() diff --git a/src/DependencyInjection/YproximiteInfluxDbPresetExtension.php b/src/DependencyInjection/YproximiteInfluxDbPresetExtension.php index 7ecf664..31fff22 100644 --- a/src/DependencyInjection/YproximiteInfluxDbPresetExtension.php +++ b/src/DependencyInjection/YproximiteInfluxDbPresetExtension.php @@ -10,15 +10,9 @@ use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use Symfony\Component\HttpKernel\DependencyInjection\Extension; -/** - * Class YproximiteInfluxDbPresetExtension - */ class YproximiteInfluxDbPresetExtension extends Extension { - /** - * {@inheritdoc} - */ - public function load(array $configs, ContainerBuilder $container) + public function load(array $configs, ContainerBuilder $container): void { $processor = new Processor(); $configuration = new Configuration(); @@ -37,7 +31,11 @@ public function load(array $configs, ContainerBuilder $container) $container->setParameter('yproximite.influx_db_preset.default_profile_name', $config['default_profile_name']); } - private function registerProfiles(array $config, ContainerBuilder $container) + /** + * @param array{ profiles: array , fields: array }>, connections: array }> } $config + */ + private function registerProfiles(array $config, ContainerBuilder $container): void { $definition = $container->getDefinition('yproximite.influx_db_preset.profile.profile_pool'); @@ -46,18 +44,21 @@ private function registerProfiles(array $config, ContainerBuilder $container) } } - private function registerEvents(array $config, ContainerBuilder $container) + /** + * @param array{ profiles: array , fields: array }> }> } $config + */ + private function registerEvents(array $config, ContainerBuilder $container): void { $eventNames = []; $definition = $container->getDefinition('yproximite.influx_db_preset.event_listener.influx_db'); foreach ($config['profiles'] as $profileConfig) { - if (\array_key_exists('presets', $profileConfig)) { - foreach ($profileConfig['presets'] as $presetName => $presetConfig) { - if (!\array_key_exists($presetName, $eventNames)) { - $eventNames[] = $presetName; - } - } + if (!\array_key_exists('presets', $profileConfig)) { + continue; + } + + foreach ($profileConfig['presets'] as $presetName => $presetConfig) { + $eventNames[] = $presetName; } } @@ -66,26 +67,30 @@ private function registerEvents(array $config, ContainerBuilder $container) } } - private function registerExtensions(array $config, ContainerBuilder $container, YamlFileLoader $loader) + /** + * @param array{ default_profile_name:string, extensions:array } $config + */ + private function registerExtensions(array $config, ContainerBuilder $container, YamlFileLoader $loader): void { foreach ($config['extensions'] as $extensionName => $extension) { - if ($extension['enabled']) { - $loader->load(sprintf('extension/%s.yml', $extensionName)); - - $extensionDefinitionId = sprintf( - 'yproximite.influx_db_preset.event_listener.extension.%s', - $extensionName - ); - - $profileName = \array_key_exists('profile_name', $extension) - ? $extension['profile_name'] - : $config['default_profile_name'] - ; - - $extensionDefinition = $container->getDefinition($extensionDefinitionId); - $extensionDefinition->addMethodCall('setEventName', [$extension['preset_name']]); - $extensionDefinition->addMethodCall('setProfileName', [$profileName]); + if (!$extension['enabled']) { + continue; } + + $loader->load(sprintf('extension/%s.yml', $extensionName)); + + $extensionDefinitionId = sprintf( + 'yproximite.influx_db_preset.event_listener.extension.%s', + $extensionName + ); + + $profileName = \array_key_exists('profile_name', $extension) + ? $extension['profile_name'] + : $config['default_profile_name']; + + $extensionDefinition = $container->getDefinition($extensionDefinitionId); + $extensionDefinition->addMethodCall('setEventName', [$extension['preset_name']]); + $extensionDefinition->addMethodCall('setProfileName', [$profileName]); } } } diff --git a/src/Event/InfluxDbEvent.php b/src/Event/InfluxDbEvent.php index 4a13f61..40712a9 100644 --- a/src/Event/InfluxDbEvent.php +++ b/src/Event/InfluxDbEvent.php @@ -23,7 +23,10 @@ final class InfluxDbEvent extends SymfonyEvent */ private $dateTime; - public function __construct($value, string $profileName = null, \DateTimeInterface $dateTime = null) + /** + * @param float|int $value + */ + public function __construct($value, ?string $profileName = null, ?\DateTimeInterface $dateTime = null) { $this->value = (float) $value; $this->profileName = $profileName; @@ -35,18 +38,12 @@ public function getValue(): float return $this->value; } - /** - * @return string|null - */ - public function getProfileName() + public function getProfileName(): ?string { return $this->profileName; } - /** - * @return \DateTimeInterface|null - */ - public function getDateTime() + public function getDateTime(): ?\DateTimeInterface { return $this->dateTime; } diff --git a/src/EventListener/Extension/AbstractListener.php b/src/EventListener/Extension/AbstractListener.php index e04fd81..bdb65bf 100644 --- a/src/EventListener/Extension/AbstractListener.php +++ b/src/EventListener/Extension/AbstractListener.php @@ -7,9 +7,6 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Yproximite\Bundle\InfluxDbPresetBundle\Event\InfluxDbEvent; -/** - * Class AbstractListener - */ abstract class AbstractListener { /** @@ -27,22 +24,25 @@ abstract class AbstractListener */ protected $profileName; - public function setEventDispatcher(EventDispatcherInterface $eventDispatcher) + public function setEventDispatcher(EventDispatcherInterface $eventDispatcher): void { $this->eventDispatcher = $eventDispatcher; } - public function setEventName(string $eventName) + public function setEventName(string $eventName): void { $this->eventName = $eventName; } - public function setProfileName(string $profileName) + public function setProfileName(string $profileName): void { $this->profileName = $profileName; } - protected function dispatchEvent($value) + /** + * @param float $value + */ + protected function dispatchEvent($value): void { $this->eventDispatcher->dispatch(new InfluxDbEvent($value, $this->profileName), $this->eventName); } diff --git a/src/EventListener/Extension/ExceptionListener.php b/src/EventListener/Extension/ExceptionListener.php index d850185..024ecdf 100644 --- a/src/EventListener/Extension/ExceptionListener.php +++ b/src/EventListener/Extension/ExceptionListener.php @@ -7,17 +7,14 @@ use Symfony\Component\HttpKernel\Event\ExceptionEvent; use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; -/** - * Class ExceptionListener - */ final class ExceptionListener extends AbstractListener { - public function onKernelException(ExceptionEvent $event) + public function onKernelException(ExceptionEvent $event): void { $exception = $event->getThrowable(); if ($exception instanceof HttpExceptionInterface) { - $code = $event->getThrowable()->getStatusCode(); + $code = $event->getThrowable()->getCode(); } else { $code = 0; } diff --git a/src/EventListener/Extension/MemoryListener.php b/src/EventListener/Extension/MemoryListener.php index abfafba..2a6e1c3 100644 --- a/src/EventListener/Extension/MemoryListener.php +++ b/src/EventListener/Extension/MemoryListener.php @@ -6,12 +6,9 @@ use Symfony\Component\HttpKernel\Event\TerminateEvent; -/** - * Class MemoryListener - */ final class MemoryListener extends AbstractListener { - public function onKernelTerminate(TerminateEvent $event) + public function onKernelTerminate(TerminateEvent $event): void { $memory = memory_get_peak_usage(true); $memory = $memory > 1024 ? \intval($memory / 1024) : 0; diff --git a/src/EventListener/Extension/RequestCountListener.php b/src/EventListener/Extension/RequestCountListener.php index 951cbd0..46a352d 100644 --- a/src/EventListener/Extension/RequestCountListener.php +++ b/src/EventListener/Extension/RequestCountListener.php @@ -6,14 +6,11 @@ use Symfony\Component\HttpKernel\Event\TerminateEvent; -/** - * Class RequestCountListener - */ final class RequestCountListener extends AbstractListener { - public function onKernelTerminate(TerminateEvent $event) + public function onKernelTerminate(TerminateEvent $event): void { - if (!$event->isMasterRequest()) { + if (!$event->isMainRequest()) { return; } diff --git a/src/EventListener/Extension/ResponseTimeListener.php b/src/EventListener/Extension/ResponseTimeListener.php index 2d0da1b..75c0827 100644 --- a/src/EventListener/Extension/ResponseTimeListener.php +++ b/src/EventListener/Extension/ResponseTimeListener.php @@ -6,14 +6,11 @@ use Symfony\Component\HttpKernel\Event\TerminateEvent; -/** - * Class ResponseTimeListener - */ final class ResponseTimeListener extends AbstractListener { - public function onKernelTerminate(TerminateEvent $event) + public function onKernelTerminate(TerminateEvent $event): void { - if (!$event->isMasterRequest()) { + if (!$event->isMainRequest()) { return; } diff --git a/src/EventListener/InfluxDbListener.php b/src/EventListener/InfluxDbListener.php index 0b1ca59..4239324 100644 --- a/src/EventListener/InfluxDbListener.php +++ b/src/EventListener/InfluxDbListener.php @@ -7,30 +7,15 @@ use Yproximite\Bundle\InfluxDbPresetBundle\Client\ClientInterface; use Yproximite\Bundle\InfluxDbPresetBundle\Event\InfluxDbEvent; -/** - * Class InfluxDbListener - */ final class InfluxDbListener { - /** - * @var ClientInterface - */ - private $client; - - /** - * @var string - */ - private $defaultProfileName; - - public function __construct(ClientInterface $client, string $defaultProfileName) + public function __construct(private ClientInterface $client, private string $defaultProfileName) { - $this->client = $client; - $this->defaultProfileName = $defaultProfileName; } - public function onInfluxDb(InfluxDbEvent $event, $eventName) + public function onInfluxDb(InfluxDbEvent $event, string $eventName): void { - $profileName = $event->getProfileName() ?: $this->defaultProfileName; + $profileName = $event->getProfileName() ?? $this->defaultProfileName; $this->client->sendPoint($profileName, $eventName, $event->getValue(), $event->getDateTime()); } diff --git a/src/Events.php b/src/Events.php index 66245da..82cec5c 100644 --- a/src/Events.php +++ b/src/Events.php @@ -4,9 +4,6 @@ namespace Yproximite\Bundle\InfluxDbPresetBundle; -/** - * Class Events - */ final class Events { public const CLIENT_REQUEST = 'yproximite.bundle.influx_db_preset.client_request'; diff --git a/src/Exception/ExceptionInterface.php b/src/Exception/ExceptionInterface.php index 993de14..dda7328 100644 --- a/src/Exception/ExceptionInterface.php +++ b/src/Exception/ExceptionInterface.php @@ -4,9 +4,6 @@ namespace Yproximite\Bundle\InfluxDbPresetBundle\Exception; -/** - * Interface ExceptionInterface - */ interface ExceptionInterface { } diff --git a/src/Exception/LogicException.php b/src/Exception/LogicException.php index d71c7c1..eb991af 100644 --- a/src/Exception/LogicException.php +++ b/src/Exception/LogicException.php @@ -4,9 +4,6 @@ namespace Yproximite\Bundle\InfluxDbPresetBundle\Exception; -/** - * Class LogicException - */ class LogicException extends \LogicException implements ExceptionInterface { } diff --git a/src/Exception/PresetNotFoundException.php b/src/Exception/PresetNotFoundException.php index 916d606..8acbaad 100644 --- a/src/Exception/PresetNotFoundException.php +++ b/src/Exception/PresetNotFoundException.php @@ -4,9 +4,6 @@ namespace Yproximite\Bundle\InfluxDbPresetBundle\Exception; -/** - * Class PresetNotFoundException - */ class PresetNotFoundException extends \LogicException implements ExceptionInterface { } diff --git a/src/Exception/ProfileNotFoundException.php b/src/Exception/ProfileNotFoundException.php index 1880bd3..d7953e5 100644 --- a/src/Exception/ProfileNotFoundException.php +++ b/src/Exception/ProfileNotFoundException.php @@ -4,9 +4,6 @@ namespace Yproximite\Bundle\InfluxDbPresetBundle\Exception; -/** - * Class ProfileNotFoundException - */ class ProfileNotFoundException extends \LogicException implements ExceptionInterface { } diff --git a/src/Point/PointBuilder.php b/src/Point/PointBuilder.php index bc3df83..4906ddb 100644 --- a/src/Point/PointBuilder.php +++ b/src/Point/PointBuilder.php @@ -6,9 +6,6 @@ use InfluxDB\Point; -/** - * Class PointBuilder - */ class PointBuilder implements PointBuilderInterface { /** @@ -77,6 +74,11 @@ public function build(): Point return new Point($measurement, $value, $tags, $fields, $timestamp); } + /** + * @param string|array $template + * + * @return array|string|string[] + */ private function compileTemplate($template) { if (\is_string($template) && preg_match_all('/<([^>]*)>/', $template, $matches) > 0) { @@ -93,6 +95,9 @@ private function compileTemplate($template) return $template; } + /** + * @return array{ value:float } + */ private function getTemplateParams(): array { return [ diff --git a/src/Point/PointBuilderFactory.php b/src/Point/PointBuilderFactory.php index d8f59a4..953690e 100644 --- a/src/Point/PointBuilderFactory.php +++ b/src/Point/PointBuilderFactory.php @@ -4,9 +4,6 @@ namespace Yproximite\Bundle\InfluxDbPresetBundle\Point; -/** - * Class PointBuilderFactory - */ class PointBuilderFactory implements PointBuilderFactoryInterface { public function create(): PointBuilderInterface diff --git a/src/Point/PointBuilderFactoryInterface.php b/src/Point/PointBuilderFactoryInterface.php index 701ccde..0cc3ac6 100644 --- a/src/Point/PointBuilderFactoryInterface.php +++ b/src/Point/PointBuilderFactoryInterface.php @@ -4,9 +4,6 @@ namespace Yproximite\Bundle\InfluxDbPresetBundle\Point; -/** - * Interface PointBuilderFactoryInterface - */ interface PointBuilderFactoryInterface { public function create(): PointBuilderInterface; diff --git a/src/Point/PointBuilderInterface.php b/src/Point/PointBuilderInterface.php index c9c4e7a..92cc9dc 100644 --- a/src/Point/PointBuilderInterface.php +++ b/src/Point/PointBuilderInterface.php @@ -6,9 +6,6 @@ use InfluxDB\Point; -/** - * Interface PointBuilderInterface - */ interface PointBuilderInterface { public function getPreset(): PointPresetInterface; diff --git a/src/Point/PointPreset.php b/src/Point/PointPreset.php index 3dfb49a..4d3ee67 100644 --- a/src/Point/PointPreset.php +++ b/src/Point/PointPreset.php @@ -4,9 +4,6 @@ namespace Yproximite\Bundle\InfluxDbPresetBundle\Point; -/** - * Class PointPreset - */ class PointPreset implements PointPresetInterface { /** @@ -20,12 +17,12 @@ class PointPreset implements PointPresetInterface private $measurement; /** - * @var array + * @var array */ private $tags = []; /** - * @var array + * @var array */ private $fields = []; diff --git a/src/Point/PointPresetFactory.php b/src/Point/PointPresetFactory.php index b1e5231..21e0f37 100644 --- a/src/Point/PointPresetFactory.php +++ b/src/Point/PointPresetFactory.php @@ -4,9 +4,6 @@ namespace Yproximite\Bundle\InfluxDbPresetBundle\Point; -/** - * Class PointPresetFactory - */ class PointPresetFactory implements PointPresetFactoryInterface { public function create(): PointPresetInterface diff --git a/src/Point/PointPresetFactoryInterface.php b/src/Point/PointPresetFactoryInterface.php index 866ef58..6bfacef 100644 --- a/src/Point/PointPresetFactoryInterface.php +++ b/src/Point/PointPresetFactoryInterface.php @@ -4,12 +4,12 @@ namespace Yproximite\Bundle\InfluxDbPresetBundle\Point; -/** - * Interface PointPresetFactoryInterface - */ interface PointPresetFactoryInterface { public function create(): PointPresetInterface; + /** + * @param array{ name:string, measurement:string, tags:array, fields:array } $config + */ public function createFromConfig(array $config): PointPresetInterface; } diff --git a/src/Point/PointPresetInterface.php b/src/Point/PointPresetInterface.php index f97d79d..33ae165 100644 --- a/src/Point/PointPresetInterface.php +++ b/src/Point/PointPresetInterface.php @@ -4,9 +4,6 @@ namespace Yproximite\Bundle\InfluxDbPresetBundle\Point; -/** - * Interface PointPresetInterface - */ interface PointPresetInterface { public function getName(): string; @@ -17,11 +14,23 @@ public function getMeasurement(): string; public function setMeasurement(string $measurement): self; + /** + * @return array + */ public function getTags(): array; + /** + * @param array $tags + */ public function setTags(array $tags): self; + /** + * @return array + */ public function getFields(): array; + /** + * @param array $fields + */ public function setFields(array $fields): self; } diff --git a/src/Profile/Profile.php b/src/Profile/Profile.php index 7e4a146..cd6dc3e 100644 --- a/src/Profile/Profile.php +++ b/src/Profile/Profile.php @@ -8,9 +8,6 @@ use Yproximite\Bundle\InfluxDbPresetBundle\Exception\PresetNotFoundException; use Yproximite\Bundle\InfluxDbPresetBundle\Point\PointPresetInterface; -/** - * Class Profile - */ class Profile implements ProfileInterface { /** diff --git a/src/Profile/ProfileFactory.php b/src/Profile/ProfileFactory.php index 8a14568..f24bc61 100644 --- a/src/Profile/ProfileFactory.php +++ b/src/Profile/ProfileFactory.php @@ -7,9 +7,6 @@ use Yproximite\Bundle\InfluxDbPresetBundle\Connection\ConnectionFactoryInterface; use Yproximite\Bundle\InfluxDbPresetBundle\Point\PointPresetFactoryInterface; -/** - * Class ProfileFactory - */ class ProfileFactory implements ProfileFactoryInterface { /** @@ -41,13 +38,13 @@ public function createFromConfig(array $config): ProfileInterface $profile->setName($config['name']); foreach ($config['presets'] as $presetName => $presetConfig) { - $preset = $this->pointPresetFactory->createFromConfig($presetConfig + ['name' => $presetName]); + $preset = $this->pointPresetFactory->createFromConfig(array_merge($presetConfig + ['name' => $presetName])); $profile->addPointPreset($preset); } foreach ($config['connections'] as $connectionName => $connectionConfig) { - $connection = $this->connectionFactory->createFromConfig($connectionConfig + ['name' => $connectionName]); + $connection = $this->connectionFactory->createFromConfig(array_merge($connectionConfig, ['name' => $connectionName])); $profile->addConnection($connection); } diff --git a/src/Profile/ProfileFactoryInterface.php b/src/Profile/ProfileFactoryInterface.php index 9676e58..aeeefb6 100644 --- a/src/Profile/ProfileFactoryInterface.php +++ b/src/Profile/ProfileFactoryInterface.php @@ -4,12 +4,12 @@ namespace Yproximite\Bundle\InfluxDbPresetBundle\Profile; -/** - * Interface ProfileFactoryInterface - */ interface ProfileFactoryInterface { public function create(): ProfileInterface; + /** + * @param array{ name:string, presets:array , fields: array }>, connections: array } $config + */ public function createFromConfig(array $config): ProfileInterface; } diff --git a/src/Profile/ProfileInterface.php b/src/Profile/ProfileInterface.php index bf95136..fc31d00 100644 --- a/src/Profile/ProfileInterface.php +++ b/src/Profile/ProfileInterface.php @@ -7,9 +7,6 @@ use Yproximite\Bundle\InfluxDbPresetBundle\Connection\ConnectionInterface; use Yproximite\Bundle\InfluxDbPresetBundle\Point\PointPresetInterface; -/** - * Interface ProfileInterface - */ interface ProfileInterface { public function getName(): string; @@ -20,6 +17,9 @@ public function addPointPreset(PointPresetInterface $preset): self; public function getPointPresetByName(string $presetName): PointPresetInterface; + /** + * @return array + */ public function getPointPresets(): array; public function addConnection(ConnectionInterface $connection): self; diff --git a/src/Profile/ProfilePool.php b/src/Profile/ProfilePool.php index 4d57c99..38be39c 100644 --- a/src/Profile/ProfilePool.php +++ b/src/Profile/ProfilePool.php @@ -6,9 +6,6 @@ use Yproximite\Bundle\InfluxDbPresetBundle\Exception\ProfileNotFoundException; -/** - * Class ProfilePool - */ class ProfilePool implements ProfilePoolInterface { /** diff --git a/src/Profile/ProfilePoolInterface.php b/src/Profile/ProfilePoolInterface.php index e604e51..e4a7791 100644 --- a/src/Profile/ProfilePoolInterface.php +++ b/src/Profile/ProfilePoolInterface.php @@ -4,13 +4,13 @@ namespace Yproximite\Bundle\InfluxDbPresetBundle\Profile; -/** - * Interface ProfilePoolInterface - */ interface ProfilePoolInterface { public function addProfile(ProfileInterface $preset): self; + /** + * @param array{ name:string, presets:array , fields: array }>, connections: array } $config + */ public function addProfileFromConfig(array $config): self; public function getProfileByName(string $profileName): ProfileInterface; diff --git a/src/YproximiteInfluxDbPresetBundle.php b/src/YproximiteInfluxDbPresetBundle.php index e147186..0cc1a1b 100644 --- a/src/YproximiteInfluxDbPresetBundle.php +++ b/src/YproximiteInfluxDbPresetBundle.php @@ -6,9 +6,6 @@ use Symfony\Component\HttpKernel\Bundle\Bundle; -/** - * Class YproximiteInfluxDbPresetBundle - */ class YproximiteInfluxDbPresetBundle extends Bundle { }