Completed
Push — 0.4.27 ( ba5c35...82f309 )
by Peter
03:09
created

ScanExecutor   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 56
ccs 14
cts 14
cp 1
rs 10

2 Methods

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