Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symfony 5 support #5

Merged
merged 12 commits into from Jan 16, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 0 additions & 14 deletions .coke

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
vendor/
composer.lock
bin/*
.php_cs.cache
28 changes: 28 additions & 0 deletions .php_cs.dist
@@ -0,0 +1,28 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude('var')
;

return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'array_syntax' => [
'syntax' => 'short',
],
'binary_operator_spaces' => [
'align_double_arrow' => true,
'align_equals' => true
],
'no_unreachable_default_argument_value' => false,
'braces' => [
'allow_single_line_closure' => true,
],
'heredoc_to_nowdoc' => false,
'phpdoc_summary' => false,
'declare_strict_types' => true,
])
->setFinder($finder)
;
3 changes: 1 addition & 2 deletions .travis.yml
Expand Up @@ -3,7 +3,6 @@ sudo: false

matrix:
include:
- php: 7.0
- php: 7.1
- php: 7.2

Expand All @@ -21,5 +20,5 @@ cache:
- ~/.composer/cache/files

script:
- bin/coke
- bin/php-cs-fixer fix --verbose --diff --dry-run src/
- bin/phpspec run -f dot -n
13 changes: 3 additions & 10 deletions composer.json
Expand Up @@ -4,15 +4,9 @@
"keywords": ["influx", "db", "influxdb", "statistics", "metrics"],
"type": "symfony-bundle",
"license": "MIT",
"repositories": [
{
"type": "vcs",
"url": "git@github.com:Yproximite/Symfony2-coding-standard"
}
],
"require": {
"php": "^7.0",
"symfony/framework-bundle": "^3.0|^4.0",
"php": "^7.1",
"symfony/framework-bundle": "^4.0|^5.0",
"algatux/influxdb-bundle": "~2.1"
},
"autoload": {
Expand All @@ -22,8 +16,7 @@
},
"require-dev": {
"phpspec/phpspec": "^3.2",
"m6web/Symfony2-coding-standard": "dev-master",
"m6web/coke": "^2.1"
"friendsofphp/php-cs-fixer": "^2.16"
},
"config": {
"bin-dir": "bin"
Expand Down
38 changes: 21 additions & 17 deletions spec/Client/ClientSpec.php
@@ -1,34 +1,35 @@
<?php

declare(strict_types=1);

namespace spec\Yproximite\Bundle\InfluxDbPresetBundle\Client;

use InfluxDB\Point;
use Algatux\InfluxDbBundle\Events\DeferredHttpEvent;
use Algatux\InfluxDbBundle\Events\DeferredUdpEvent;
use Algatux\InfluxDbBundle\Events\HttpEvent;
use Algatux\InfluxDbBundle\Events\UdpEvent;
use InfluxDB\Database;
use InfluxDB\Point;
use PhpSpec\ObjectBehavior;
use Algatux\InfluxDbBundle\Events\UdpEvent;
use Algatux\InfluxDbBundle\Events\HttpEvent;
use Algatux\InfluxDbBundle\Events\DeferredUdpEvent;
use Algatux\InfluxDbBundle\Events\DeferredHttpEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

use Yproximite\Bundle\InfluxDbPresetBundle\Events;
use Yproximite\Bundle\InfluxDbPresetBundle\Client\Client;
use Yproximite\Bundle\InfluxDbPresetBundle\Profile\Profile;
use Yproximite\Bundle\InfluxDbPresetBundle\Point\PointPreset;
use Yproximite\Bundle\InfluxDbPresetBundle\Point\PointBuilder;
use Yproximite\Bundle\InfluxDbPresetBundle\Connection\Connection;
use Yproximite\Bundle\InfluxDbPresetBundle\Event\ClientRequestEvent;
use Yproximite\Bundle\InfluxDbPresetBundle\Profile\ProfilePoolInterface;
use Yproximite\Bundle\InfluxDbPresetBundle\Events;
use Yproximite\Bundle\InfluxDbPresetBundle\Point\PointBuilder;
use Yproximite\Bundle\InfluxDbPresetBundle\Point\PointBuilderFactoryInterface;
use Yproximite\Bundle\InfluxDbPresetBundle\Point\PointPreset;
use Yproximite\Bundle\InfluxDbPresetBundle\Profile\Profile;
use Yproximite\Bundle\InfluxDbPresetBundle\Profile\ProfilePoolInterface;

class ClientSpec extends ObjectBehavior
{
function it_is_initializable()
public function it_is_initializable()
{
$this->shouldHaveType(Client::class);
}

function let(
public function let(
EventDispatcherInterface $eventDispatcher,
ProfilePoolInterface $profilePool,
PointBuilderFactoryInterface $pointBuilderFactory
Expand All @@ -41,7 +42,8 @@ function let(
$this->beConstructedWith($eventDispatcher, $profilePool, $pointBuilderFactory);
}

function it_should_send_point_through_each_of_connection_types(EventDispatcherInterface $eventDispatcher) {
public function it_should_send_point_through_each_of_connection_types(EventDispatcherInterface $eventDispatcher)
{
$dateTime = new \DateTime();

$this->sendPoint('default', 'apple.dropped', 7., $dateTime);
Expand All @@ -62,7 +64,8 @@ function it_should_send_point_through_each_of_connection_types(EventDispatcherIn
}
}

function it_should_dispatch_client_request_event(EventDispatcherInterface $eventDispatcher) {
public function it_should_dispatch_client_request_event(EventDispatcherInterface $eventDispatcher)
{
$dateTime = new \DateTime();

$this->sendPoint('default', 'apple.dropped', 7., $dateTime);
Expand All @@ -72,7 +75,8 @@ function it_should_dispatch_client_request_event(EventDispatcherInterface $event
$eventDispatcher->dispatch(Events::CLIENT_REQUEST, $event)->shouldHaveBeenCalled();
}

function it_should_use_other_profiles_separately(EventDispatcherInterface $eventDispatcher) {
public function it_should_use_other_profiles_separately(EventDispatcherInterface $eventDispatcher)
{
$dateTime = new \DateTime();

$this->sendPoint('custom', 'apple.dropped', 5., $dateTime);
Expand Down Expand Up @@ -105,7 +109,7 @@ private function buildDefaultProfile(): Profile
];

foreach ($connectionConfigs as $connectionConfig) {
list ($connectionName, $connectionProtocol, $connectionDeferred) = $connectionConfig;
list($connectionName, $connectionProtocol, $connectionDeferred) = $connectionConfig;

$connection = new Connection();
$connection
Expand Down
11 changes: 6 additions & 5 deletions spec/Point/PointBuilderSpec.php
@@ -1,20 +1,21 @@
<?php

declare(strict_types=1);

namespace spec\Yproximite\Bundle\InfluxDbPresetBundle\Point;

use PhpSpec\ObjectBehavior;

use Yproximite\Bundle\InfluxDbPresetBundle\Point\PointPreset;
use Yproximite\Bundle\InfluxDbPresetBundle\Point\PointBuilder;
use Yproximite\Bundle\InfluxDbPresetBundle\Point\PointPreset;

class PointBuilderSpec extends ObjectBehavior
{
function it_is_initializable()
public function it_is_initializable()
{
$this->shouldHaveType(PointBuilder::class);
}

function it_should_build_simple_point()
public function it_should_build_simple_point()
{
$pointPreset = new PointPreset();
$pointPreset->setMeasurement('apples');
Expand All @@ -28,7 +29,7 @@ function it_should_build_simple_point()
$this->build()->__toString()->shouldBeEqualTo(sprintf('apples value=5 %d', $dateTime->getTimestamp()));
}

function it_should_build_advanced_point()
public function it_should_build_advanced_point()
{
$pointPreset = new PointPreset();
$pointPreset
Expand Down
25 changes: 13 additions & 12 deletions src/Client/Client.php
@@ -1,22 +1,23 @@
<?php

declare(strict_types=1);

namespace Yproximite\Bundle\InfluxDbPresetBundle\Client;

use InfluxDB\Point;
use InfluxDB\Database;
use Algatux\InfluxDbBundle\Events\UdpEvent;
use Algatux\InfluxDbBundle\Events\HttpEvent;
use Algatux\InfluxDbBundle\Events\DeferredUdpEvent;
use Algatux\InfluxDbBundle\Events\DeferredHttpEvent;
use Algatux\InfluxDbBundle\Events\DeferredUdpEvent;
use Algatux\InfluxDbBundle\Events\HttpEvent;
use Algatux\InfluxDbBundle\Events\UdpEvent;
use InfluxDB\Database;
use InfluxDB\Point;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Yproximite\Bundle\InfluxDbPresetBundle\Events;
use Yproximite\Bundle\InfluxDbPresetBundle\Connection\ConnectionInterface;
use Yproximite\Bundle\InfluxDbPresetBundle\Event\ClientRequestEvent;
use Yproximite\Bundle\InfluxDbPresetBundle\Events;
use Yproximite\Bundle\InfluxDbPresetBundle\Exception\LogicException;
use Yproximite\Bundle\InfluxDbPresetBundle\Point\PointBuilderFactoryInterface;
use Yproximite\Bundle\InfluxDbPresetBundle\Point\PointPresetInterface;
use Yproximite\Bundle\InfluxDbPresetBundle\Profile\ProfilePoolInterface;
use Yproximite\Bundle\InfluxDbPresetBundle\Connection\ConnectionInterface;
use Yproximite\Bundle\InfluxDbPresetBundle\Point\PointBuilderFactoryInterface;

/**
* Class Client
Expand Down Expand Up @@ -94,13 +95,13 @@ private function sendPointUsingConnection(Point $point, ConnectionInterface $con
private function getEventClassName(ConnectionInterface $connection): string
{
switch (true) {
case ($connection->isHttpProtocol() && !$connection->isDeferred()):
case $connection->isHttpProtocol() && !$connection->isDeferred():
return HttpEvent::class;
case ($connection->isHttpProtocol() && $connection->isDeferred()):
case $connection->isHttpProtocol() && $connection->isDeferred():
return DeferredHttpEvent::class;
case ($connection->isUdpProtocol() && !$connection->isDeferred()):
case $connection->isUdpProtocol() && !$connection->isDeferred():
return UdpEvent::class;
case ($connection->isUdpProtocol() && $connection->isDeferred()):
case $connection->isUdpProtocol() && $connection->isDeferred():
return DeferredUdpEvent::class;
default:
throw new LogicException('Could not determine the event class name.');
Expand Down
1 change: 1 addition & 0 deletions src/Client/ClientInterface.php
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Yproximite\Bundle\InfluxDbPresetBundle\Client;
Expand Down
5 changes: 3 additions & 2 deletions src/Connection/Connection.php
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Yproximite\Bundle\InfluxDbPresetBundle\Connection;
Expand Down Expand Up @@ -49,12 +50,12 @@ public function setProtocol(string $protocol): ConnectionInterface

public function isUdpProtocol(): bool
{
return $this->getProtocol() === self::PROTOCOL_UDP;
return self::PROTOCOL_UDP === $this->getProtocol();
}

public function isHttpProtocol(): bool
{
return $this->getProtocol() === self::PROTOCOL_HTTP;
return self::PROTOCOL_HTTP === $this->getProtocol();
}

public function isDeferred(): bool
Expand Down
1 change: 1 addition & 0 deletions src/Connection/ConnectionFactory.php
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Yproximite\Bundle\InfluxDbPresetBundle\Connection;
Expand Down
1 change: 1 addition & 0 deletions src/Connection/ConnectionFactoryInterface.php
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Yproximite\Bundle\InfluxDbPresetBundle\Connection;
Expand Down
1 change: 1 addition & 0 deletions src/Connection/ConnectionInterface.php
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Yproximite\Bundle\InfluxDbPresetBundle\Connection;
Expand Down
2 changes: 1 addition & 1 deletion src/DataCollector/ClientRequest.php
Expand Up @@ -7,9 +7,9 @@
use Yproximite\Bundle\InfluxDbPresetBundle\Connection\Connection;
use Yproximite\Bundle\InfluxDbPresetBundle\Connection\ConnectionInterface;
use Yproximite\Bundle\InfluxDbPresetBundle\Point\PointPreset;
use Yproximite\Bundle\InfluxDbPresetBundle\Point\PointPresetInterface;
use Yproximite\Bundle\InfluxDbPresetBundle\Profile\Profile;
use Yproximite\Bundle\InfluxDbPresetBundle\Profile\ProfileInterface;
use Yproximite\Bundle\InfluxDbPresetBundle\Point\PointPresetInterface;

/**
* Class ClientRequest
Expand Down
1 change: 1 addition & 0 deletions src/DataCollector/InfluxDbPresetDataCollector.php
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Yproximite\Bundle\InfluxDbPresetBundle\DataCollector;
Expand Down
15 changes: 9 additions & 6 deletions src/DependencyInjection/Configuration.php
@@ -1,10 +1,11 @@
<?php

declare(strict_types=1);

namespace Yproximite\Bundle\InfluxDbPresetBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
Expand All @@ -22,8 +23,8 @@ class Configuration implements ConfigurationInterface
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('yproximite_influx_db_preset');
$treeBuilder = new TreeBuilder('yproximite_influx_db_preset');
$rootNode = \method_exists($treeBuilder, 'getRootNode') ? $treeBuilder->getRootNode() : $treeBuilder->root('yproximite_influx_db_preset');

$this->addProfilesSection($rootNode);
$this->addExtensionsSection($rootNode);
Expand All @@ -40,9 +41,11 @@ private function addProfilesSection(NodeDefinition $rootNode)
->requiresAtLeastOneElement()
->useAttributeAsKey('name')
->prototype('array');
$this->addConnectionsSection($profiles);
$this->addPresetsSection($profiles);
$profiles->end()

$this->addConnectionsSection($profiles);
$this->addPresetsSection($profiles);

$profiles->end()
->end()
->end()
;
Expand Down
5 changes: 3 additions & 2 deletions src/DependencyInjection/YproximiteInfluxDbPresetExtension.php
@@ -1,13 +1,14 @@
<?php

declare(strict_types=1);

namespace Yproximite\Bundle\InfluxDbPresetBundle\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

/**
* Class YproximiteInfluxDbPresetExtension
Expand Down
1 change: 1 addition & 0 deletions src/Event/ClientRequestEvent.php
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Yproximite\Bundle\InfluxDbPresetBundle\Event;
Expand Down
1 change: 1 addition & 0 deletions src/Event/InfluxDbEvent.php
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Yproximite\Bundle\InfluxDbPresetBundle\Event;
Expand Down