Silencer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 13
dl 0
loc 35
rs 10
c 1
b 1
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A applyToCallback() 0 19 3
1
<?php
2
/**
3
 * Copyright © Vaimo Group. All rights reserved.
4
 * See LICENSE_VAIMO.txt for license details.
5
 */
6
namespace Vaimo\ComposerPatches\Console;
7
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
use Vaimo\ComposerPatches\Composer\OutputUtils;
11
12
class Silencer
13
{
14
    /**
15
     * @var \Composer\IO\IOInterface
16
     */
17
    private $appIO;
18
19
    /**
20
     * @param \Composer\IO\ConsoleIO $appIO
21
     */
22
    public function __construct(
23
        \Composer\IO\ConsoleIO $appIO
24
    ) {
25
        $this->appIO = $appIO;
26
    }
27
28
    public function applyToCallback(\Closure $callback)
29
    {
30
        if ($this->appIO->isVerbose()) {
31
            return $callback();
32
        }
33
34
        $verbosityLevel = OutputUtils::resetVerbosity($this->appIO, OutputInterface::VERBOSITY_QUIET);
35
36
        try {
37
            $result = $callback();
38
        } catch (\Exception $exception) {
39
            OutputUtils::resetVerbosity($this->appIO, $verbosityLevel);
40
41
            throw $exception;
42
        }
43
44
        OutputUtils::resetVerbosity($this->appIO, $verbosityLevel);
45
46
        return $result;
47
    }
48
}
49