Completed
Push — 6.0 ( eb641c...92cb73 )
by Ruud
148:12 queued 131:31
created

RebuildFolderTreeCommand::__construct()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 2
nop 1
1
<?php
2
3
namespace Kunstmaan\MediaBundle\Command;
4
5
use Doctrine\ORM\EntityManager;
6
use Doctrine\ORM\EntityManagerInterface;
7
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
/**
12
 * @final since 5.1
13
 * NEXT_MAJOR extend from `Command` and remove `$this->getContainer` usages
14
 */
15
class RebuildFolderTreeCommand extends ContainerAwareCommand
16
{
17
    /**
18
     * @var EntityManager
19
     */
20
    private $em;
21
22
    /**
23
     * @param EntityManagerInterface|null $em
24
     */
25
    public function __construct(/* EntityManagerInterface */ $em = null)
26
    {
27
        parent::__construct();
28
29
        if (!$em instanceof EntityManagerInterface) {
30
            @trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version symfony 3.4 and will be removed in symfony 4.0. If the command was registered by convention, make it a service instead. ', __METHOD__), E_USER_DEPRECATED);
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...
31
32
            $this->setName(null === $em ? 'kuma:media:rebuild-folder-tree' : $em);
33
34
            return;
35
        }
36
37
        $this->em = $em;
0 ignored issues
show
Documentation Bug introduced by
$em is of type object<Doctrine\ORM\EntityManagerInterface>, but the property $em was declared to be of type object<Doctrine\ORM\EntityManager>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    protected function configure()
44
    {
45
        parent::configure();
46
47
        $this->setName('kuma:media:rebuild-folder-tree')
48
            ->setDescription('Rebuild the media folder tree.')
49
            ->setHelp("The <info>kuma:media:rebuild-folder-tree</info> will loop over all media folders and update the media folder tree.");
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    protected function execute(InputInterface $input, OutputInterface $output)
56
    {
57
        if (null === $this->em) {
58
            $this->em = $this->getContainer()->get('doctrine.orm.entity_manager');
59
        }
60
61
        $this->em->getRepository('KunstmaanMediaBundle:Folder')->rebuildTree();
62
        $output->writeln('Updated all folders');
63
    }
64
}
65