Debug   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A dispatchDebug() 0 13 5
1
<?php
2
3
namespace PhpConsole\Dispatcher;
4
use PhpConsole\DebugMessage;
5
use PhpConsole\Dispatcher;
6
7
/**
8
 * Sends debug data to connector as client expected messages
9
 *
10
 * @package PhpConsole
11
 * @version 3.1
12
 * @link http://consle.com
13
 * @author Sergey Barbushin http://linkedin.com/in/barbushin
14
 * @copyright © Sergey Barbushin, 2011-2013. All rights reserved.
15
 * @license http://www.opensource.org/licenses/BSD-3-Clause "The BSD 3-Clause License"
16
 */
17
class Debug extends Dispatcher {
18
19
	/** @var bool Autodetect and append trace data to debug */
20
	public $detectTraceAndSource = false;
21
22
	/**
23
	 * Send debug data message to client
24
	 * @param mixed $data
25
	 * @param null|string $tags Tags separated by dot, e.g. "low.db.billing"
26
	 * @param int|array $ignoreTraceCalls Ignore tracing classes by name prefix `array('PhpConsole')` or fixed number of calls to ignore
27
	 */
28 14
	public function dispatchDebug($data, $tags = null, $ignoreTraceCalls = 0) {
29 14
		if($this->isActive()) {
30 13
			$message = new DebugMessage();
31 13
			$message->data = $this->dumper->dump($data);
32 13
			if($tags) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $tags 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...
33 7
				$message->tags = explode('.', $tags);
34
			}
35 13
			if($this->detectTraceAndSource && $ignoreTraceCalls !== null) {
36 4
				$message->trace = $this->fetchTrace(debug_backtrace(), $message->file, $message->line, $ignoreTraceCalls);
37
			}
38 13
			$this->sendMessage($message);
39
		}
40 14
	}
41
}
42