Completed
Push — master ( 582aca...bfe713 )
by Peter
02:49
created

ScanExecutor   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 57
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A export() 0 15 1
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
10
namespace AnimeDb\Bundle\CatalogBundle\Service\Storage;
11
12
use Symfony\Component\Filesystem\Filesystem;
13
use AnimeDb\Bundle\AppBundle\Service\CommandExecutor;
14
use AnimeDb\Bundle\CatalogBundle\Entity\Storage as StorageEntity;
15
16
/**
17
 * Storage scanner service.
18
 *
19
 * @author  Peter Gribanov <[email protected]>
20
 */
21
class ScanExecutor
22
{
23
    /**
24
     * @var CommandExecutor
25
     */
26
    protected $command;
27
28
    /**
29
     * @var Filesystem
30
     */
31
    protected $fs;
32
33
    /**
34
     * @var string
35
     */
36
    protected $output = '';
37
38
    /**
39
     * @var string
40
     */
41
    protected $progress = '';
42
43
    /**
44
     * @param CommandExecutor $command
45
     * @param Filesystem $fs
46
     * @param string $output
47
     * @param string $progress
48
     */
49 1
    public function __construct(CommandExecutor $command, Filesystem $fs, $output, $progress)
50
    {
51 1
        $this->progress = $progress;
52 1
        $this->command = $command;
53 1
        $this->output = $output;
54 1
        $this->fs = $fs;
55 1
    }
56
57
    /**
58
     * Scan storage in background and export progress and output.
59
     *
60
     * @param StorageEntity $storage
61
     */
62 1
    public function export(StorageEntity $storage)
63
    {
64 1
        $output = sprintf($this->output, $storage->getId());
65 1
        $progress = sprintf($this->progress, $storage->getId());
66
67 1
        $this->fs->mkdir([dirname($output), dirname($progress)], 0755);
68 1
        $this->fs->remove([$output, $progress]);
69
70 1
        $this->command->send(sprintf(
71 1
            'php app/console animedb:scan-storage --no-ansi --force --export=%s %s >%s 2>&1',
72 1
            $progress,
73 1
            $storage->getId(),
74
            $output
75 1
        ));
76 1
    }
77
}
78