1 | <?php |
||
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() |
||
45 | |||
46 | /** |
||
47 | * Sets output formatter. |
||
48 | * |
||
49 | * @param OutputFormatterInterface $formatter |
||
50 | * |
||
51 | * @api |
||
52 | */ |
||
53 | public function setFormatter(OutputFormatterInterface $formatter) |
||
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() |
||
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() |
||
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( |
||
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) |
||
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) |
||
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() |
||
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) |
||
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() |
||
154 | |||
155 | /** |
||
156 | * Returns current output formatter instance. |
||
157 | * |
||
158 | * @return OutputFormatterInterface |
||
159 | * @api |
||
160 | */ |
||
161 | public function getFormatter() |
||
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() |
||
175 | } |
||
176 |
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:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.