Observer_Td   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 32
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
B after_save() 0 20 7
1
<?php
2
3
namespace Fluentd;
4
5
class Observer_Td extends \Orm\Observer {
6
7
	public static $td_config;
8
9
	public function __construct($class)
10
	{
11
		\Config::load('observer', true);
12
		$ob_config = \Config::get('observer');
13
		self::$td_config = $ob_config['td'];
14
	}
15
16
	public function after_save(\Orm\Model $obj)
17
	{
18
19
		$save_data = array();
20
		foreach(array_keys($obj->properties()) as $p){
21
			$save_data[$p] = $obj->{$p};
22
		}
23
24
		$host     = empty(self::$td_config['host'])     ? null      : self::$td_config['host'];
25
		$port     = empty(self::$td_config['port'])     ? null      : self::$td_config['port'];
26
		$options  = empty(self::$td_config['options'])  ? array()   : self::$td_config['options'];
27
		$packer   = empty(self::$td_config['packer'])   ? null      : self::$td_config['packer'];
28
		$database = empty(self::$td_config['database']) ? 'default' : self::$td_config['database'];
29
		$table_name = $obj->table();
30
31
		\Fluent\Autoloader::register();
32
		$logger = new \Fluent\Logger\FluentLogger($host,$port,$options,$packer);
33
		$res = $logger->post('td.'.$database.'.'.$table_name,$save_data);
0 ignored issues
show
Unused Code introduced by
$res is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
34
35
	}
36
}
37