AbstractDumper   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 7
c 2
b 1
f 0
lcom 0
cbo 0
dl 0
loc 44
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 1 1
A output() 0 3 1
B dump() 0 34 5
1
<?php
2
/*
3
 * This file is part of Yolk - Gamer Network's PHP Framework.
4
 *
5
 * Copyright (c) 2013 Gamer Network Ltd.
6
 * 
7
 * Distributed under the MIT License, a copy of which is available in the
8
 * LICENSE file that was bundled with this package, or online at:
9
 * https://github.com/gamernetwork/yolk-core
10
 */
11
12
namespace yolk\debug;
13
14
abstract class AbstractDumper implements DumperInterface {
15
16
	private function __construct() {}
17
18
	public static function dump( $var, $output = true ) {
19
20
		$dumpers = [
21
			'is_null'     => 'dumpNull',
22
			'is_bool'     => 'dumpBoolean',
23
			'is_integer'  => 'dumpInteger',
24
			'is_float'    => 'dumpFloat',
25
			'is_string'   => 'dumpString',
26
			'is_array'    => 'dumpArray',
27
			'is_object'   => 'dumpObject',
28
			'is_resource' => 'dumpResource',
29
		];
30
31
		$item = false;
32
33
		foreach( $dumpers as $test => $dumper ) {
34
			if( $test($var) ) {
35
				$item = static::$dumper($var);
36
				break;
37
			}
38
		}
39
40
		if( !$item ) {
41
			ob_start();
42
			var_dump($var);
43
			$item = ob_get_clean();
44
		}
45
46
		if( $output )
47
			static::output($item);
48
49
		return $item;
50
51
	}
52
53
	protected static function output( $item ) {
54
		echo $item, "\n";
55
	}
56
57
}
58
59
// EOF