NameVersion   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 33
ccs 11
cts 11
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A render() 0 12 4
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\UI\Component;
13
14
use Webmozart\Console\Api\Config\ApplicationConfig;
15
use Webmozart\Console\Api\IO\IO;
16
use Webmozart\Console\UI\Component;
17
18
/**
19
 * Renders the name and version of an application.
20
 *
21
 * @since  1.0
22
 *
23
 * @author Bernhard Schussek <[email protected]>
24
 */
25
class NameVersion implements Component
26
{
27
    private $config;
28
29
    /**
30
     * Creates the renderer.
31
     *
32
     * @param ApplicationConfig $config The application configuration.
33
     */
34 23
    public function __construct(ApplicationConfig $config)
35
    {
36 23
        $this->config = $config;
37 23
    }
38
39
    /**
40
     * Renders the name and version.
41
     *
42
     * @param IO  $io          The I/O.
43
     * @param int $indentation The number of spaces to indent.
44
     */
45 23
    public function render(IO $io, $indentation = 0)
46
    {
47 23
        if ($this->config->getDisplayName() && $this->config->getVersion()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->config->getDisplayName() of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
48 11
            $paragraph = new Paragraph("{$this->config->getDisplayName()} version <c1>{$this->config->getVersion()}</c1>");
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $this instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
49 12
        } elseif ($this->config->getDisplayName()) {
50 3
            $paragraph = new Paragraph("{$this->config->getDisplayName()}");
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $this instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
51
        } else {
52 9
            $paragraph = new Paragraph('Console Tool');
53
        }
54
55 23
        $paragraph->render($io, $indentation);
56 23
    }
57
}
58