Completed
Push — 3.x ( 1cd1d0...b03505 )
by Grégoire
16:27 queued 03:11
created

CreateClassCacheCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 33 and the first side effect is on line 21.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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(
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 '.__NAMESPACE__.'\CreateClassCacheCommand class is deprecated since version 3.39.0 and will be removed in 4.0.',
23
    E_USER_DEPRECATED
24
);
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
    /**
36
     * {@inheritdoc}
37
     */
38
    protected static $defaultName = 'cache:create-cache-class';
39
40
    /**
41
     * @var string
42
     */
43
    private $cacheDir;
44
45
    /**
46
     * @var bool
47
     */
48
    private $debug;
49
50
    public function __construct(string $cacheDir, bool $debug)
51
    {
52
        $this->cacheDir = $cacheDir;
53
        $this->debug = $debug;
54
55
        parent::__construct();
56
    }
57
58
    public function configure()
59
    {
60
        $this->setDescription('Generate the classes.php files');
61
    }
62
63
    public function execute(InputInterface $input, OutputInterface $output)
64
    {
65
        $classmap = $this->cacheDir.'/classes.map';
66
67
        if (!is_file($classmap)) {
68
            throw new \RuntimeException(sprintf('The file %s does not exist', $classmap));
69
        }
70
71
        $name = 'classes';
72
        $extension = '.php';
73
74
        $output->write('<info>Writing cache file ...</info>');
75
        ClassCollectionLoader::load(
76
            include($classmap),
77
            $this->cacheDir,
78
            $name,
79
            $this->debug,
80
            false,
81
            $extension
82
        );
83
84
        $output->writeln(' done!');
85
    }
86
}
87