Completed
Pull Request — master (#7)
by Andreas
02:07
created

NullOutput::writeln()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 1
nc 1
nop 2
1
<?php
2
/**
3
 * Copyright (c) 2016-2016} Andreas Heigl<[email protected]>
4
 * Permission is hereby granted, free of charge, to any person obtaining a copy
5
 * of this software and associated documentation files (the "Software"), to deal
6
 * in the Software without restriction, including without limitation the rights
7
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
 * copies of the Software, and to permit persons to whom the Software is
9
 * furnished to do so, subject to the following conditions:
10
 * The above copyright notice and this permission notice shall be included in
11
 * all copies or substantial portions of the Software.
12
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
18
 * THE SOFTWARE.
19
 *
20
 * @author    Andreas Heigl<[email protected]>
21
 * @copyright 2016-2016 Andreas Heigl
22
 * @license   http://www.opensource.org/licenses/mit-license.php MIT-License
23
 * @version   0.0
24
 * @since     27.03.2016
25
 * @link      http://github.com/heiglandreas/callingallpapers
26
 */
27
28
namespace Callingallpapers\Writer;
29
30
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
31
use Symfony\Component\Console\Output\OutputInterface;
32
33
class NullOutput implements OutputInterface
34
{
35
36
    /**
37
     * Returns whether verbosity is debug (-vvv).
38
     *
39
     * @return bool true if verbosity is set to VERBOSITY_DEBUG, false otherwise
40
     */
41
    public function isDebug()
42
    {
43
        return false;
44
    }
45
46
    /**
47
     * Sets output formatter.
48
     *
49
     * @param OutputFormatterInterface $formatter
50
     *
51
     * @api
52
     */
53
    public function setFormatter(OutputFormatterInterface $formatter)
54
    {
55
        // TODO: Implement setFormatter() method.
56
    }
57
58
    /**
59
     * Returns whether verbosity is verbose (-v).
60
     *
61
     * @return bool true if verbosity is set to VERBOSITY_VERBOSE, false otherwise
62
     */
63
    public function isVerbose()
64
    {
65
        return false;
66
    }
67
68
    /**
69
     * Returns whether verbosity is very verbose (-vv).
70
     *
71
     * @return bool true if verbosity is set to VERBOSITY_VERY_VERBOSE, false otherwise
72
     */
73
    public function isVeryVerbose()
74
    {
75
        return false;
76
    }
77
78
    /**
79
     * Writes a message to the output.
80
     *
81
     * @param string|array $messages The message as an array of lines or a single string
82
     * @param bool         $newline  Whether to add a newline
83
     * @param int          $type     The type of output (one of the OUTPUT constants)
84
     *
85
     * @throws \InvalidArgumentException When unknown output type is given
86
     * @api
87
     */
88
    public function write(
89
        $messages,
90
        $newline = false,
91
        $type = self::OUTPUT_NORMAL
92
    ) {
93
        // TODO: Implement write() method.
94
    }
95
96
    /**
97
     * Writes a message to the output and adds a newline at the end.
98
     *
99
     * @param string|array $messages The message as an array of lines or a single string
100
     * @param int          $type     The type of output (one of the OUTPUT constants)
101
     *
102
     * @throws \InvalidArgumentException When unknown output type is given
103
     * @api
104
     */
105
    public function writeln($messages, $type = self::OUTPUT_NORMAL)
106
    {
107
        // TODO: Implement writeln() method.
108
    }
109
110
    /**
111
     * Sets the verbosity of the output.
112
     *
113
     * @param int $level The level of verbosity (one of the VERBOSITY constants)
114
     *
115
     * @api
116
     */public function setVerbosity($level)
117
{
118
    // TODO: Implement setVerbosity() method.
119
}
120
121
    /**
122
     * Gets the current verbosity of the output.
123
     *
124
     * @return int The current level of verbosity (one of the VERBOSITY constants)
125
     * @api
126
     */
127
    public function getVerbosity()
128
    {
129
        return 0;
130
    }
131
132
    /**
133
     * Sets the decorated flag.
134
     *
135
     * @param bool $decorated Whether to decorate the messages
136
     *
137
     * @api
138
     */
139
    public function setDecorated($decorated)
140
    {
141
        // TODO: Implement setDecorated() method.
142
    }
143
144
    /**
145
     * Gets the decorated flag.
146
     *
147
     * @return bool true if the output will decorate messages, false otherwise
148
     * @api
149
     */
150
    public function isDecorated()
151
    {
152
        return 0;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return 0; (integer) is incompatible with the return type declared by the interface Symfony\Component\Consol...tInterface::isDecorated of type boolean.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
153
    }
154
155
    /**
156
     * Returns current output formatter instance.
157
     *
158
     * @return OutputFormatterInterface
159
     * @api
160
     */
161
    public function getFormatter()
162
    {
163
        // TODO: Implement getFormatter() method.
164
    }
165
166
    /**
167
     * Returns whether verbosity is quiet (-q).
168
     *
169
     * @return bool true if verbosity is set to VERBOSITY_QUIET, false otherwise
170
     */
171
    public function isQuiet()
172
    {
173
        // TODO: Implement isQuiet() method.
174
    }
175
}
176