Console::getLang()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Jaeger
4
 *
5
 * @author		Eric Lamb <[email protected]>
6
 * @copyright	Copyright (c) 2015-2016, mithra62, Eric Lamb
7
 * @link		http://jaeger-app.com
8
 * @version		1.0
9
 * @filesource 	./Console.php
10
 */
11
 
12
namespace JaegerApp;
13
14
/**
15
 * Jaeger - Console Output Object
16
 *
17
 * Handles outputting/writing data to the console 
18
 *
19
 * @package Platforms\Console
20
 * @author Eric Lamb <[email protected]>
21
 */
22
class Console
23
{
24
    /**
25
     * The arguments object
26
     * 
27
     * @var \cli\Arguments
28
     */
29
    protected $args = null;
30
31
    /**
32
     * The mithra62 Language object
33
     * 
34
     * @param
35
     *            Language
36
     */
37
    protected $lang = null;
38
39
    /**
40
     * The cli input string
41
     * 
42
     * @param string $tokens            
0 ignored issues
show
Bug introduced by
There is no parameter named $tokens. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
43
     */
44
    public function __construct()
45
    {}
46
47
    /**
48
     * Outputs an error to the console
49
     * 
50
     * @param string $error
51
     *            The language key for the message to display
52
     */
53
    public function outputError($error)
54
    {
55
        \cli\err($this->getLang()->__($error));
56
    }
57
58
    /**
59
     * Outputs a new line
60
     * 
61
     * @param string $string The output we want to display to the console out
62
     * @param bool $translate Whether the string should be sent through the mithra62\Language object
63
     * @return void
64
     */
65
    public function outputLine($string = '', $translate = true)
66
    {
67
        if ($translate) {
68
            \cli\line($this->getLang()->__($string));
69
        } else {
70
            \cli\line($string);
71
        }
72
    }
73
74
    /**
75
     * Adds a new line with page break
76
     */
77
    public function outputPageBreak()
78
    {
79
        \cli\line('');
80
        \cli\line('========================================================');
81
    }
82
83
    /**
84
     * An instance of the language object
85
     * 
86
     * @return \JaegerApp\Language
87
     */
88
    public function getLang()
89
    {
90
        return $this->lang;
91
    }
92
93
    /**
94
     * Sets the language object
95
     * 
96
     * @param Language $lang            
97
     * @return \JaegerApp\Console
98
     */
99
    public function setLang(Language $lang)
100
    {
101
        $this->lang = $lang;
102
        return $this;
103
    }
104
105
    /**
106
     * Returns the available commands the Console provides
107
     * @see \cli\Arguments
108
     * @param string $strict
109
     * @param string $force
110
     * @return \cli\Arguments
111
     */
112
    public function getArgs($strict = false, $force = false)
113
    {
114
        if (is_null($this->args) || $force) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $force of type false|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false 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...
115
            $this->args = new \cli\Arguments($strict);
0 ignored issues
show
Documentation introduced by
$strict is of type false|string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
116
            $this->args->addFlag(array(
117
                'verbose',
118
                'v'
119
            ), 'Turn on verbose output');
0 ignored issues
show
Documentation introduced by
'Turn on verbose output' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
120
            $this->args->addFlag('version', 'Display the version');
0 ignored issues
show
Documentation introduced by
'Display the version' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
121
            $this->args->addFlag(array(
122
                'help',
123
                'h'
124
            ), 'Show this help screen');
0 ignored issues
show
Documentation introduced by
'Show this help screen' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
125
        }
126
        
127
        return $this->args;
128
    }
129
}