diff --git a/.gitignore b/.gitignore index ec60c84f8..b9809c577 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,6 @@ bin/doctrine* bin/php-cs-fixer bin/phpunit bin/sql-formatter -vendor \ No newline at end of file +vendor +.php_cs +.php_cs.cache \ No newline at end of file diff --git a/.php_cs b/.php_cs deleted file mode 100644 index d3414a1f1..000000000 --- a/.php_cs +++ /dev/null @@ -1,21 +0,0 @@ -in(__DIR__) - ->notPath('vendor') -; - -return Symfony\CS\Config::create() - ->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL) - ->fixers([ - 'ordered_use', - 'no_blank_lines_before_namespace', - 'short_array_syntax', - 'unused_use', - 'phpdoc_order', - - - ]) - ->finder($finder) -; - diff --git a/.php_cs.dist b/.php_cs.dist new file mode 100644 index 000000000..99a418499 --- /dev/null +++ b/.php_cs.dist @@ -0,0 +1,28 @@ +setRiskyAllowed(true) + ->setRules(array( + '@Symfony' => true, + '@Symfony:risky' => true, + 'array_syntax' => array('syntax' => 'short'), + 'combine_consecutive_unsets' => true, + // one should use PHPUnit methods to set up expected exception instead of annotations + 'general_phpdoc_annotation_remove' => array('expectedException', 'expectedExceptionMessage', 'expectedExceptionMessageRegExp'), + 'heredoc_to_nowdoc' => true, + 'no_extra_consecutive_blank_lines' => array('break', 'continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block'), + 'no_unreachable_default_argument_value' => true, + 'no_useless_else' => true, + 'no_useless_return' => true, + 'ordered_class_elements' => true, + 'ordered_imports' => true, + 'phpdoc_add_missing_param_annotation' => true, + 'phpdoc_order' => true, + 'psr4' => true, + 'strict_param' => true, + )) + ->setFinder( + PhpCsFixer\Finder::create() + ->in(__DIR__) + ) +; \ No newline at end of file diff --git a/bin/dev b/bin/dev index dcfa42f1e..11f87e39d 100755 --- a/bin/dev +++ b/bin/dev @@ -3,7 +3,7 @@ set -x set -e -while getopts "buste" OPTION; do +while getopts "bustef" OPTION; do case $OPTION in b) COMPOSE_PROJECT_NAME=mqdev docker-compose build @@ -17,6 +17,9 @@ while getopts "buste" OPTION; do e) docker exec -it mqdev_dev_1 /bin/bash ;; + f) + ./bin/php-cs-fixer fix + ;; t) COMPOSE_PROJECT_NAME=mqdev docker-compose run --workdir="/mqdev" --rm dev ./bin/test ;; diff --git a/bin/pre-commit b/bin/pre-commit index 9ab08b441..4537cf91a 100755 --- a/bin/pre-commit +++ b/bin/pre-commit @@ -105,11 +105,10 @@ function runPhpCsFixer() $output = ''; $returnCode = null; exec(sprintf( - '%s %s fix %s --config-file=%s', + '%s %s fix %s', $phpBin, $phpCsFixerBin, - $projectRootDir.'/'.$file, - $projectRootDir.'/.php_cs' + $projectRootDir.'/'.$file ), $output, $returnCode); if ($returnCode) { diff --git a/composer.json b/composer.json index e0fe925ad..cce8a9151 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "symfony/monolog-bundle": "^2.8|^3", "symfony/browser-kit": "^2.8|^3", "symfony/expression-language": "^2.8|^3", - "friendsofphp/php-cs-fixer": "^1" + "friendsofphp/php-cs-fixer": "^2" }, "config": { "bin-dir": "bin" diff --git a/pkg/amqp-ext/AmqpConnectionFactory.php b/pkg/amqp-ext/AmqpConnectionFactory.php index dfe36a35f..ab46fe0f0 100644 --- a/pkg/amqp-ext/AmqpConnectionFactory.php +++ b/pkg/amqp-ext/AmqpConnectionFactory.php @@ -1,4 +1,5 @@ bind($destination, $queue); return new AmqpConsumer($this, $queue); - } else { - return new AmqpConsumer($this, $destination); } + + return new AmqpConsumer($this, $destination); } public function close() diff --git a/pkg/amqp-ext/AmqpMessage.php b/pkg/amqp-ext/AmqpMessage.php index 044c4f19e..d5992237b 100644 --- a/pkg/amqp-ext/AmqpMessage.php +++ b/pkg/amqp-ext/AmqpMessage.php @@ -1,4 +1,5 @@ assertSame(null, $message->getBody()); + $this->assertNull($message->getBody()); $this->assertSame([], $message->getProperties()); $this->assertSame([], $message->getHeaders()); } diff --git a/pkg/amqp-ext/Tests/AmqpQueueTest.php b/pkg/amqp-ext/Tests/AmqpQueueTest.php index 9381c1def..56e234764 100644 --- a/pkg/amqp-ext/Tests/AmqpQueueTest.php +++ b/pkg/amqp-ext/Tests/AmqpQueueTest.php @@ -1,4 +1,5 @@ true]); - $meta = new QueueMetaRegistry($config, ['default' => []]); $driver = new RabbitMqDriver($context, $config, $meta); diff --git a/pkg/amqp-ext/Tests/Functional/AmqpCommonUseCasesTest.php b/pkg/amqp-ext/Tests/Functional/AmqpCommonUseCasesTest.php index 45a884231..be0ef4fef 100644 --- a/pkg/amqp-ext/Tests/Functional/AmqpCommonUseCasesTest.php +++ b/pkg/amqp-ext/Tests/Functional/AmqpCommonUseCasesTest.php @@ -1,4 +1,5 @@ amqpContext->createConsumer($topic); //guard - $this->assertSame(null, $consumer->receive(1)); + $this->assertNull($consumer->receive(1)); $message = $this->amqpContext->createMessage(__METHOD__); diff --git a/pkg/amqp-ext/Tests/Functional/AmqpConsumptionUseCasesTest.php b/pkg/amqp-ext/Tests/Functional/AmqpConsumptionUseCasesTest.php index 66705ae7f..76abbfce9 100644 --- a/pkg/amqp-ext/Tests/Functional/AmqpConsumptionUseCasesTest.php +++ b/pkg/amqp-ext/Tests/Functional/AmqpConsumptionUseCasesTest.php @@ -1,4 +1,5 @@ assertEquals('test message body', $processor->message->getBody()); } - private function getMessageProducer() - { - return $this->container->get('enqueue.client.message_producer'); - } - /** * @return string */ @@ -101,4 +97,9 @@ public static function getKernelClass() return AmqpAppKernel::class; } + + private function getMessageProducer() + { + return $this->container->get('enqueue.client.message_producer'); + } } diff --git a/pkg/enqueue-bundle/Tests/Functional/ContextTest.php b/pkg/enqueue-bundle/Tests/Functional/ContextTest.php index 557005797..f11a9b17a 100644 --- a/pkg/enqueue-bundle/Tests/Functional/ContextTest.php +++ b/pkg/enqueue-bundle/Tests/Functional/ContextTest.php @@ -1,4 +1,5 @@ load(__DIR__.'/config/amqp-config.yml'); } + + protected function getContainerClass() + { + return parent::getContainerClass().'BundleAmqp'; + } } diff --git a/pkg/enqueue-bundle/Tests/Functional/app/AppKernel.php b/pkg/enqueue-bundle/Tests/Functional/app/AppKernel.php index 9c84fd9ee..e2ed065a3 100644 --- a/pkg/enqueue-bundle/Tests/Functional/app/AppKernel.php +++ b/pkg/enqueue-bundle/Tests/Functional/app/AppKernel.php @@ -1,4 +1,5 @@ load(__DIR__.'/config/config.yml'); } + + protected function getContainerClass() + { + return parent::getContainerClass().'BundleDefault'; + } } diff --git a/pkg/enqueue-bundle/Tests/Unit/Consumption/Extension/DoctrineClearIdentityMapExtensionTest.php b/pkg/enqueue-bundle/Tests/Unit/Consumption/Extension/DoctrineClearIdentityMapExtensionTest.php index c9b0c8901..7bf9eaa36 100644 --- a/pkg/enqueue-bundle/Tests/Unit/Consumption/Extension/DoctrineClearIdentityMapExtensionTest.php +++ b/pkg/enqueue-bundle/Tests/Unit/Consumption/Extension/DoctrineClearIdentityMapExtensionTest.php @@ -1,4 +1,5 @@ reason = (string) $reason; } + /** + * @return string + */ + public function __toString() + { + return $this->status; + } + /** * @return string */ @@ -78,14 +87,6 @@ public function setReply(PsrMessage $reply = null) $this->reply = $reply; } - /** - * @return string - */ - public function __toString() - { - return $this->status; - } - /** * @param string $reason * diff --git a/pkg/enqueue/Router/Recipient.php b/pkg/enqueue/Router/Recipient.php index 94083a2b0..892c0e511 100644 --- a/pkg/enqueue/Router/Recipient.php +++ b/pkg/enqueue/Router/Recipient.php @@ -1,4 +1,5 @@ consumer->acknowledge($message); return $message; - } else { - $this->consumer->reject($message, true); } + $this->consumer->reject($message, true); } } diff --git a/pkg/enqueue/Rpc/RpcClient.php b/pkg/enqueue/Rpc/RpcClient.php index e8b4b6268..fad0bcd69 100644 --- a/pkg/enqueue/Rpc/RpcClient.php +++ b/pkg/enqueue/Rpc/RpcClient.php @@ -1,4 +1,5 @@ extension; + } + protected function configure() { parent::configure(); @@ -26,9 +32,4 @@ protected function execute(InputInterface $input, OutputInterface $output) { $this->extension = $this->getSetupBrokerExtension($input, new NullDriver(new NullContext(), Config::create())); } - - public function getExtension() - { - return $this->extension; - } } diff --git a/pkg/enqueue/Tests/Symfony/Client/ProduceMessageCommandTest.php b/pkg/enqueue/Tests/Symfony/Client/ProduceMessageCommandTest.php index cd3bed816..6cbfbfc1d 100644 --- a/pkg/enqueue/Tests/Symfony/Client/ProduceMessageCommandTest.php +++ b/pkg/enqueue/Tests/Symfony/Client/ProduceMessageCommandTest.php @@ -1,4 +1,5 @@ extensions; + } + protected function configure() { parent::configure(); @@ -23,9 +29,4 @@ protected function execute(InputInterface $input, OutputInterface $output) { $this->extensions = $this->getLimitsExtensions($input, $output); } - - public function getExtensions() - { - return $this->extensions; - } } diff --git a/pkg/enqueue/Tests/Symfony/DefaultTransportFactoryTest.php b/pkg/enqueue/Tests/Symfony/DefaultTransportFactoryTest.php index 3fbc5c59a..917ad5d2b 100644 --- a/pkg/enqueue/Tests/Symfony/DefaultTransportFactoryTest.php +++ b/pkg/enqueue/Tests/Symfony/DefaultTransportFactoryTest.php @@ -1,4 +1,5 @@ assertInstanceOf(NullMessage::class, $message); - $this->assertSame(null, $message->getBody()); + $this->assertNull($message->getBody()); $this->assertSame([], $message->getHeaders()); $this->assertSame([], $message->getProperties()); } diff --git a/pkg/enqueue/Tests/Transport/Null/NullMessageTest.php b/pkg/enqueue/Tests/Transport/Null/NullMessageTest.php index d8d2569bc..ddf9cd2d5 100644 --- a/pkg/enqueue/Tests/Transport/Null/NullMessageTest.php +++ b/pkg/enqueue/Tests/Transport/Null/NullMessageTest.php @@ -1,4 +1,5 @@ assertSame(null, $message->getBody()); + $this->assertNull($message->getBody()); } public function testShouldNewMessageReturnEmptyProperties() diff --git a/pkg/enqueue/Tests/Transport/Null/NullProducerTest.php b/pkg/enqueue/Tests/Transport/Null/NullProducerTest.php index 39c05898f..1e90bf349 100644 --- a/pkg/enqueue/Tests/Transport/Null/NullProducerTest.php +++ b/pkg/enqueue/Tests/Transport/Null/NullProducerTest.php @@ -1,4 +1,5 @@ toString(); - } else { - return RhumsaaUuid::uuid4()->toString(); } + + return RhumsaaUuid::uuid4()->toString(); } } diff --git a/pkg/enqueue/Util/VarExport.php b/pkg/enqueue/Util/VarExport.php index 897c664f3..4a48afadd 100644 --- a/pkg/enqueue/Util/VarExport.php +++ b/pkg/enqueue/Util/VarExport.php @@ -1,4 +1,5 @@ isRoot() ? $job : $job->getRootJob(); $stopStatuses = [Job::STATUS_SUCCESS, Job::STATUS_FAILED, Job::STATUS_CANCELLED]; - if (in_array($rootJob->getStatus(), $stopStatuses)) { + if (in_array($rootJob->getStatus(), $stopStatuses, true)) { return; } $rootStopped = false; $this->jobStorage->saveJob($rootJob, function (Job $rootJob) use ($stopStatuses, &$rootStopped) { - if (in_array($rootJob->getStatus(), $stopStatuses)) { + if (in_array($rootJob->getStatus(), $stopStatuses, true)) { return; } @@ -47,7 +48,7 @@ public function calculate(Job $job) $rootJob->setStatus($status); - if (in_array($status, $stopStatuses)) { + if (in_array($status, $stopStatuses, true)) { $rootStopped = true; if (!$rootJob->getStoppedAt()) { $rootJob->setStoppedAt(new \DateTime()); diff --git a/pkg/job-queue/DependentJobContext.php b/pkg/job-queue/DependentJobContext.php index 6393eed5f..34deba656 100644 --- a/pkg/job-queue/DependentJobContext.php +++ b/pkg/job-queue/DependentJobContext.php @@ -1,4 +1,5 @@ jobStorage->findJobById($job->getId()); - if (!in_array($job->getStatus(), [Job::STATUS_NEW, Job::STATUS_RUNNING])) { + if (!in_array($job->getStatus(), [Job::STATUS_NEW, Job::STATUS_RUNNING], true)) { throw new \LogicException(sprintf( 'Can cancel only new or running jobs. id: "%s", status: "%s"', $job->getId(), diff --git a/pkg/job-queue/JobRunner.php b/pkg/job-queue/JobRunner.php index c0adb97b0..bfca429a6 100644 --- a/pkg/job-queue/JobRunner.php +++ b/pkg/job-queue/JobRunner.php @@ -1,4 +1,5 @@ wrapTransactionNestingLevel('rollBack'); } - /** - * @param int $level - */ - private function setTransactionNestingLevel($level) - { - $prop = new \ReflectionProperty('Doctrine\DBAL\Connection', '_transactionNestingLevel'); - $prop->setAccessible(true); - - return $prop->setValue($this, $level); - } - - /** - * @param string $method - * - * @throws \Exception - */ - private function wrapTransactionNestingLevel($method) - { - $e = null; - - $this->setTransactionNestingLevel($this->getPersistedTransactionNestingLevel()); - - try { - call_user_func(['parent', $method]); - } catch (\Exception $e) { - } - - $this->persistTransactionNestingLevel($this->getTransactionNestingLevel()); - - if ($e) { - throw $e; - } - } - /** * @param bool $connected */ @@ -161,4 +128,38 @@ protected function getConnectionId() { return md5(serialize($this->getParams())); } + + /** + * @param int $level + */ + private function setTransactionNestingLevel($level) + { + $prop = new \ReflectionProperty('Doctrine\DBAL\Connection', '_transactionNestingLevel'); + $prop->setAccessible(true); + + return $prop->setValue($this, $level); + } + + /** + * @param string $method + * + * @throws \Exception + */ + private function wrapTransactionNestingLevel($method) + { + $e = null; + + $this->setTransactionNestingLevel($this->getPersistedTransactionNestingLevel()); + + try { + call_user_func(['parent', $method]); + } catch (\Exception $e) { + } + + $this->persistTransactionNestingLevel($this->getTransactionNestingLevel()); + + if ($e) { + throw $e; + } + } } diff --git a/pkg/job-queue/Test/JobRunner.php b/pkg/job-queue/Test/JobRunner.php index fe2d3cb77..62d9f9a52 100644 --- a/pkg/job-queue/Test/JobRunner.php +++ b/pkg/job-queue/Test/JobRunner.php @@ -1,4 +1,5 @@ load(__DIR__.'/config/config.yml'); } + + protected function getContainerClass() + { + return parent::getContainerClass().'JobQueue'; + } } diff --git a/pkg/job-queue/Tests/JobProcessorTest.php b/pkg/job-queue/Tests/JobProcessorTest.php index 85c7f06f8..31ce0a7d8 100644 --- a/pkg/job-queue/Tests/JobProcessorTest.php +++ b/pkg/job-queue/Tests/JobProcessorTest.php @@ -1,12 +1,13 @@ $value) { + if (0 === strpos($key, self::PROPERTY_PREFIX)) { + $encodedProperties[substr($key, $prefixLength)] = $value; + } else { + $encodedHeaders[$key] = $value; + } + } + + $decodedHeaders = self::doDecode($encodedHeaders); + $decodedProperties = self::doDecode($encodedProperties); + + return [$decodedHeaders, $decodedProperties]; + } + /** * @param array $headers * @@ -72,32 +99,6 @@ private static function doEncode($headers = []) return $encoded; } - /** - * @param array $headers - * - * @return array [[headers], [properties]] - */ - public static function decode(array $headers = []) - { - $encodedHeaders = []; - $encodedProperties = []; - $prefixLength = strlen(self::PROPERTY_PREFIX); - - // separate headers/properties - foreach ($headers as $key => $value) { - if (0 === strpos($key, self::PROPERTY_PREFIX)) { - $encodedProperties[substr($key, $prefixLength)] = $value; - } else { - $encodedHeaders[$key] = $value; - } - } - - $decodedHeaders = self::doDecode($encodedHeaders); - $decodedProperties = self::doDecode($encodedProperties); - - return [$decodedHeaders, $decodedProperties]; - } - /** * @param array $headers * diff --git a/pkg/stomp/StompMessage.php b/pkg/stomp/StompMessage.php index 5eb1c0843..ed90f6317 100644 --- a/pkg/stomp/StompMessage.php +++ b/pkg/stomp/StompMessage.php @@ -1,4 +1,5 @@