Completed
Push — master ( 4dd9bb...1d5a37 )
by Allan
03:20 queued 12s
created

Silencer::__construct()   A

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
use Vaimo\ComposerPatches\Composer\OutputUtils;
10
11
class Silencer
12
{
13
    /**
14
     * @var \Composer\IO\IOInterface
15
     */
16
    private $appIO;
17
18
    /**
19
     * @param \Composer\IO\ConsoleIO $appIO
20
     */
21
    public function __construct(
22
        \Composer\IO\ConsoleIO $appIO
23
    ) {
24
        $this->appIO = $appIO;
25
    }
26
    
27
    public function applyToCallback(\Closure $callback)
28
    {
29
        $verbosityLevel = OutputUtils::resetVerbosity(
30
            $this->appIO,
31
            OutputInterface::VERBOSITY_QUIET
32
        );
33
34
        try {
35
            $result = $callback();
36
        } catch (\Exception $exception) {
37
            OutputUtils::resetVerbosity($this->appIO, $verbosityLevel);
38
39
            throw $exception;
40
        }
41
42
        OutputUtils::resetVerbosity($this->appIO, $verbosityLevel);
43
44
        return $result;
45
    }
46
}
47