From 456fbdc10148aac8b53ffebc72b411d1fa55a455 Mon Sep 17 00:00:00 2001 From: jubianchi Date: Fri, 5 Aug 2016 20:40:29 +0200 Subject: [PATCH] Add CS Fixer --- .gitignore | 2 + .php_cs | 11 ++ Makefile | 12 +- bin/kahlan | 48 ----- composer.json | 3 +- composer.lock | 370 +++++++++++++++++++++++++++++++++++- spec/fetch-services.php | 12 +- spec/fetch-volumes.php | 12 +- spec/read-configuratoin.php | 14 +- src/application.php | 24 +-- src/functions.php | 11 +- 11 files changed, 427 insertions(+), 92 deletions(-) create mode 100644 .php_cs delete mode 100644 bin/kahlan diff --git a/.gitignore b/.gitignore index b9fd184..1c191ac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ vendor/ docker.lock +bin/ +!bin/dcv diff --git a/.php_cs b/.php_cs new file mode 100644 index 0000000..ebaf9b8 --- /dev/null +++ b/.php_cs @@ -0,0 +1,11 @@ +exclude('somedir') + ->in(__DIR__.DIRECTORY_SEPARATOR.'src') + ->in(__DIR__.DIRECTORY_SEPARATOR.'spec') +; + +return Symfony\CS\Config\Config::create() + ->finder($finder) +; diff --git a/Makefile b/Makefile index 209b111..3cb3a18 100644 --- a/Makefile +++ b/Makefile @@ -5,13 +5,21 @@ COMPOSERFLAGS ?= DOCKER ?= docker PHP ?= php -.PHONY: clean docker test +.PHONY: clean docker test unit cs fix-cs docker: docker.lock -test: vendor +test: vendor unit cs + +unit: vendor $(PHP) bin/kahlan --pattern='*.php' --reporter=verbose --persistent=false --cc=true +cs: + $(PHP) bin/php-cs-fixer fix --dry-run + +fix-cs + $(PHP) bin/php-cs-fixer fix + clean: rm -rf vendor/ diff --git a/bin/kahlan b/bin/kahlan deleted file mode 100644 index 27357d5..0000000 --- a/bin/kahlan +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env php -service('suite.global', function() { - return new Suite(); -}); - -$specs = new Kahlan([ - 'autoloader' => reset($autoloaders), - 'suite' => $box->get('suite.global') -]); -$specs->loadConfig($argv); -$specs->run(); -exit($specs->status()); diff --git a/composer.json b/composer.json index 3fb5af6..fed01ce 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,8 @@ "graphp/graphviz": "^0.2" }, "require-dev": { - "crysalead/kahlan": "^2.5.4" + "crysalead/kahlan": "^2.5.4", + "friendsofphp/php-cs-fixer": "^1.11" }, "license": "MIT", "authors": [ diff --git a/composer.lock b/composer.lock index c99c1cf..a538a6b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "466baff14323f499d4a7257cdd2805bb", - "content-hash": "4685875c2d24d2ba11ca3ff77293a406", + "hash": "696a6b3b1a107635fb32ba218a89999b", + "content-hash": "507a2cc5a9d6155e47cca472793790e0", "packages": [ { "name": "clue/graph", @@ -364,6 +364,372 @@ "unit test" ], "time": "2016-06-15 15:07:49" + }, + { + "name": "friendsofphp/php-cs-fixer", + "version": "v1.11.6", + "source": { + "type": "git", + "url": "https://github.com/FriendsOfPHP/PHP-CS-Fixer.git", + "reference": "41dc93abd2937a85a3889e28765231d574d2bac8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/41dc93abd2937a85a3889e28765231d574d2bac8", + "reference": "41dc93abd2937a85a3889e28765231d574d2bac8", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=5.3.6", + "sebastian/diff": "~1.1", + "symfony/console": "~2.3|~3.0", + "symfony/event-dispatcher": "~2.1|~3.0", + "symfony/filesystem": "~2.1|~3.0", + "symfony/finder": "~2.1|~3.0", + "symfony/process": "~2.3|~3.0", + "symfony/stopwatch": "~2.5|~3.0" + }, + "conflict": { + "hhvm": "<3.9" + }, + "require-dev": { + "phpunit/phpunit": "^4.5|^5", + "satooshi/php-coveralls": "^0.7.1" + }, + "bin": [ + "php-cs-fixer" + ], + "type": "application", + "autoload": { + "psr-4": { + "Symfony\\CS\\": "Symfony/CS/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Dariusz RumiƄski", + "email": "dariusz.ruminski@gmail.com" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "A tool to automatically fix PHP code style", + "time": "2016-07-22 06:46:28" + }, + { + "name": "sebastian/diff", + "version": "1.4.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "13edfd8706462032c2f52b4b862974dd46b71c9e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/13edfd8706462032c2f52b4b862974dd46b71c9e", + "reference": "13edfd8706462032c2f52b4b862974dd46b71c9e", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.8" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Diff implementation", + "homepage": "https://github.com/sebastianbergmann/diff", + "keywords": [ + "diff" + ], + "time": "2015-12-08 07:14:41" + }, + { + "name": "symfony/event-dispatcher", + "version": "v3.1.3", + "source": { + "type": "git", + "url": "https://github.com/symfony/event-dispatcher.git", + "reference": "c0c00c80b3a69132c4e55c3e7db32b4a387615e5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/c0c00c80b3a69132c4e55c3e7db32b4a387615e5", + "reference": "c0c00c80b3a69132c4e55c3e7db32b4a387615e5", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "~2.8|~3.0", + "symfony/dependency-injection": "~2.8|~3.0", + "symfony/expression-language": "~2.8|~3.0", + "symfony/stopwatch": "~2.8|~3.0" + }, + "suggest": { + "symfony/dependency-injection": "", + "symfony/http-kernel": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\EventDispatcher\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony EventDispatcher Component", + "homepage": "https://symfony.com", + "time": "2016-07-19 10:45:57" + }, + { + "name": "symfony/filesystem", + "version": "v3.1.3", + "source": { + "type": "git", + "url": "https://github.com/symfony/filesystem.git", + "reference": "bb29adceb552d202b6416ede373529338136e84f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/bb29adceb552d202b6416ede373529338136e84f", + "reference": "bb29adceb552d202b6416ede373529338136e84f", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Filesystem\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Filesystem Component", + "homepage": "https://symfony.com", + "time": "2016-07-20 05:44:26" + }, + { + "name": "symfony/finder", + "version": "v3.1.3", + "source": { + "type": "git", + "url": "https://github.com/symfony/finder.git", + "reference": "8201978de88a9fa0923e18601bb17f1df9c721e7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/finder/zipball/8201978de88a9fa0923e18601bb17f1df9c721e7", + "reference": "8201978de88a9fa0923e18601bb17f1df9c721e7", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Finder\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Finder Component", + "homepage": "https://symfony.com", + "time": "2016-06-29 05:41:56" + }, + { + "name": "symfony/process", + "version": "v3.1.3", + "source": { + "type": "git", + "url": "https://github.com/symfony/process.git", + "reference": "04c2dfaae4ec56a5c677b0c69fac34637d815758" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/process/zipball/04c2dfaae4ec56a5c677b0c69fac34637d815758", + "reference": "04c2dfaae4ec56a5c677b0c69fac34637d815758", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Process\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Process Component", + "homepage": "https://symfony.com", + "time": "2016-07-28 11:13:48" + }, + { + "name": "symfony/stopwatch", + "version": "v3.1.3", + "source": { + "type": "git", + "url": "https://github.com/symfony/stopwatch.git", + "reference": "bb42806b12c5f89db4ebf64af6741afe6d8457e1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/stopwatch/zipball/bb42806b12c5f89db4ebf64af6741afe6d8457e1", + "reference": "bb42806b12c5f89db4ebf64af6741afe6d8457e1", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Stopwatch\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Stopwatch Component", + "homepage": "https://symfony.com", + "time": "2016-06-29 05:41:56" } ], "aliases": [], diff --git a/spec/fetch-services.php b/spec/fetch-services.php index 0741acd..d7ac077 100644 --- a/spec/fetch-services.php +++ b/spec/fetch-services.php @@ -2,19 +2,19 @@ use function PMSIpilot\DockerComposeViz\fetchServices; -require_once __DIR__ . '/../vendor/autoload.php'; +require_once __DIR__.'/../vendor/autoload.php'; -describe('Fetching services', function() { - describe('from a version 1 configuration', function() { - it('should fetch services from top-level keys', function() { +describe('Fetching services', function () { + describe('from a version 1 configuration', function () { + it('should fetch services from top-level keys', function () { $configuration = ['foo' => ['image' => 'bar'], 'baz' => ['build' => '.']]; expect(fetchServices($configuration))->toBe($configuration); }); }); - describe('from a version 2 configuration', function() { - it('should fetch services from the dedicated section', function() { + describe('from a version 2 configuration', function () { + it('should fetch services from the dedicated section', function () { $configuration = ['version' => 2, 'services' => ['foo' => ['image' => 'bar'], 'baz' => ['build' => '.']]]; expect(fetchServices($configuration))->toBe($configuration['services']); diff --git a/spec/fetch-volumes.php b/spec/fetch-volumes.php index 17a50ed..ff1fc16 100644 --- a/spec/fetch-volumes.php +++ b/spec/fetch-volumes.php @@ -2,19 +2,19 @@ use function PMSIpilot\DockerComposeViz\fetchVolumes; -require_once __DIR__ . '/../vendor/autoload.php'; +require_once __DIR__.'/../vendor/autoload.php'; -describe('Fetching volumes', function() { - describe('from a version 1 configuration', function() { - it('should always return an empty array', function() { +describe('Fetching volumes', function () { + describe('from a version 1 configuration', function () { + it('should always return an empty array', function () { $configuration = ['volumes' => ['image' => 'bar']]; expect(fetchVolumes($configuration))->toBe([]); }); }); - describe('from a version 2 configuration', function() { - it('should fetch volumes from the dedicated section', function() { + describe('from a version 2 configuration', function () { + it('should fetch volumes from the dedicated section', function () { $configuration = ['version' => 2, 'volumes' => ['foo' => [], 'bar' => []]]; expect(fetchVolumes($configuration))->toBe($configuration['volumes']); diff --git a/spec/read-configuratoin.php b/spec/read-configuratoin.php index 067476b..9cbb0bf 100644 --- a/spec/read-configuratoin.php +++ b/spec/read-configuratoin.php @@ -2,21 +2,21 @@ use function PMSIpilot\DockerComposeViz\readConfiguration; -require_once __DIR__ . '/../vendor/autoload.php'; +require_once __DIR__.'/../vendor/autoload.php'; -describe('Reading configuration', function() { - it('should check if file exists', function() { - expect(function() { readConfiguration(uniqid()); }) +describe('Reading configuration', function () { + it('should check if file exists', function () { + expect(function () { readConfiguration(uniqid()); }) ->toThrow(new InvalidArgumentException()); }); - it('should parse YAML and return an array', function() { + it('should parse YAML and return an array', function () { expect(readConfiguration(__DIR__.'/fixtures/read-configuration/valid.yml')) ->toBe(['version' => 2, 'services' => ['foo' => ['image' => 'bar']]]); }); - it('should report if YAML is invalid', function() { - expect(function() { readConfiguration(__DIR__.'/fixtures/read-configuration/invalid.json'); }) + it('should report if YAML is invalid', function () { + expect(function () { readConfiguration(__DIR__.'/fixtures/read-configuration/invalid.json'); }) ->toThrow(new InvalidArgumentException()); }); }); diff --git a/src/application.php b/src/application.php index 4fc396e..a07fdb0 100644 --- a/src/application.php +++ b/src/application.php @@ -4,21 +4,17 @@ namespace PMSIpilot\DockerComposeViz; use Graphp\GraphViz\GraphViz; use Symfony\Component\Console; -use Symfony\Component\Yaml\Yaml; - -use function PMSIpilot\DockerComposeViz\{ - readConfiguration, - fetchServices, - fetchVolumes, - fetchNetworks, - createGraph, - applyGraphvizStyle -}; +use function PMSIpilot\DockerComposeViz\readConfiguration; +use function PMSIpilot\DockerComposeViz\fetchServices; +use function PMSIpilot\DockerComposeViz\fetchVolumes; +use function PMSIpilot\DockerComposeViz\fetchNetworks; +use function PMSIpilot\DockerComposeViz\createGraph; +use function PMSIpilot\DockerComposeViz\applyGraphvizStyle; $application = new Console\Application(); $application->register('render') - ->addArgument('input-file',Console\Input\InputArgument::OPTIONAL, 'Path to a docker compose file', getcwd().DIRECTORY_SEPARATOR.'docker-compose.yml') + ->addArgument('input-file', Console\Input\InputArgument::OPTIONAL, 'Path to a docker compose file', getcwd().DIRECTORY_SEPARATOR.'docker-compose.yml') ->addOption('output-file', 'o', Console\Input\InputOption::VALUE_REQUIRED, 'Path to a output file (Only for "dot" and "image" output format)') ->addOption('output-format', 'm', Console\Input\InputOption::VALUE_REQUIRED, 'Output format (one of: "dot", "image", "display")', 'display') @@ -28,7 +24,7 @@ $application->register('render') ->addOption('no-volumes', null, Console\Input\InputOption::VALUE_NONE, 'Do not display volumes') ->addOption('horizontal', 'r', Console\Input\InputOption::VALUE_NONE, 'Display a horizontal graph') - ->setCode(function(Console\Input\InputInterface $input, Console\Output\OutputInterface $output) { + ->setCode(function (Console\Input\InputInterface $input, Console\Output\OutputInterface $output) { $inputFile = $input->getArgument('input-file'); $outputFormat = $input->getOption('output-format'); $outputFile = $input->getOption('output-file') ?: getcwd().DIRECTORY_SEPARATOR.'docker-compose.'.($outputFormat === 'dot' ? $outputFormat : 'png'); @@ -62,7 +58,7 @@ $application->register('render') $services = array_filter( $services, - function($service) use ($onlyServices) { + function ($service) use ($onlyServices) { return in_array($service, $onlyServices); }, ARRAY_FILTER_USE_KEY @@ -77,7 +73,7 @@ $application->register('render') switch ($outputFormat) { case 'dot': case 'image': - $rendererClass = 'Graphp\GraphViz\\' . ucfirst($outputFormat); + $rendererClass = 'Graphp\GraphViz\\'.ucfirst($outputFormat); $renderer = new $rendererClass(); file_put_contents($outputFile, $renderer->getOutput($graph)); diff --git a/src/functions.php b/src/functions.php index 3d96e60..02c72da 100644 --- a/src/functions.php +++ b/src/functions.php @@ -76,7 +76,6 @@ function fetchNetworks(array $configuration) : array return $configuration['networks'] ?? []; } - /** * @public * @@ -338,8 +337,8 @@ function addPort(Graph $graph, int $port, string $proto = null) /** * @internal * - * @param Graph $graph Input graph - * @param string $path Path + * @param Graph $graph Input graph + * @param string $path Path * * @return Vertex */ @@ -358,9 +357,9 @@ function addVolume(Graph $graph, string $path) /** * @internal * - * @param Graph $graph Input graph - * @param string $name Name of the network - * @param string $type Network type + * @param Graph $graph Input graph + * @param string $name Name of the network + * @param string $type Network type * * @return Vertex */