Completed
Push — 4.0 ( 268f2c...88f012 )
by Hideki
05:48 queued 10s
created

src/Eccube/Command/UpdateSchemaDoctrineCommand.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Eccube\Command;
4
5
use Doctrine\Bundle\DoctrineBundle\Command\Proxy\DoctrineCommandHelper;
6
use Doctrine\Bundle\DoctrineBundle\Command\Proxy\UpdateSchemaDoctrineCommand as BaseUpdateSchemaDoctrineCommand;
7
use Doctrine\Common\Annotations\AnnotationReader;
8
use Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand;
9
use Doctrine\ORM\Tools\SchemaTool;
10
use Eccube\Doctrine\ORM\Mapping\Driver\ReloadSafeAnnotationDriver;
11
use Eccube\Repository\PluginRepository;
12
use Eccube\Service\PluginService;
13
use Eccube\Service\SchemaService;
14
use Eccube\Util\StringUtil;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Input\InputOption;
17
use Symfony\Component\Console\Output\OutputInterface;
18
use Symfony\Component\Console\Style\SymfonyStyle;
19
use Symfony\Component\Finder\Finder;
20
use Symfony\Component\Filesystem\Filesystem;
21
22
/**
23
 * Command to generate the SQL needed to update the database schema to match
24
 * the current mapping information.
25
 */
26
class UpdateSchemaDoctrineCommand extends BaseUpdateSchemaDoctrineCommand
27
{
28
    /**
29
     * @var PluginRepository
30
     */
31
    protected $pluginRepository;
32
33
    /**
34
     * @var PluginService
35
     */
36
    protected $pluginService;
37
38
    /**
39
     * @var SchemaService
40
     */
41
    protected $schemaService;
42
43
    public function __construct(
44
        PluginRepository $pluginRepository,
45
        PluginService $pluginService,
46
        SchemaService $schemaService
47
    ) {
48
        parent::__construct();
49
        $this->pluginRepository = $pluginRepository;
50
        $this->pluginService = $pluginService;
51
        $this->schemaService = $schemaService;
52
    }
53
54
    /**
55
     * {@inheritDoc}
56
     */
57
    protected function configure()
58
    {
59
        parent::configure();
60
61
        $this
62
            ->setName('eccube:schema:update')
63
            ->setAliases(['doctrine:schema:update'])
64
            ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command')
65
            ->addOption('no-proxy', null, InputOption::VALUE_NONE, 'Does not use the proxy class and behaves the same as the original doctrine:schema:update command');
66
    }
67
68
    /**
69
     * {@inheritDoc}
70
     */
71
    protected function execute(InputInterface $input, OutputInterface $output)
72
    {
73
        DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
0 ignored issues
show
$this->getApplication() is of type object<Symfony\Component...nsole\Application>|null, but the function expects a object<Symfony\Bundle\Fr...le\Console\Application>.

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...
74
        $noProxy = true === $input->getOption('no-proxy');
75
        $dumpSql = true === $input->getOption('dump-sql');
76
        $force = true === $input->getOption('force');
77
78
        if ($noProxy || $dumpSql === false && $force === false) {
79
            return parent::execute($input, $output);
80
        }
81
82
        $tmpProxyOutputDir = sys_get_temp_dir().'/proxy_'.StringUtil::random(12);
83
        $tmpMetaDataOutputDir = sys_get_temp_dir().'/metadata_'.StringUtil::random(12);
84
85
        $generateAllFiles = [];
86
        try {
87
            // Generate proxy files of plugins
88
            $Plugins = $this->pluginRepository->findAll();
89
            foreach ($Plugins as $Plugin) {
90
                $config = ['code' => $Plugin->getCode()];
91
                $this->pluginService->generateProxyAndCallback(function ($generateFiles) use (&$generateAllFiles) {
92
                    $generateAllFiles = array_merge($generateAllFiles, $generateFiles);
93
                }, $Plugin, $config, false, $tmpProxyOutputDir);
94
            }
95
96
            $result = null;
97
            $command = $this;
98
99
            // Generate Doctrine metadata and execute schema command
100
            $this->schemaService->executeCallback(function (SchemaTool $schemaTool, array $metaData) use ($command, $input, $output, &$result) {
101
                $ui = new SymfonyStyle($input, $output);
102
                if (empty($metaData)) {
103
                    $ui->success('No Metadata Classes to process.');
104
                    $result = 0;
105
                } else {
106
                    $result = $command->executeSchemaCommand($input, $output, $schemaTool, $metaData, $ui);
107
                }
108
            }, $generateAllFiles, $tmpProxyOutputDir, $tmpMetaDataOutputDir);
109
110
            return $result;
111
        } finally {
112
            $this->removeOutputDir($tmpMetaDataOutputDir);
113
            $this->removeOutputDir($tmpProxyOutputDir);
114
        }
115
    }
116
117
    protected function removeOutputDir($outputDir)
118
    {
119
        if (file_exists($outputDir)) {
120
            $files = Finder::create()
121
                ->in($outputDir)
122
                ->files();
123
            $f = new Filesystem();
124
            $f->remove($files);
0 ignored issues
show
$files is of type object<Symfony\Component\Finder\Finder>, but the function expects a string|object<Symfony\Co...nt\Filesystem\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...
125
        }
126
    }
127
}
128