AbstractDumper::output()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
nc 1
cc 1
eloc 2
nop 1
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