Completed
Pull Request — master (#6194)
by Vincent
05:04
created

CreateClassCacheCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 9.52
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\AdminBundle\Command;
15
16
use Symfony\Component\ClassLoader\ClassCollectionLoader;
17
use Symfony\Component\Console\Command\Command;
18
use Symfony\Component\Console\Input\InputInterface;
19
use Symfony\Component\Console\Output\OutputInterface;
20
21
@trigger_error(sprintf(
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
22
    'The %s\CreateClassCacheCommand class is deprecated since version 3.39.0 and will be removed in 4.0.',
23
    __NAMESPACE__
24
), E_USER_DEPRECATED);
25
26
/**
27
 * NEXT_MAJOR: Remove this class.
28
 *
29
 * @deprecated since version sonata-project/admin-bundle 3.39.0 and will be removed in 4.0.
30
 *
31
 * @author Thomas Rabaix <[email protected]>
32
 */
33
class CreateClassCacheCommand extends Command
34
{
35
    protected static $defaultName = 'cache:create-cache-class';
36
37
    /**
38
     * @var string
39
     */
40
    private $cacheDir;
41
42
    /**
43
     * @var bool
44
     */
45
    private $debug;
46
47
    public function __construct(string $cacheDir, bool $debug)
48
    {
49
        $this->cacheDir = $cacheDir;
50
        $this->debug = $debug;
51
52
        parent::__construct();
53
    }
54
55
    public function configure()
56
    {
57
        $this->setDescription('Generate the classes.php files');
58
    }
59
60
    public function execute(InputInterface $input, OutputInterface $output)
61
    {
62
        $classmap = $this->cacheDir.'/classes.map';
63
64
        if (!is_file($classmap)) {
65
            throw new \RuntimeException(sprintf('The file %s does not exist', $classmap));
66
        }
67
68
        $name = 'classes';
69
        $extension = '.php';
70
71
        $output->write('<info>Writing cache file ...</info>');
72
        ClassCollectionLoader::load(
73
            include($classmap),
74
            $this->cacheDir,
75
            $name,
76
            $this->debug,
77
            false,
78
            $extension
79
        );
80
81
        $output->writeln(' done!');
82
83
        return 0;
84
    }
85
}
86