Completed
Push — master ( 5017d8...561e2a )
by Christian
07:36 queued 03:33
created

DiCommand::execute()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 39
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 39
rs 8.439
cc 5
eloc 23
nc 6
nop 2
1
<?php
2
3
namespace N98\Magento\Command\Config\Data;
4
5
use Magento\Framework\ObjectManager\ConfigLoaderInterface;
6
use N98\Magento\Command\AbstractMagentoCommand;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Input\InputOption;
10
use Symfony\Component\Console\Output\OutputInterface;
11
use Symfony\Component\VarDumper\Cloner\VarCloner;
12
use Symfony\Component\VarDumper\Dumper\CliDumper;
13
14
class DiCommand extends AbstractMagentoCommand
15
{
16
    /**
17
     * @var \Magento\Framework\App\ProductMetadataInterface
18
     */
19
    private $productMetadata;
0 ignored issues
show
Unused Code introduced by
The property $productMetadata is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
20
21
    protected function configure()
22
    {
23
        $this
24
            ->setName('config:data:di')
25
            ->addArgument('type', InputArgument::OPTIONAL, 'Type (class)')
26
            ->addOption(
27
                'scope',
28
                's',
29
                InputOption::VALUE_OPTIONAL,
30
                'Config scope (global, adminhtml, frontend, webapi_rest, webapi_soap, ...)',
31
                'global'
32
            )
33
            ->setDescription('Dump dependency injection config')
34
        ;
35
    }
36
37
    /**
38
     * @param \Symfony\Component\Console\Input\InputInterface   $input
39
     * @param \Symfony\Component\Console\Output\OutputInterface $output
40
     *
41
     * @return int|void
42
     */
43
    protected function execute(InputInterface $input, OutputInterface $output)
44
    {
45
        $this->detectMagento($output, true);
46
47
        if (!$this->initMagento()) {
48
            return;
49
        }
50
51
        /** @var ConfigLoaderInterface $configLoader */
52
        $configLoader = $this->getObjectManager()->get(ConfigLoaderInterface::class);
53
        $configDataPrimary = $configLoader->load('primary');
54
        $configDataScope = $configLoader->load($input->getOption('scope'));
55
56
        $configData = array_merge_recursive($configDataPrimary, $configDataScope);
57
58
        $cloner = new VarCloner();
59
        $cloner->setMaxItems(-1);
60
        $cloner->setMaxString(-1);
61
        $dumper = new CliDumper();
62
63
        if ($input->getArgument('type')) {
64
            $config = [];
65
66
            $normalizedKey = ltrim($input->getArgument('type'), '\\');
67
            if (isset($configData[$normalizedKey])) {
68
                $config[$normalizedKey] = $configData[$normalizedKey];
69
            }
70
71
            if (isset($configData['preferences'][$normalizedKey])) {
72
                $config['preferences'] = $configData['preferences'][$normalizedKey];
73
            }
74
        } else {
75
            $config = $configData;
76
        }
77
78
        $dumpContent = $dumper->dump($cloner->cloneVar($config), true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a callable|resource|null.

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...
79
80
        $output->write($dumpContent);
81
    }
82
}
83