ClearMediaTempCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 6
dl 0
loc 32
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 5 1
A execute() 0 17 3
1
<?php
2
/**
3
 * AnimeDb package.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2011, Peter Gribanov
7
 * @license   http://opensource.org/licenses/GPL-3.0 GPL v3
8
 */
9
namespace AnimeDb\Bundle\AppBundle\Command;
10
11
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
12
use Symfony\Component\Console\Input\InputInterface;
13
use Symfony\Component\Console\Output\OutputInterface;
14
use Symfony\Component\Filesystem\Filesystem;
15
use Symfony\Component\Finder\Finder;
16
17
/**
18
 * Clear the media temporary folder of images.
19
 */
20
class ClearMediaTempCommand extends ContainerAwareCommand
21
{
22
    protected function configure()
23
    {
24
        $this->setName('animedb:clear-media-temp')
25
            ->setDescription('Clear the media temporary folder of images');
26
    }
27
28
    /**
29
     * @param InputInterface $input
30
     * @param OutputInterface $output
31
     *
32
     * @return bool
33
     */
34
    protected function execute(InputInterface $input, OutputInterface $output)
35
    {
36
        $start = microtime(true);
37
38
        if (file_exists($dir = $this->getContainer()->getParameter('kernel.root_dir').'/../web/media/tmp/')) {
39
            $fs = new Filesystem();
40
41
            $finder = new Finder();
42
            $finder->in($dir)->date('< 1 hour ago')->ignoreUnreadableDirs();
43
            /* @var $file \SplFileInfo */
44
            foreach ($finder as $file) {
45
                $fs->remove($file->getRealPath());
46
            }
47
        }
48
49
        $output->writeln('Time: <info>'.round((microtime(true) - $start) * 1000, 2).'</info> s.');
50
    }
51
}
52