ExportSettingsCommand::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 2
1
<?php declare(strict_types=1);
2
3
namespace ShopwareEnvironmentVariables\Source\Commands;
4
5
use Doctrine\DBAL\Connection;
0 ignored issues
show
Bug introduced by
The type Doctrine\DBAL\Connection was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Shopware\Components\Plugin\ConfigReader;
0 ignored issues
show
Bug introduced by
The type Shopware\Components\Plugin\ConfigReader was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Symfony\Component\Console\Command\Command;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Command\Command was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Symfony\Component\Console\Input\InputInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Input\InputInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Symfony\Component\Console\Output\OutputInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Output\OutputInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
11
class ExportSettingsCommand extends Command
12
{
13
    /**
14
     * @var ConfigReader
15
     */
16
    private $configReader;
17
18
    /**
19
     * @var Connection
20
     */
21
    private $connection;
22
23
    public function __construct(ConfigReader $configReader, Connection $connection)
24
    {
25
        parent::__construct();
26
        $this->configReader = $configReader;
27
        $this->connection = $connection;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    protected function configure()
34
    {
35
        $this->setName('shopware-blog:export:settings');
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    protected function execute(InputInterface $input, OutputInterface $output)
42
    {
43
        $plugins = $this->connection
44
            ->fetchAll(
45
                'SELECT name FROM s_core_plugins
46
                           WHERE name != \'PluginManager\' 
47
                           AND capability_enable = 1'
48
            );
49
        $shopIds = $this->connection
50
            ->fetchAll('SELECT id FROM s_core_shops');
51
52
        $config = [];
53
        foreach ($plugins as $plugin) {
54
            foreach ($shopIds as $shopId) {
55
                $pluginConfig = $this->configReader->getByPluginName($plugin['name']);
56
                if ($pluginConfig) {
57
                    $config['plugins'][(int) $shopId['id']][$plugin['name']] = $pluginConfig;
58
                }
59
            }
60
        }
61
62
        file_put_contents(
63
            __DIR__ . '/../../plugins_config.php',
64
            '<?php' . "\n\n" . var_export($config, true) . ';',
65
            LOCK_EX
66
        );
67
    }
68
}
69