Completed
Push — develop ( fdb6a9...488668 )
by Paul
02:02
created

ConsoleExecutor::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace PhpUnitGen\Executor;
4
5
use PhpUnitGen\Configuration\ConfigurationInterface\ConsoleConfigInterface;
6
use PhpUnitGen\Exception\Exception;
7
use PhpUnitGen\Exception\ExceptionInterface\ExceptionCatcherInterface;
8
use PhpUnitGen\Executor\ExecutorInterface\ConsoleExecutorInterface;
9
use PhpUnitGen\Executor\ExecutorInterface\DirectoryExecutorInterface;
10
use PhpUnitGen\Executor\ExecutorInterface\FileExecutorInterface;
11
use Symfony\Component\Console\Style\StyleInterface;
12
13
/**
14
 * Class ConsoleExecutor.
15
 *
16
 * @author     Paul Thébaud <[email protected]>.
17
 * @copyright  2017-2018 Paul Thébaud <[email protected]>.
18
 * @license    https://opensource.org/licenses/MIT The MIT license.
19
 * @link       https://github.com/paul-thebaud/phpunit-generator
20
 * @since      Class available since Release 2.0.0.
21
 */
22
class ConsoleExecutor implements ConsoleExecutorInterface
23
{
24
    /**
25
     * @var ConsoleConfigInterface $config The configuration to use.
26
     */
27
    private $config;
28
29
    /**
30
     * @var StyleInterface $output The output to display message.
31
     */
32
    private $output;
33
34
    /**
35
     * @var DirectoryExecutorInterface $directoryExecutor A directory executor.
36
     */
37
    private $directoryExecutor;
38
39
    /**
40
     * @var FileExecutorInterface $fileExecutor A file executor.
41
     */
42
    private $fileExecutor;
43
44
    /**
45
     * @var ExceptionCatcherInterface $exceptionCatcher An exception catcher to catch exception.
46
     */
47
    private $exceptionCatcher;
48
49
    /**
50
     * ConsoleExecutor constructor.
51
     *
52
     * @param ConsoleConfigInterface     $config            The config to use.
53
     * @param StyleInterface             $output            The output to use.
54
     * @param DirectoryExecutorInterface $directoryExecutor The directory executor.
55
     * @param FileExecutorInterface      $fileExecutor      The file executor.
56
     * @param ExceptionCatcherInterface  $exceptionCatcher  The exception catcher.
57
     */
58
    public function __construct(
59
        ConsoleConfigInterface $config,
60
        StyleInterface $output,
0 ignored issues
show
Unused Code introduced by
The parameter $output is not used and could be removed. ( Ignorable by Annotation )

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

60
        /** @scrutinizer ignore-unused */ StyleInterface $output,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
61
        DirectoryExecutorInterface $directoryExecutor,
62
        FileExecutorInterface $fileExecutor,
63
        ExceptionCatcherInterface $exceptionCatcher
64
    ) {
65
        $this->config            = $config;
66
        $this->directoryExecutor = $directoryExecutor;
67
        $this->fileExecutor      = $fileExecutor;
68
        $this->exceptionCatcher  = $exceptionCatcher;
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public function execute(): void
75
    {
76
        $this->executeOnDirectories();
77
78
        $this->output->section('Global files parsing begins.');
79
80
        $this->executeOnFiles();
81
    }
82
83
    /**
84
     * Execute PhpUnitGen tasks on directories.
85
     */
86
    private function executeOnDirectories(): void
87
    {
88
        foreach ($this->config->getDirectories() as $source => $target) {
89
            try {
90
                $this->directoryExecutor->execute($source, $target);
91
            } catch (Exception $exception) {
92
                $this->exceptionCatcher->catch($exception);
93
            }
94
        }
95
    }
96
97
    /**
98
     * Execute PhpUnitGen tasks on files.
99
     */
100
    private function executeOnFiles(): void
101
    {
102
        foreach ($this->config->getFiles() as $source => $target) {
103
            try {
104
                $this->fileExecutor->execute($source, $target);
105
            } catch (Exception $exception) {
106
                $this->exceptionCatcher->catch($exception);
107
            }
108
        }
109
    }
110
}
111