Writer   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 42
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A confirm() 0 12 1
A writeError() 0 15 1
1
<?php
2
/**
3
 * This file is part of the phpspec-console package.
4
 * (c) 2017 Timo Michna <timomichna/yahoo.de>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Tidal\PhpSpec\ConsoleExtension;
11
12
use Tidal\PhpSpec\ConsoleExtension\Contract\WriterInterface;
13
use Tidal\PhpSpec\ConsoleExtension\Behavior\Command\HasConsoleIOTrait;
14
15
/**
16
 * class Tidal\PhpSpec\ConsoleExtension\Writer
17
 */
18
class Writer implements WriterInterface
19
{
20
    use HasConsoleIOTrait;
21
22
    /**
23
     * @param string $pattern
24
     * @param array $arguments
25
     * @param bool $default
26
     * @return bool
27
     */
28
    public function confirm(string $pattern, array $arguments = [], bool $default = true): bool
29
    {
30
        $message = vsprintf(
31
            $pattern,
32
            $arguments
33
        );
34
35
        return $this->getConsoleIO()->askConfirmation(
36
            $message,
37
            $default
38
        );
39
    }
40
41
    /**
42
     * @param string $message
43
     */
44
    public function writeError(string $message): void
45
    {
46
        $this->getConsoleIO()->writeln(sprintf(
47
            '<error> %s </error>',
48
            str_repeat(' ', strlen($message))
49
        ));
50
        $this->getConsoleIO()->writeln(sprintf(
51
            '<error> %s </error>',
52
            $message
53
        ));
54
        $this->getConsoleIO()->writeln(sprintf(
55
            '<error> %s </error>',
56
            str_repeat(' ', strlen($message))
57
        ));
58
    }
59
}
60
61