Silencer::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 1
c 1
b 1
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
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