chore: Update dependencies

This commit is contained in:
jubianchi 2018-01-20 10:41:27 +01:00
parent 27758c0f0a
commit f6f67be46c
No known key found for this signature in database
GPG key ID: 5D9C896D2AA9E390
7 changed files with 660 additions and 172 deletions

1
.gitignore vendored
View file

@ -4,3 +4,4 @@ bin/
!bin/dcv !bin/dcv
!bin/entrypoint.sh !bin/entrypoint.sh
.cache/ .cache/
.php_cs.cache

13
.php_cs
View file

@ -1,12 +1,15 @@
<?php <?php
$finder = Symfony\CS\Finder\DefaultFinder::create() use PhpCsFixer as CS;
->exclude('somedir')
$finder = CS\Finder::create()
->in(__DIR__.DIRECTORY_SEPARATOR.'src') ->in(__DIR__.DIRECTORY_SEPARATOR.'src')
->in(__DIR__.DIRECTORY_SEPARATOR.'spec') ->in(__DIR__.DIRECTORY_SEPARATOR.'spec')
; ;
return Symfony\CS\Config\Config::create() return CS\Config::create()
->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL) ->setRules([
->finder($finder) '@Symfony' => true,
])
->setFinder($finder)
; ;

View file

@ -8,12 +8,14 @@ services:
php: php:
- 7.0 - 7.0
- 7.1 - 7.1
- 7.2
- nightly - nightly
env: env:
matrix: matrix:
- COMPOSERFLAGS= - COMPOSERFLAGS=
- COMPOSERFLAGS=--prefer-lowest - COMPOSERFLAGS=--prefer-lowest
- COMPOSERFLAGS=--prefer-stable
global: global:
# DOCKER_EMAIL # DOCKER_EMAIL
@ -29,6 +31,8 @@ matrix:
env: COMPOSERFLAGS= env: COMPOSERFLAGS=
- php: 7.1 - php: 7.1
env: COMPOSERFLAGS=--prefer-lowest env: COMPOSERFLAGS=--prefer-lowest
- php: 7.2
env: COMPOSERFLAGS=--prefer-lowest
- php: nightly - php: nightly
env: COMPOSERFLAGS=--prefer-lowest env: COMPOSERFLAGS=--prefer-lowest
allow_failures: allow_failures:

View file

