Logger::info()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
/**
3
 * This file is part of the Composer Merge plugin.
4
 *
5
 * Copyright (C) 2015 Bryan Davis, Wikimedia Foundation, and contributors
6
 *
7
 * This software may be modified and distributed under the terms of the MIT
8
 * license. See the LICENSE file for details.
9
 */
10
11
namespace Wikimedia\Composer;
12
13
use Composer\IO\IOInterface;
14
15
/**
16
 * Simple logging wrapper for Composer\IO\IOInterface
17
 *
18
 * @author Bryan Davis <[email protected]>
19
 */
20
class Logger
21
{
22
    /**
23
     * @var string $name
24
     */
25
    protected $name;
26
27
    /**
28
     * @var IOInterface $inputOutput
29
     */
30
    protected $inputOutput;
31
32
    /**
33
     * @param string $name
34
     * @param IOInterface $io
35
     */
36 220
    public function __construct($name, IOInterface $io)
37
    {
38 220
        $this->name = $name;
39 220
        $this->inputOutput = $io;
40 220
    }
41
42
    /**
43
     * Log a debug message
44
     *
45
     * Messages will be output at the "very verbose" logging level (eg `-vv`
46
     * needed on the Composer command).
47
     *
48
     * @param string $message
49
     */
50 180
    public function debug($message)
51
    {
52 180
        if ($this->inputOutput->isVeryVerbose()) {
53 5
            $message = "  <info>[{$this->name}]</info> {$message}";
54 5
            $this->log($message);
55 1
        }
56 180
    }
57
58
    /**
59
     * Log an informative message
60
     *
61
     * Messages will be output at the "verbose" logging level (eg `-v` needed
62
     * on the Composer command).
63
     *
64
     * @param string $message
65
     */
66 190
    public function info($message)
67
    {
68 190
        if ($this->inputOutput->isVerbose()) {
69 5
            $message = "  <info>[{$this->name}]</info> {$message}";
70 5
            $this->log($message);
71 1
        }
72 190
    }
73
74
    /**
75
     * Log a warning message
76
     *
77
     * @param string $message
78
     */
79 10
    public function warning($message)
80
    {
81 10
        $message = "  <error>[{$this->name}]</error> {$message}";
82 10
        $this->log($message);
83 10
    }
84
85
    /**
86
     * Write a message
87
     *
88
     * @param string $message
89
     */
90 20
    protected function log($message)
91
    {
92 20
        if (method_exists($this->inputOutput, 'writeError')) {
93 20
            $this->inputOutput->writeError($message);
94 4
        } else {
95
            // @codeCoverageIgnoreStart
96
            // Backwards compatiblity for Composer before cb336a5
97
            $this->inputOutput->write($message);
98
            // @codeCoverageIgnoreEnd
99
        }
100 20
    }
101
}
102
// vim:sw=4:ts=4:sts=4:et:
103