EstimatedTimeComparisonAnalytic   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B build() 0 27 3
1
<?php
2
3
/*
4
 * This file is part of Jitamin.
5
 *
6
 * Copyright (C) Jitamin Team
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Jitamin\Analytic;
13
14
use Jitamin\Foundation\Base;
15
use Jitamin\Model\TaskModel;
16
17
/**
18
 * Estimated/Spent Time Comparison.
19
 */
20
class EstimatedTimeComparisonAnalytic extends Base
21
{
22
    /**
23
     * Build report.
24
     *
25
     * @param int $project_id Project id
26
     *
27
     * @return array
28
     */
29
    public function build($project_id)
30
    {
31
        $rows = $this->db->table(TaskModel::TABLE)
0 ignored issues
show
Documentation introduced by
The property db does not exist on object<Jitamin\Analytic\...TimeComparisonAnalytic>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
32
            ->columns('SUM(time_estimated) AS time_estimated', 'SUM(time_spent) AS time_spent', 'is_active')
33
            ->eq('project_id', $project_id)
34
            ->groupBy('is_active')
35
            ->findAll();
36
37
        $metrics = [
38
            'open' => [
39
                'time_spent'     => 0,
40
                'time_estimated' => 0,
41
            ],
42
            'closed' => [
43
                'time_spent'     => 0,
44
                'time_estimated' => 0,
45
            ],
46
        ];
47
48
        foreach ($rows as $row) {
49
            $key = $row['is_active'] == TaskModel::STATUS_OPEN ? 'open' : 'closed';
50
            $metrics[$key]['time_spent'] = (float) $row['time_spent'];
51
            $metrics[$key]['time_estimated'] = (float) $row['time_estimated'];
52
        }
53
54
        return $metrics;
55
    }
56
}
57