@ -2,14 +2,15 @@
"name": "pmsipilot/docker-compose-viz", "name": "pmsipilot/docker-compose-viz",
"description": "Docker compose graph visualization", "description": "Docker compose graph visualization",
"require": { "require": {
"symfony/yaml": "^3.1 || ^4@dev", "php": "^7",
"symfony/yaml": "^3.1 || ^4",
"symfony/console": "^3.1", "symfony/console": "^3.1",
"clue/graph": "^0.9", "clue/graph": "^0.9",
"graphp/graphviz": "^0.2" "graphp/graphviz": "^0.2"
}, },
"require-dev": { "require-dev": {
"crysalead/kahlan": "^2.5.4", "crysalead/kahlan": "^2.5.4",
"friendsofphp/php-cs-fixer": "^1.11" "friendsofphp/php-cs-fixer": "^2"
}, },
"license": "MIT", "license": "MIT",
"authors": [ "authors": [

731
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -26,7 +26,7 @@ $application->register('render')
->setCode(function (Console\Input\InputInterface $input, Console\Output\OutputInterface $output) { ->setCode(function (Console\Input\InputInterface $input, Console\Output\OutputInterface $output) {
$backgroundColor = $input->getOption('background'); $backgroundColor = $input->getOption('background');
if (preg_match('/^#[a-fA-F0-9]{6}|transparent$/', $backgroundColor) === 0) { if (0 === preg_match('/^#[a-fA-F0-9]{6}|transparent$/', $backgroundColor)) {
throw new Console\Exception\InvalidArgumentException(sprintf('Invalid background color "%s". It must be a valid hex color or "transparent".', $backgroundColor)); throw new Console\Exception\InvalidArgumentException(sprintf('Invalid background color "%s". It must be a valid hex color or "transparent".', $backgroundColor));
} }
@ -36,19 +36,19 @@ $application->register('render')
$overrideFile = dirname($inputFile).DIRECTORY_SEPARATOR.basename($inputFile, '.'.$inputFileExtension).'.'.$input->getOption('override').'.'.$inputFileExtension; $overrideFile = dirname($inputFile).DIRECTORY_SEPARATOR.basename($inputFile, '.'.$inputFileExtension).'.'.$input->getOption('override').'.'.$inputFileExtension;
$outputFormat = $input->getOption('output-format'); $outputFormat = $input->getOption('output-format');
$outputFile = $input->getOption('output-file') ?: getcwd().DIRECTORY_SEPARATOR.'docker-compose.'.($outputFormat === 'dot' ? $outputFormat : 'png'); $outputFile = $input->getOption('output-file') ?: getcwd().DIRECTORY_SEPARATOR.'docker-compose.'.('dot' === $outputFormat ? $outputFormat : 'png');
$onlyServices = $input->getOption('only'); $onlyServices = $input->getOption('only');
if (in_array($outputFormat, ['dot', 'image', 'display']) === false) { if (false === in_array($outputFormat, ['dot', 'image', 'display'])) {
throw new Console\Exception\InvalidArgumentException(sprintf('Invalid output format "%s". It must be one of "dot", "image" or "display".', $outputFormat)); throw new Console\Exception\InvalidArgumentException(sprintf('Invalid output format "%s". It must be one of "dot", "image" or "display".', $outputFormat));
} }
if ($outputFormat === 'display') { if ('display' === $outputFormat) {
if ($input->getOption('force') || $input->getOption('output-file')) { if ($input->getOption('force') || $input->getOption('output-file')) {
$output->writeln('<comment>The following options are ignored with the "display" output format: "--force", "--output-file"</comment>'); $output->writeln('<comment>The following options are ignored with the "display" output format: "--force", "--output-file"</comment>');
} }
} else { } else {
if (file_exists($outputFile) === true && $input->getOption('force') === false) { if (true === file_exists($outputFile) && false === $input->getOption('force')) {
throw new Console\Exception\InvalidArgumentException(sprintf('File "%s" already exists. Use the "--force" option to overwrite it.', $outputFile)); throw new Console\Exception\InvalidArgumentException(sprintf('File "%s" already exists. Use the "--force" option to overwrite it.', $outputFile));
} }
} }
@ -103,19 +103,19 @@ $application->register('render')
} }
$flags = 0; $flags = 0;
if ($input->getOption('no-volumes') === true) { if (true === $input->getOption('no-volumes')) {
$logger('<comment>Volumes</comment> will not be displayed'); $logger('<comment>Volumes</comment> will not be displayed');
$flags |= WITHOUT_VOLUMES; $flags |= WITHOUT_VOLUMES;
} }
if ($input->getOption('no-networks') === true) { if (true === $input->getOption('no-networks')) {
$logger('<comment>Networks</comment> will not be displayed'); $logger('<comment>Networks</comment> will not be displayed');
$flags |= WITHOUT_NETWORKS; $flags |= WITHOUT_NETWORKS;
} }
if ($input->getOption('no-ports') === true) { if (true === $input->getOption('no-ports')) {
$logger('<comment>Ports</comment> will not be displayed'); $logger('<comment>Ports</comment> will not be displayed');
$flags |= WITHOUT_PORTS; $flags |= WITHOUT_PORTS;

View file

@ -20,7 +20,7 @@ const WITHOUT_PORTS = 4;
* *
* @return callable * @return callable
*/ */
function logger(OutputInterface $output) : callable function logger(OutputInterface $output): callable
{ {
return function (string $message, int $verbosity = null) use ($output) { return function (string $message, int $verbosity = null) use ($output) {
$output->writeln(sprintf('[%s] %s', date(DATE_ISO8601), $message), $verbosity ?: OutputInterface::VERBOSITY_VERBOSE); $output->writeln(sprintf('[%s] %s', date(DATE_ISO8601), $message), $verbosity ?: OutputInterface::VERBOSITY_VERBOSE);
@ -34,9 +34,9 @@ function logger(OutputInterface $output) : callable
* *
* @return array * @return array
*/ */
function readConfiguration(string $path) : array function readConfiguration(string $path): array
{ {
if (file_exists($path) === false) { if (false === file_exists($path)) {
throw new \InvalidArgumentException(sprintf('File "%s" does not exist', $path)); throw new \InvalidArgumentException(sprintf('File "%s" does not exist', $path));
} }
@ -54,9 +54,9 @@ function readConfiguration(string $path) : array
* *
* @return array List of service definitions exctracted from the configuration * @return array List of service definitions exctracted from the configuration
*/ */
function fetchServices(array $configuration) : array function fetchServices(array $configuration): array
{ {
if (isset($configuration['version']) === false || (int) $configuration['version'] === 1) { if (false === isset($configuration['version']) || 1 === (int) $configuration['version']) {
return $configuration; return $configuration;
} }
@ -70,9 +70,9 @@ function fetchServices(array $configuration) : array
* *
* @return array List of service definitions exctracted from the configuration * @return array List of service definitions exctracted from the configuration
*/ */
function fetchVolumes(array $configuration) : array function fetchVolumes(array $configuration): array
{ {
if (isset($configuration['version']) === false || (int) $configuration['version'] === 1) { if (false === isset($configuration['version']) || 1 === (int) $configuration['version']) {
return []; return [];
} }
@ -86,9 +86,9 @@ function fetchVolumes(array $configuration) : array
* *
* @return array List of service definitions exctracted from the configuration * @return array List of service definitions exctracted from the configuration
*/ */
function fetchNetworks(array $configuration) : array function fetchNetworks(array $configuration): array
{ {
if (isset($configuration['version']) === false || (int) $configuration['version'] === 1) { if (false === isset($configuration['version']) || 1 === (int) $configuration['version']) {
return []; return [];
} }
@ -106,7 +106,7 @@ function fetchNetworks(array $configuration) : array
* *
* @return Graph The complete graph for the given list of services * @return Graph The complete graph for the given list of services
*/ */
function createGraph(array $services, array $volumes, array $networks, string $path, int $flags) : Graph function createGraph(array $services, array $volumes, array $networks, string $path, int $flags): Graph
{ {
return makeVerticesAndEdges(new Graph(), $services, $volumes, $networks, $path, $flags); return makeVerticesAndEdges(new Graph(), $services, $volumes, $networks, $path, $flags);
} }
@ -120,14 +120,14 @@ function createGraph(array $services, array $volumes, array $networks, string $p
* *
* @return Graph A copy of the input graph with style attributes * @return Graph A copy of the input graph with style attributes
*/ */
function applyGraphvizStyle(Graph $graph, bool $horizontal, string $background) : Graph function applyGraphvizStyle(Graph $graph, bool $horizontal, string $background): Graph
{ {
$graph = $graph->createGraphClone(); $graph = $graph->createGraphClone();
$graph->setAttribute('graphviz.graph.bgcolor', $background); $graph->setAttribute('graphviz.graph.bgcolor', $background);
$graph->setAttribute('graphviz.graph.pad', '0.5'); $graph->setAttribute('graphviz.graph.pad', '0.5');
$graph->setAttribute('graphviz.graph.ratio', 'fill'); $graph->setAttribute('graphviz.graph.ratio', 'fill');
if ($horizontal === true) { if (true === $horizontal) {
$graph->setAttribute('graphviz.graph.rankdir', 'LR'); $graph->setAttribute('graphviz.graph.rankdir', 'LR');
} }
@ -158,7 +158,7 @@ function applyGraphvizStyle(Graph $graph, bool $horizontal, string $background)
case 'port': case 'port':
$vertex->setAttribute('graphviz.shape', 'circle'); $vertex->setAttribute('graphviz.shape', 'circle');
if (($proto = $vertex->getAttribute('docker_compose.proto')) === 'udp') { if ('udp' === ($proto = $vertex->getAttribute('docker_compose.proto'))) {
$vertex->setAttribute('graphviz.style', 'dashed'); $vertex->setAttribute('graphviz.style', 'dashed');
} }
break; break;
@ -193,10 +193,10 @@ function applyGraphvizStyle(Graph $graph, bool $horizontal, string $background)
break; break;
} }
if (($alias = $edge->getAttribute('docker_compose.alias')) !== null) { if (null !== ($alias = $edge->getAttribute('docker_compose.alias'))) {
$edge->setAttribute('graphviz.label', $alias); $edge->setAttribute('graphviz.label', $alias);
if ($edge->getAttribute('docker_compose.condition') !== null) { if (null !== $edge->getAttribute('docker_compose.condition')) {
$edge->setAttribute('graphviz.fontsize', '10'); $edge->setAttribute('graphviz.fontsize', '10');
} }
} }
@ -220,19 +220,19 @@ function applyGraphvizStyle(Graph $graph, bool $horizontal, string $background)
* *
* @return Graph A copy of the input graph with vertices and edges for services * @return Graph A copy of the input graph with vertices and edges for services
*/ */
function makeVerticesAndEdges(Graph $graph, array $services, array $volumes, array $networks, string $path, int $flags) : Graph function makeVerticesAndEdges(Graph $graph, array $services, array $volumes, array $networks, string $path, int $flags): Graph
{ {
if (((bool) ($flags & WITHOUT_VOLUMES)) === false) { if (false === ((bool) ($flags & WITHOUT_VOLUMES))) {
foreach (array_keys($volumes) as $volume) { foreach (array_keys($volumes) as $volume) {
addVolume($graph, 'named: '.$volume); addVolume($graph, 'named: '.$volume);
} }
} }
if (((bool) ($flags & WITHOUT_NETWORKS)) === false) { if (false === ((bool) ($flags & WITHOUT_NETWORKS))) {
foreach ($networks as $network => $definition) { foreach ($networks as $network => $definition) {
addNetwork( addNetwork(
$graph, 'net: '.$network, $graph, 'net: '.$network,
isset($definition['external']) && $definition['external'] === true ? 'external_network' : 'network' isset($definition['external']) && true === $definition['external'] ? 'external_network' : 'network'
); );
} }
} }
@ -302,7 +302,7 @@ function makeVerticesAndEdges(Graph $graph, array $services, array $volumes, arr
); );
} }
if (((bool) ($flags & WITHOUT_VOLUMES)) === false) { if (false === ((bool) ($flags & WITHOUT_VOLUMES))) {
$serviceVolumes = []; $serviceVolumes = [];
foreach ($definition['volumes'] ?? [] as $volume) { foreach ($definition['volumes'] ?? [] as $volume) {
@ -314,7 +314,7 @@ function makeVerticesAndEdges(Graph $graph, array $services, array $volumes, arr
foreach ($serviceVolumes as $container => $volume) { foreach ($serviceVolumes as $container => $volume) {
list($host, $attr) = $volume; list($host, $attr) = $volume;
if ($host[0] !== '.' && $host[0] !== DIRECTORY_SEPARATOR) { if ('.' !== $host[0] && DIRECTORY_SEPARATOR !== $host[0]) {
$host = 'named: '.$host; $host = 'named: '.$host;
} }
@ -323,12 +323,12 @@ function makeVerticesAndEdges(Graph $graph, array $services, array $volumes, arr
$graph->getVertex($service), $graph->getVertex($service),
'volumes', 'volumes',
$host !== $container ? $container : null, $host !== $container ? $container : null,
$attr !== 'ro' 'ro' !== $attr
); );
} }
} }
if (((bool) ($flags & WITHOUT_PORTS)) === false) { if (false === ((bool) ($flags & WITHOUT_PORTS))) {
foreach ($definition['ports'] ?? [] as $port) { foreach ($definition['ports'] ?? [] as $port) {
list($host, $container, $proto) = explodeMapping($port); list($host, $container, $proto) = explodeMapping($port);
@ -341,7 +341,7 @@ function makeVerticesAndEdges(Graph $graph, array $services, array $volumes, arr
} }
} }
if (((bool) ($flags & WITHOUT_NETWORKS)) === false) { if (false === ((bool) ($flags & WITHOUT_NETWORKS))) {
foreach ($definition['networks'] ?? [] as $network => $config) { foreach ($definition['networks'] ?? [] as $network => $config) {
$network = is_int($network) ? $config : $network; $network = is_int($network) ? $config : $network;
$config = is_int($network) ? [] : $config; $config = is_int($network) ? [] : $config;
@ -371,7 +371,7 @@ function makeVerticesAndEdges(Graph $graph, array $services, array $volumes, arr
*/ */
function addService(Graph $graph, string $service, string $type = null) function addService(Graph $graph, string $service, string $type = null)
{ {
if ($graph->hasVertex($service) === true) { if (true === $graph->hasVertex($service)) {
return $graph->getVertex($service); return $graph->getVertex($service);
} }
@ -392,7 +392,7 @@ function addService(Graph $graph, string $service, string $type = null)
*/ */
function addPort(Graph $graph, int $port, string $proto = null) function addPort(Graph $graph, int $port, string $proto = null)
{ {
if ($graph->hasVertex($port) === true) { if (true === $graph->hasVertex($port)) {
return $graph->getVertex($port); return $graph->getVertex($port);
} }
@ -413,7 +413,7 @@ function addPort(Graph $graph, int $port, string $proto = null)
*/ */
function addVolume(Graph $graph, string $path) function addVolume(Graph $graph, string $path)
{ {
if ($graph->hasVertex($path) === true) { if (true === $graph->hasVertex($path)) {
return $graph->getVertex($path); return $graph->getVertex($path);
} }
@ -434,7 +434,7 @@ function addVolume(Graph $graph, string $path)
*/ */
function addNetwork(Graph $graph, string $name, string $type = null) function addNetwork(Graph $graph, string $name, string $type = null)
{ {
if ($graph->hasVertex($name) === true) { if (true === $graph->hasVertex($name)) {
return $graph->getVertex($name); return $graph->getVertex($name);
} }
@ -456,7 +456,7 @@ function addNetwork(Graph $graph, string $name, string $type = null)
* *
* @return Edge\Directed * @return Edge\Directed
*/ */
function addRelation(Vertex $from, Vertex $to, string $type, string $alias = null, bool $bidirectional = false, bool $condition = false) : Edge\Directed function addRelation(Vertex $from, Vertex $to, string $type, string $alias = null, bool $bidirectional = false, bool $condition = false): Edge\Directed
{ {
$edge = null; $edge = null;
@ -476,7 +476,7 @@ function addRelation(Vertex $from, Vertex $to, string $type, string $alias = nul
$edge->setAttribute('docker_compose.type', $type); $edge->setAttribute('docker_compose.type', $type);
if ($alias !== null) { if (null !== $alias) {
$edge->setAttribute('docker_compose.alias', $alias); $edge->setAttribute('docker_compose.alias', $alias);
} }
@ -497,7 +497,7 @@ function addRelation(Vertex $from, Vertex $to, string $type, string $alias = nul
* @return array An 2 items array containing the parts of the mapping. * @return array An 2 items array containing the parts of the mapping.
* If the mapping does not specify a second part, the first one will be repeated * If the mapping does not specify a second part, the first one will be repeated
*/ */
function explodeMapping($mapping) : array function explodeMapping($mapping): array
{ {
$parts = explode(':', $mapping); $parts = explode(':', $mapping);
$parts[1] = $parts[1] ?? $parts[0]; $parts[1] = $parts[1] ?? $parts[0];