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

Silencer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A applyToCallback() 0 18 2
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