ConsoleIO::getDefaultTerminalDimensions()   A
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 1
Bugs 1 Features 1
Metric Value
c 1
b 1
f 1
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
cc 3
eloc 4
nc 1
nop 0
crap 3
1
<?php
2
3
/*
4
 * This file is part of the webmozart/console package.
5
 *
6
 * (c) Bernhard Schussek <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Webmozart\Console\IO;
13
14
use Symfony\Component\Console\Application;
15
use Webmozart\Console\Api\IO\Input;
16
use Webmozart\Console\Api\IO\IO;
17
use Webmozart\Console\Api\IO\Output;
18
use Webmozart\Console\Formatter\AnsiFormatter;
19
use Webmozart\Console\Formatter\PlainFormatter;
20
use Webmozart\Console\IO\InputStream\StandardInputStream;
21
use Webmozart\Console\IO\OutputStream\ErrorOutputStream;
22
use Webmozart\Console\IO\OutputStream\StandardOutputStream;
23
use Webmozart\Console\UI\Rectangle;
24
25
/**
26
 * An I/O that reads from/prints to the console.
27
 *
28
 * @since  1.0
29
 *
30
 * @author Bernhard Schussek <[email protected]>
31
 */
32
class ConsoleIO extends IO
33
{
34
    /**
35
     * Creates the I/O.
36
     *
37
     * @param Input  $input       The standard input.
0 ignored issues
show
Documentation introduced by
Should the type for parameter $input not be null|Input?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
38
     * @param Output $output      The standard output.
0 ignored issues
show
Documentation introduced by
Should the type for parameter $output not be null|Output?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
39
     * @param Output $errorOutput The error output.
0 ignored issues
show
Documentation introduced by
Should the type for parameter $errorOutput not be null|Output?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
40
     */
41 138
    public function __construct(Input $input = null, Output $output = null, Output $errorOutput = null)
42
    {
43 138
        if (null === $input) {
44 138
            $inputStream = new StandardInputStream();
45 138
            $input = new Input($inputStream);
46
        }
47
48 138 View Code Duplication
        if (null === $output) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
49 138
            $outputStream = new StandardOutputStream();
50 138
            $formatter = $outputStream->supportsAnsi() ? new AnsiFormatter() : new PlainFormatter();
51 138
            $output = new Output($outputStream, $formatter);
52
        }
53
54 138 View Code Duplication
        if (null === $errorOutput) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55 138
            $errorStream = new ErrorOutputStream();
56 138
            $formatter = $errorStream->supportsAnsi() ? new AnsiFormatter() : new PlainFormatter();
57 138
            $errorOutput = new Output($errorStream, $formatter);
58
        }
59
60 138
        parent::__construct($input, $output, $errorOutput);
61 138
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66 15
    protected function getDefaultTerminalDimensions()
67
    {
68 15
        $application = new Application();
69
70 15
        list($width, $height) = $application->getTerminalDimensions();
71
72 15
        return new Rectangle($width ?: 80, $height ?: 20);
73
    }
74
}
75