Completed
Push — ezp_30463_solr_cloud ( e5cf94...9860cc )
by
unknown
23:28
created

DebugConfigResolverCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 7

Importance

Changes 0
Metric Value
dl 0
loc 98
rs 10
c 0
b 0
f 0
wmc 4
lcom 2
cbo 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A configure() 0 42 1
A execute() 0 26 2
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
namespace eZ\Bundle\EzPublishCoreBundle\Command;
8
9
use eZ\Publish\Core\MVC\ConfigResolverInterface;
10
use eZ\Publish\Core\MVC\Symfony\SiteAccess;
11
use Symfony\Component\Console\Command\Command;
12
use Symfony\Component\Console\Input\InputArgument;
13
use Symfony\Component\Console\Input\InputInterface;
14
use Symfony\Component\Console\Input\InputOption;
15
use Symfony\Component\Console\Output\OutputInterface;
16
use Symfony\Component\VarDumper\Cloner\VarCloner;
17
use Symfony\Component\VarDumper\Dumper\CliDumper;
18
19
class DebugConfigResolverCommand extends Command
20
{
21
    /**
22
     * @var \eZ\Publish\Core\MVC\ConfigResolverInterface
23
     */
24
    private $configResolver;
25
26
    /**
27
     * @var \eZ\Publish\Core\MVC\Symfony\SiteAccess
28
     */
29
    private $siteAccess;
30
31
    public function __construct(
32
        ConfigResolverInterface $configResolver,
33
        SiteAccess $siteAccess
34
    ) {
35
        $this->configResolver = $configResolver;
36
        $this->siteAccess = $siteAccess;
37
38
        parent::__construct();
39
    }
40
41
    /**
42
     * {@inheritdoc}.
43
     */
44
    public function configure()
45
    {
46
        $this->setName('ezplatform:debug:config-resolver');
47
        $this->setAliases(['ezplatform:debug:config']);
48
        $this->setDescription('Debug / Retrive parameter from Config Resolver');
49
        $this->addArgument(
50
            'parameter',
51
            InputArgument::REQUIRED,
52
            'The configuration resolver parameter to return, for instance "languages" or "http_cache.purge_servers"'
53
        );
54
        $this->addOption(
55
            'json',
56
            null,
57
            InputOption::VALUE_NONE,
58
            'Only return value, for automation / testing use on a single line in json format.'
59
        );
60
        $this->addOption(
61
            'scope',
62
            null,
63
            InputOption::VALUE_REQUIRED,
64
            'Set another scope (siteaccess) to use, alternative to using the global --siteaccess[=SITEACCESS] option.'
65
        );
66
        $this->addOption(
67
            'namespace',
68
            null,
69
            InputOption::VALUE_REQUIRED,
70
            'Set another namespace than default "ezsettings" used by siteaccess settings.'
71
        );
72
        $this->setHelp(<<<EOM
73
Outputs a given config resolver parameter, more commonly known as a SiteAccess setting.
74
75
By default it will give value depending on global <comment>--siteaccess[=SITEACCESS]</comment> (default siteaccess is used if not set).
76
77
However you can also manually set <comment>--scope[=NAME]</comment> yourself if you don't want to affect the siteaccess
78
set by the system. You can also override namespace to get something else than default "ezsettings" namespace using
79
<comment>--namespace[=NS]</comment> option.
80
81
NOTE: To rather see *all* compiled siteaccess settings, use: <comment>debug:config ezpublish [system.default]</comment>
82
83
EOM
84
        );
85
    }
86
87
    /**
88
     * {@inheritdoc}.
89
     */
90
    protected function execute(InputInterface $input, OutputInterface $output)
91
    {
92
        $parameter = $input->getArgument('parameter');
93
        $namespace = $input->getOption('namespace');
94
        $scope = $input->getOption('scope');
95
        $parameterData = $this->configResolver->getParameter($parameter, $namespace, $scope);
0 ignored issues
show
Bug introduced by
It seems like $parameter defined by $input->getArgument('parameter') on line 92 can also be of type array<integer,string> or null; however, eZ\Publish\Core\MVC\Conf...terface::getParameter() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
96
97
        // In case of json output return early with no newlines and only the parameter data
98
        if ($input->getOption('json')) {
99
            $output->write(json_encode($parameterData));
100
101
            return;
102
        }
103
104
        $output->writeln('<comment>SiteAccess name:</comment> ' . $this->siteAccess->name);
105
106
        $output->writeln('<comment>Parameter:</comment>');
107
        $cloner = new VarCloner();
108
        $dumper = new CliDumper();
109
        $output->write(
110
            $dumper->dump(
111
                $cloner->cloneVar($parameterData),
112
                true
113
            )
114
        );
115
    }
116
}
117