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

ListAliases::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 36
rs 9.344
c 0
b 0
f 0
cc 2
nc 2
nop 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
     * List migration template creation aliases.
53
     *
54
     * {@inheritdoc}
55
     */
56
    protected function execute(InputInterface $input, OutputInterface $output)
57
    {
58
        $this->bootstrap($input, $output);
59
60
        $aliases = $this->config->getAliases();
61
62
        if ($aliases) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $aliases of type string[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
63
            $maxAliasLength = max(array_map('strlen', array_keys($aliases)));
64
            $maxClassLength = max(array_map('strlen', $aliases));
65
            $output->writeln(
66
                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...
67
                    [
68
                        '',
69
                        sprintf('%s %s', str_pad('Alias', $maxAliasLength), str_pad('Class', $maxClassLength)),
70
                        sprintf('%s %s', str_repeat('=', $maxAliasLength), str_repeat('=', $maxClassLength)),
71
                    ],
72
                    array_map(
73
                        function ($alias, $class) use ($maxAliasLength, $maxClassLength) {
74
                            return sprintf('%s %s', str_pad($alias, $maxAliasLength), str_pad($class, $maxClassLength));
75
                        },
76
                        array_keys($aliases),
77
                        $aliases
78
                    )
79
                )
80
            );
81
        } else {
82
            $output->writeln(
83
                sprintf(
84
                    '<error>No aliases defined in %s</error>',
85
                    str_replace(getcwd(), '', realpath($this->config->getConfigFilePath()))
86
                )
87
            );
88
        }
89
90
        return 0;
91
    }
92
}
93