Completed
Push — develop ( a0b2b6...96900c )
by Paul
02:40
created

ExceptionCatcher   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A catch() 0 6 2
1
<?php
2
3
namespace PhpUnitGen\Exception;
4
5
use PhpUnitGen\Configuration\ConfigurationInterface\ConsoleConfigInterface;
6
use PhpUnitGen\Exception\ExceptionInterface\ExceptionCatcherInterface;
7
use Symfony\Component\Console\Style\StyleInterface;
8
9
/**
10
 * Class ExceptionCatcher.
11
 *
12
 * @author     Paul Thébaud <[email protected]>.
13
 * @copyright  2017-2018 Paul Thébaud <[email protected]>.
14
 * @license    https://opensource.org/licenses/MIT The MIT license.
15
 * @link       https://github.com/paul-thebaud/phpunit-generator
16
 * @since      Class available since Release 2.0.0.
17
 */
18
class ExceptionCatcher implements ExceptionCatcherInterface
19
{
20
    /**
21
     * @var ConsoleConfigInterface $config The configuration to use.
22
     */
23
    private $config;
24
25
    /**
26
     * @var StyleInterface $output The output to display message.
27
     */
28
    private $output;
29
30
    /**
31
     * ExceptionCatcher constructor.
32
     *
33
     * @param ConsoleConfigInterface $config The config to use.
34
     * @param StyleInterface         $output The output to use.
35
     */
36
    public function __construct(
37
        ConsoleConfigInterface $config,
38
        StyleInterface $output
39
    ) {
40
        $this->config = $config;
41
        $this->output = $output;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function catch(Exception $exception): void
48
    {
49
        if ($this->config->hasIgnore()) {
50
            $this->output->note($exception->getMessage());
51
        } else {
52
            throw new Exception($exception->getMessage());
53
        }
54
    }
55
}
56