Completed
Pull Request — 1.0 (#853)
by Rob
02:21
created

ConsoleIO   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 60
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A isInteractive() 0 4 1
A write() 0 10 2
A ask() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the `liip/LiipImagineBundle` project.
5
 *
6
 * (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Liip\ImagineBundle\Utils\Composer;
13
14
use Composer\IO\IOInterface;
15
use Composer\Package\RootPackageInterface;
16
17
final class ConsoleIO
18
{
19
    /**
20
     * @var string
21
     */
22
    private static $format = '<fg=yellow>[%s]</> %s';
23
24
    /**
25
     * @var IOInterface
26
     */
27
    private $io;
28
29
    /**
30
     * @var RootPackageInterface
31
     */
32
    private $package;
33
34
    /**
35
     * @param IOInterface          $io
36
     * @param RootPackageInterface $package
37
     */
38
    public function __construct(IOInterface $io, RootPackageInterface $package)
39
    {
40
        $this->io = $io;
41
        $this->package = $package;
42
    }
43
44
    /**
45
     * @return bool
46
     */
47
    public function isInteractive()
48
    {
49
        return $this->io->isInteractive();
50
    }
51
52
    /**
53
     * @param string $line
54
     * @param array  $replacements
55
     */
56
    public function write($line, array $replacements = array())
57
    {
58
        $line = sprintf(static::$format, $this->package->getName(), $line);
0 ignored issues
show
Comprehensibility introduced by
Since Liip\ImagineBundle\Utils\Composer\ConsoleIO is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
59
60
        if (count($replacements) > 0) {
61
            $line = vsprintf($line, $replacements);
62
        }
63
64
        $this->io->write($line);
65
    }
66
67
    /**
68
     * @param string $what
69
     *
70
     * @return bool
71
     */
72
    public function ask($what)
73
    {
74
        return $this->io->askConfirmation(sprintf(static::$format, $this->package->getName(), $what), true);
0 ignored issues
show
Comprehensibility introduced by
Since Liip\ImagineBundle\Utils\Composer\ConsoleIO is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
75
    }
76
}
77