Completed
Push — master ( c6463e...8a62ed )
by Pavel
02:21
created

FunctionSum::renderResult()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * @copyright   Copyright (c) 2015 ublaboo <[email protected]>
5
 * @author      Pavel Janda <[email protected]>
6
 * @package     Ublaboo
7
 */
8
9
namespace Ublaboo\DataGrid\AggregationFunction;
10
11
class FunctionSum implements IAggregationFunction
12
{
13
14
	/**
15
	 * @var string
16
	 */
17
	protected $column;
18
19
	/**
20
	 * @var int
21
	 */
22
	protected $result = 0;
23
24
25
	/**
26
	 * @param string $column
27
	 */
28
	public function __construct($column)
29
	{
30
		$this->column = $column;
31
	}
32
33
34
	/**
35
	 * @return bool
36
	 */
37
	public function getFilterDataType()
38
	{
39
		return IAggregationFunction::DATA_TYPE_PAGINATED;
40
	}
41
42
43
	/**
44
	 * @param  mixed $data_source
45
	 * @return void
46
	 */
47
	public function processDataSource($data_source)
48
	{
49
		if ($data_source instanceof \DibiFluent) {
0 ignored issues
show
Bug introduced by
The class DibiFluent does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
50
			$connection = $data_source->getConnection();
51
			$this->result = $connection->select('SUM(%n) AS sum', $this->column)
52
				->from($data_source, 's')
53
				->fetch()
54
				->sum;
55
		}
56
	}
57
58
59
	/**
60
	 * @return int
61
	 */
62
	public function renderResult()
63
	{
64
		return $this->result;
65
	}
66
67
}
68