Skip to content

Commit

Permalink
Upgrade CS
Browse files Browse the repository at this point in the history
  • Loading branch information
simPod committed Oct 13, 2020
1 parent ed60e7e commit 2a4b1bc
Show file tree
Hide file tree
Showing 23 changed files with 78 additions and 114 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"symfony/yaml": "^4.3|^5.0"
},
"require-dev": {
"cdn77/coding-standard": "^2.0",
"cdn77/coding-standard": "^4.0",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "0.12.7",
"phpstan/phpstan-phpunit": "0.12.6",
Expand Down
28 changes: 13 additions & 15 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
<?xml version="1.0" ?>
<?xml version="1.0"?>
<ruleset>
<rule ref="Cdn77CodingStandard"/>

<arg name="basepath" value="."/>
<arg name="extensions" value="php"/>
<arg name="encoding" value="utf-8"/>
<arg value="s"/>
<arg value="n"/>
<arg value="p"/>
<arg name="basepath" value="." />
<arg name="extensions" value="php" />
<arg name="parallel" value="80" />
<arg name="cache" value=".phpcs-cache" />
<arg name="colors" />
<arg name="parallel" value="80"/>
<arg name="cache" value=".phpcs-cache"/>

<file>src/</file>
<file>tests/</file>
<!-- Ignore warnings, show progress of the run and show sniff names -->
<arg value="nps" />

<file>src</file>
<file>tests</file>

<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFallbackGlobalName">
<severity>5</severity>
<rule ref="Cdn77">
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint" />
<exclude name="SlevomatCodingStandard.PHP.RequireExplicitAssertion.RequiredExplicitAssertion" />
</rule>
</ruleset>
13 changes: 7 additions & 6 deletions src/Configuration/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,28 @@ public function __construct(
$this->readWriteTimeout = $readWriteTimeout;
}

/**
* @param mixed[] $configuration
*/
/** @param mixed[] $configuration */
public static function fromDI(array $configuration) : self
{
$dsn = new Dsn($configuration[Configuration::KEY_CONFIGURATION_DSN]);
$new = self::fromDsn($dsn);

if (isset($configuration[Configuration::KEY_CONFIGURATION_HEARTBEAT])
if (
isset($configuration[Configuration::KEY_CONFIGURATION_HEARTBEAT])
&& ! isset($dsn->getParameters()[Configuration::KEY_CONFIGURATION_HEARTBEAT])
) {
$new->heartbeat = (int) $configuration[Configuration::KEY_CONFIGURATION_HEARTBEAT];
}

if (isset($configuration[Configuration::KEY_CONFIGURATION_CONNECTION_TIMEOUT])
if (
isset($configuration[Configuration::KEY_CONFIGURATION_CONNECTION_TIMEOUT])
&& ! isset($dsn->getParameters()[Configuration::KEY_CONFIGURATION_CONNECTION_TIMEOUT])
) {
$new->connectionTimeout = (int) $configuration[Configuration::KEY_CONFIGURATION_CONNECTION_TIMEOUT];
}

if (isset($configuration[Configuration::KEY_CONFIGURATION_READ_WRITE_TIMEOUT])
if (
isset($configuration[Configuration::KEY_CONFIGURATION_READ_WRITE_TIMEOUT])
&& ! isset($dsn->getParameters()[Configuration::KEY_CONFIGURATION_READ_WRITE_TIMEOUT])
) {
$new->readWriteTimeout = (int) $configuration[Configuration::KEY_CONFIGURATION_READ_WRITE_TIMEOUT];
Expand Down
35 changes: 17 additions & 18 deletions src/Configuration/Dsn.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Cdn77\RabbitMQBundle\Configuration;

use Cdn77\RabbitMQBundle\Exception\InvalidDsn;

use function count;
use function http_build_query;
use function parse_str;
Expand Down Expand Up @@ -65,6 +66,21 @@ public function __construct(string $dsn)
parse_str($parts['query'], $this->parameters);
}

public function __toString() : string
{
return sprintf(
'%s://%s:%s@%s:%s/%s%s%s',
self::SCHEME,
$this->username,
$this->password,
$this->host,
$this->port,
$this->vhost === '/' ? '' : $this->vhost,
count($this->parameters) !== 0 ? '?' : '',
count($this->parameters) !== 0 ? http_build_query($this->parameters) : ''
);
}

public function getHost() : string
{
return $this->host;
Expand All @@ -90,26 +106,9 @@ public function getVhost() : string
return $this->vhost;
}

/**
* @return string[]
*/
/** @return string[] */
public function getParameters() : array
{
return $this->parameters;
}

public function __toString() : string
{
return sprintf(
'%s://%s:%s@%s:%s/%s%s%s',
self::SCHEME,
$this->username,
$this->password,
$this->host,
$this->port,
$this->vhost === '/' ? '' : $this->vhost,
count($this->parameters) !== 0 ? '?' : '',
count($this->parameters) !== 0 ? http_build_query($this->parameters) : ''
);
}
}
12 changes: 3 additions & 9 deletions src/Configuration/Topology.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ public function __construct(array $exchanges, array $exchangeBindings, array $qu
}
}

/**
* @param mixed[] $configuration
*/
/** @param mixed[] $configuration */
public static function fromDI(array $configuration) : self
{
$exchanges = [];
Expand Down Expand Up @@ -107,17 +105,13 @@ public static function fromDI(array $configuration) : self
return new self($exchanges, $exchangesBindings, $queues, $queuesBindings);
}

/**
* @return Exchange[]
*/
/** @return Exchange[] */
public function getExchanges() : array
{
return $this->exchanges;
}

/**
* @return Queue[]
*/
/** @return Queue[] */
public function getQueues() : array
{
return $this->queues;
Expand Down
1 change: 1 addition & 0 deletions src/Console/ConsumerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

use function assert;
use function is_string;
use function strtolower;
Expand Down
1 change: 1 addition & 0 deletions src/ConsumerRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Cdn77\RabbitMQBundle\RabbitMQ\Connection;
use Cdn77\RabbitMQBundle\RabbitMQ\Consumer\Configuration;
use Cdn77\RabbitMQBundle\RabbitMQ\Consumer\Consumer;

use function microtime;

final class ConsumerRunner
Expand Down
12 changes: 7 additions & 5 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

use function assert;

final class Configuration implements ConfigurationInterface
{
public const KEY_BINDING_EXCHANGE = 'exchange';
Expand Down Expand Up @@ -41,8 +43,8 @@ public function getConfigTreeBuilder() : TreeBuilder
{
$treeBuilder = new TreeBuilder(RabbitMQExtension::ALIAS);

/** @var ArrayNodeDefinition $rootNode */
$rootNode = $treeBuilder->getRootNode();
assert($rootNode instanceof ArrayNodeDefinition);

$this->configureConnection($rootNode);
$this->configureExchanges($rootNode);
Expand Down Expand Up @@ -72,13 +74,13 @@ private function configureConnection(ArrayNodeDefinition $rootNode) : void

private function configureExchanges(ArrayNodeDefinition $rootNode) : void
{
/** @var ArrayNodeDefinition $exchangesNode */
$exchangesNode = $rootNode->children()
->arrayNode(self::KEY_CONFIGURATION_EXCHANGES)
->useAttributeAsKey(self::KEY_EXCHANGE_NAME)
->normalizeKeys(false)
->defaultValue([])
->prototype('array');
assert($exchangesNode instanceof ArrayNodeDefinition);

$exchangesNode->children()
->scalarNode(self::KEY_EXCHANGE_TYPE);
Expand Down Expand Up @@ -106,13 +108,13 @@ private function configureExchanges(ArrayNodeDefinition $rootNode) : void

private function configureQueues(ArrayNodeDefinition $rootNode) : void
{
/** @var ArrayNodeDefinition $queuesNode */
$queuesNode = $rootNode->children()
->arrayNode(self::KEY_CONFIGURATION_QUEUES)
->useAttributeAsKey(self::KEY_QUEUE_NAME)
->normalizeKeys(false)
->defaultValue([])
->prototype('array');
assert($queuesNode instanceof ArrayNodeDefinition);

$queuesNode->children()
->booleanNode(self::KEY_QUEUE_DURABLE)
Expand All @@ -137,24 +139,24 @@ private function configureQueues(ArrayNodeDefinition $rootNode) : void

private function configureExchangeBindings(ArrayNodeDefinition $exchangesNode) : void
{
/** @var ArrayNodeDefinition $exchangesBindingsNode */
$exchangesBindingsNode = $exchangesNode->children()
->arrayNode(self::KEY_EXCHANGE_BINDINGS)
->normalizeKeys(false)
->defaultValue([])
->prototype('array');
assert($exchangesBindingsNode instanceof ArrayNodeDefinition);

$this->configureBindingNode($exchangesBindingsNode);
}

private function configureQueueBindings(ArrayNodeDefinition $queuesNode) : void
{
/** @var ArrayNodeDefinition $queueBindingsNode */
$queueBindingsNode = $queuesNode->children()
->arrayNode(self::KEY_QUEUE_BINDINGS)
->normalizeKeys(false)
->defaultValue([])
->prototype('array');
assert($queueBindingsNode instanceof ArrayNodeDefinition);

$this->configureBindingNode($queueBindingsNode);
}
Expand Down
1 change: 1 addition & 0 deletions src/Exception/CannotCreateChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Cdn77\RabbitMQBundle\Exception;

use RuntimeException;

use function sprintf;

final class CannotCreateChannel extends RuntimeException implements Exception
Expand Down
1 change: 1 addition & 0 deletions src/Exception/ConfigurationFailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Cdn77\RabbitMQBundle\RabbitMQ\Exchange;
use Cdn77\RabbitMQBundle\RabbitMQ\Queue;
use RuntimeException;

use function sprintf;

final class ConfigurationFailed extends RuntimeException implements Exception
Expand Down
1 change: 1 addition & 0 deletions src/Exception/ConsumerFailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Cdn77\RabbitMQBundle\Exception;

use InvalidArgumentException;

use function sprintf;

final class ConsumerFailed extends InvalidArgumentException implements Exception
Expand Down
1 change: 1 addition & 0 deletions src/Exception/InvalidDsn.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Cdn77\RabbitMQBundle\Exception;

use LogicException;

use function sprintf;

final class InvalidDsn extends LogicException implements Exception
Expand Down
1 change: 1 addition & 0 deletions src/Exception/OperationFailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Cdn77\RabbitMQBundle\Exception;

use RuntimeException;

use function sprintf;

final class OperationFailed extends RuntimeException implements Exception
Expand Down
12 changes: 3 additions & 9 deletions src/RabbitMQ/Binding.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,15 @@ final class Binding
/** @var mixed[] */
private $arguments;

/**
* @param mixed[] $arguments
*/
/** @param mixed[] $arguments */
public function __construct(Bindable $bindable, string $routingKey, array $arguments = [])
{
$this->bindable = $bindable;
$this->routingKey = $routingKey;
$this->arguments = $arguments;
}

/**
* @param mixed[] $configuration
*/
/** @param mixed[] $configuration */
public static function fromConfiguration(Bindable $bindable, array $configuration) : self
{
return new self(
Expand All @@ -49,9 +45,7 @@ public function getRoutingKey() : string
return $this->routingKey;
}

/**
* @return mixed[]
*/
/** @return mixed[] */
public function getArguments() : array
{
return $this->arguments;
Expand Down
16 changes: 4 additions & 12 deletions src/RabbitMQ/Exchange.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ final class Exchange implements Bindable
/** @var Binding[] */
private $bindings = [];

/**
* @param mixed[] $arguments
*/
/** @param mixed[] $arguments */
public function __construct(
string $name,
ExchangeType $exchangeType,
Expand All @@ -48,9 +46,7 @@ public function __construct(
$this->arguments = $arguments;
}

/**
* @param mixed[] $configuration
*/
/** @param mixed[] $configuration */
public static function fromConfiguration(string $name, array $configuration) : self
{
return new self(
Expand Down Expand Up @@ -83,9 +79,7 @@ public function getExchangeType() : ExchangeType
return $this->exchangeType;
}

/**
* @return Binding[]
*/
/** @return Binding[] */
public function getBindings() : array
{
return $this->bindings;
Expand All @@ -101,9 +95,7 @@ public function isInternal() : bool
return $this->internal;
}

/**
* @return mixed[]
*/
/** @return mixed[] */
public function getArguments() : array
{
return $this->arguments;
Expand Down
8 changes: 2 additions & 6 deletions src/RabbitMQ/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ class Message
/** @var mixed[] */
public $headers;

/**
* @param mixed[] $headers
*/
/** @param mixed[] $headers */
public function __construct(string $body, array $headers = [])
{
$this->body = $body;
Expand All @@ -28,9 +26,7 @@ public function __construct(string $body, array $headers = [])
$this->headers = $headers;
}

/**
* @param mixed[] $headers
*/
/** @param mixed[] $headers */
public static function json(string $body, array $headers = []) : self
{
return new self($body, ['Content-Type' => 'application/json'] + $headers);
Expand Down
Loading

0 comments on commit 2a4b1bc

Please sign in to comment.