1 | <?php |
||
15 | class Logger implements LoggerInterface { |
||
16 | |||
17 | /** |
||
18 | * @var LoggerInterface[] An array of writers. |
||
19 | */ |
||
20 | protected $writers = []; |
||
21 | |||
22 | /** |
||
23 | * @var int The max indent level to send to the writers. |
||
24 | */ |
||
25 | protected $maxLevel = 2; |
||
26 | |||
27 | /** |
||
28 | * @var array An array of currently running tasks. |
||
29 | */ |
||
30 | protected $taskStack = []; |
||
31 | |||
32 | /** |
||
33 | * Add a writer. |
||
34 | * |
||
35 | * @param WriterInterface $writer A writer to use. |
||
36 | * |
||
37 | * @return $this |
||
38 | */ |
||
39 | public function addWriter(WriterInterface $writer) { |
||
44 | |||
45 | /** |
||
46 | * Set the maximum indent level to send to the writers. |
||
47 | * |
||
48 | * @param int $maxLevel The maximum indent level |
||
49 | * |
||
50 | * @return $this |
||
51 | */ |
||
52 | public function setMaxLevel(int $maxLevel) { |
||
61 | |||
62 | /** |
||
63 | * Get the max indent level to send to the writers. |
||
64 | * |
||
65 | * @return int Returns the maxLevel. |
||
66 | */ |
||
67 | public function getMaxLevel() { |
||
70 | |||
71 | /** |
||
72 | * Log a message that designates the beginning of a task. |
||
73 | * |
||
74 | * @param string $str The message to output. |
||
75 | * @return $this |
||
76 | */ |
||
77 | public function begin(string $str) { |
||
90 | |||
91 | /** |
||
92 | * Log an error message. |
||
93 | * |
||
94 | * @param string $str The message to output. |
||
95 | * |
||
96 | * @return $this |
||
97 | */ |
||
98 | public function error(string $str) { |
||
104 | |||
105 | /** |
||
106 | * Log a success message. |
||
107 | * |
||
108 | * @param string $str The message to output. |
||
109 | * |
||
110 | * @return $this |
||
111 | */ |
||
112 | public function success(string $str) { |
||
118 | |||
119 | /** |
||
120 | * Log a warning message. |
||
121 | * |
||
122 | * @param string $str The message to output. |
||
123 | * |
||
124 | * @return $this |
||
125 | */ |
||
126 | public function warn(string $str) { |
||
132 | |||
133 | /** |
||
134 | * Log an info message. |
||
135 | * |
||
136 | * @param string $str The message to output. |
||
137 | * @param bool $force Whether or not to force output of the message even if it's past the max depth. |
||
138 | * |
||
139 | * @return $this |
||
140 | */ |
||
141 | public function message(string $str, bool $force = false) { |
||
164 | |||
165 | /** |
||
166 | * Log a message that represents a task being completed in success. |
||
167 | * |
||
168 | * @param string $str The message to output. |
||
169 | * @param bool $force Whether or not to force a message past the max level to be output. |
||
170 | * |
||
171 | * @return $this |
||
172 | */ |
||
173 | public function endSuccess(string $str, bool $force = false) { |
||
176 | |||
177 | /** |
||
178 | * Log a message that represents a task being completed in an error. |
||
179 | * |
||
180 | * When formatting is turned on, error messages are output in red. Error messages are always output even if they are |
||
181 | * past the maximum depth. |
||
182 | * |
||
183 | * @param string $str The message to output. |
||
184 | * |
||
185 | * @return $this |
||
186 | */ |
||
187 | public function endError(string $str) { |
||
190 | |||
191 | /** |
||
192 | * Log a message that designates a task being completed. |
||
193 | * |
||
194 | * @param string $str The message to output. |
||
195 | * @param bool $force Whether or not to always output the message even if the task is past the max depth. |
||
196 | * @param string $logLevel The level/type of log to write. |
||
197 | * |
||
198 | * @return $this |
||
199 | */ |
||
200 | public function end(string $str = '', bool $force = false, $logLevel = LogLevels::INFO) { |
||
221 | |||
222 | /** |
||
223 | * Log a message that ends a task with an HTTP status code. |
||
224 | * |
||
225 | * @param int $httpStatus The HTTP status code that represents the completion of a task. |
||
226 | * @param bool $force Whether or not to force message output. |
||
227 | * |
||
228 | * @return $this |
||
229 | * |
||
230 | * @see LogFormatter::endSuccess(), LogFormatter::endError(). |
||
231 | */ |
||
232 | public function endHttpStatus(int $httpStatus, bool $force = false) { |
||
245 | |||
246 | /** |
||
247 | * Write the stream. |
||
248 | * |
||
249 | * @param int $timestamp The unix timestamp of the log. |
||
250 | * @param string $logLevel The level of the message (e.g. SUCCESS, WARNING, ERROR). |
||
251 | * @param int $indentLevel The nesting level of the message. |
||
252 | * @param string $message The message. |
||
253 | * @param float|null $duration The duration to add to the message. |
||
254 | * |
||
255 | * @return $this |
||
256 | */ |
||
257 | public function write(int $timestamp, string $logLevel, string $message, $indentLevel = 0, $duration = null) { |
||
264 | } |
||
265 |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.