Completed
Pull Request — master (#1642)
by Richard
01:48
created

ListAliases   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 60
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 7 1
A execute() 0 36 2
1
<?php
2
/**
3
 * Phinx
4
 *
5
 * (The MIT license)
6
 * Copyright (c) 2015 Rob Morgan
7
 *
8
 * Permission is hereby granted, free of charge, to any person obtaining a copy
9
 * of this software and associated * documentation files (the "Software"), to
10
 * deal in the Software without restriction, including without limitation the
11
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12
 * sell copies of the Software, and to permit persons to whom the Software is
13
 * furnished to do so, subject to the following conditions:
14
 *
15
 * The above copyright notice and this permission notice shall be included in
16
 * all copies or substantial portions of the Software.
17
 *
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24
 * IN THE SOFTWARE.
25
 *
26
 * @author     Richard Quadling
27
 * @package    Phinx
28
 * @subpackage Phinx\Console
29
 */
30
31
namespace Phinx\Console\Command;
32
33
use Symfony\Component\Console\Input\InputInterface;
34
use Symfony\Component\Console\Output\OutputInterface;
35
36
class ListAliases extends AbstractCommand
37
{
38
    protected static $defaultName = 'list:aliases';
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    protected function configure()
44
    {
45
        parent::configure();
46
47
        $this->setDescription('List template class aliases')
48
            ->setHelp('The <info>list:aliases</info> command lists the migration template generation class aliases');
49
    }
50
51
    /**
52
     * Toggle the breakpoint.
53
     *
54
     * @param InputInterface $input
55
     * @param OutputInterface $output
56
     *
57
     * @return int integer 0 on success, or an error code.
58
     */
59
    protected function execute(InputInterface $input, OutputInterface $output)
60
    {
61
        $this->bootstrap($input, $output);
62
63
        $aliases = $this->config->getAliases();
64
65
        if ($aliases) {
66
            $maxAliasLength = max(array_map('strlen', array_keys($aliases)));
67
            $maxClassLength = max(array_map('strlen', $aliases));
68
            $output->writeln(
69
                array_merge(
0 ignored issues
show
Documentation introduced by
array_merge(array('', sp...s($aliases), $aliases)) is of type array, but the function expects a string|object<Symfony\Co...onsole\Output\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
70
                    [
71
                        '',
72
                        sprintf('%s %s', str_pad('Alias', $maxAliasLength), str_pad('Class', $maxClassLength)),
73
                        sprintf('%s %s', str_repeat('=', $maxAliasLength), str_repeat('=', $maxClassLength)),
74
                    ],
75
                    array_map(
76
                        function ($alias, $class) use ($maxAliasLength, $maxClassLength) {
77
                            return sprintf('%s %s', str_pad($alias, $maxAliasLength), str_pad($class, $maxClassLength));
78
                        },
79
                        array_keys($aliases),
80
                        $aliases
81
                    )
82
                )
83
            );
84
        } else {
85
            $output->writeln(
86
                sprintf(
87
                    '<error>No aliases defined in %s</error>',
88
                    str_replace(getcwd(), '', realpath($this->config->getConfigFilePath()))
89
                )
90
            );
91
        }
92
93
        return 0;
94
    }
95
}
96