Passed
Push — master ( 249a0e...ea66cd )
by Dev
11:53
created

MediaCommand::execute()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 4
eloc 11
c 1
b 1
f 0
nc 6
nop 2
dl 0
loc 17
ccs 0
cts 14
cp 0
crap 20
rs 9.9
1
<?php
2
3
namespace PiedWeb\CMSBundle\Command;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
7
use Liip\ImagineBundle\Imagine\Data\DataManager;
8
use Liip\ImagineBundle\Imagine\Filter\FilterManager;
9
use PiedWeb\CMSBundle\EventListener\MediaCacheGeneratorTrait;
10
use Symfony\Component\Console\Command\Command;
11
use Symfony\Component\Console\Helper\ProgressBar;
12
use Symfony\Component\Console\Input\InputInterface;
13
use Symfony\Component\Console\Input\InputArgument;
14
use Symfony\Component\Console\Output\OutputInterface;
15
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
16
17
class MediaCommand extends Command
18
{
19
    use MediaCacheGeneratorTrait;
20
21
    /**
22
     * @var EntityManagerInterface
23
     */
24
    private $em;
25
26
    /**
27
     * @var string
28
     */
29
    private $webDir;
30
31
    /**
32
     * @var string
33
     */
34
    private $staticDir;
35
36
    private $params;
37
38
    protected $redirections = '';
39
40
    private $cacheManager;
41
    private $dataManager;
42
    private $filterManager;
43
44
    public function __construct(
45
        EntityManagerInterface $em,
46
        ParameterBagInterface $params,
47
        CacheManager $cacheManager,
48
        DataManager $dataManager,
49
        FilterManager $filterManager,
50
        string $webDir
51
    ) {
52
        $this->em = $em;
53
        $this->params = $params;
54
        $this->webDir = $webDir;
55
        $this->cacheManager = $cacheManager;
56
        $this->dataManager = $dataManager;
57
        $this->filterManager = $filterManager;
58
        $this->staticDir = $this->webDir.'/../static';
59
        $this->projectDir = $this->webDir.'/..';
60
61
        parent::__construct();
62
    }
63
64
    protected function configure()
65
    {
66
        $this
67
            ->setName('media:cache:generate')
68
            ->setDescription('Generate all images cache')
69
            ->addArgument('media', InputArgument::OPTIONAL,
70
                'Image file path for which to generate the cached images.');
71
    }
72
73
    protected function execute(InputInterface $input, OutputInterface $output)
74
    {
75
        if ($input->getArgument('media')) {
76
            $medias = $this->em->getRepository($this->params->get('app.entity_media'))->findByMedia($input->getArgument('media'));
0 ignored issues
show
Bug introduced by
The method findByMedia() does not exist on Doctrine\Persistence\ObjectRepository. Did you maybe mean findBy()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

76
            $medias = $this->em->getRepository($this->params->get('app.entity_media'))->/** @scrutinizer ignore-call */ findByMedia($input->getArgument('media'));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
77
        } else {
78
            $medias = $this->em->getRepository($this->params->get('app.entity_media'))->findAll();
79
        }
80
81
        $progressBar = new ProgressBar($output, count($medias));
82
        $progressBar->start();
83
        foreach ($medias as $media) {
84
            if (false !== strpos($media->getMimeType(), 'image/')) {
85
                $this->generateCache($media);
86
            }
87
            $progressBar->advance();
88
        }
89
        $progressBar->finish();
90
    }
91
}
92