ProjectTaskPriorityModel   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 63
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getPriorities() 0 6 1
A getPrioritySettings() 0 8 1
A getDefaultPriority() 0 4 2
A getPriorityForProject() 0 10 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\Model;
13
14
use Jitamin\Foundation\Database\Model;
15
16
/**
17
 * Project Task Priority Model.
18
 */
19
class ProjectTaskPriorityModel extends Model
20
{
21
    /**
22
     * Get Priority range from a project.
23
     *
24
     * @param array $project
25
     *
26
     * @return array
27
     */
28
    public function getPriorities(array $project)
29
    {
30
        $range = range($project['priority_start'], $project['priority_end']);
31
32
        return array_combine($range, $range);
33
    }
34
35
    /**
36
     * Get task priority settings.
37
     *
38
     * @param int $project_id
39
     *
40
     * @return array|null
41
     */
42
    public function getPrioritySettings($project_id)
43
    {
44
        return $this->db
0 ignored issues
show
Documentation introduced by
The property db does not exist on object<Jitamin\Model\ProjectTaskPriorityModel>. 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...
45
            ->table(ProjectModel::TABLE)
46
            ->columns('priority_default', 'priority_start', 'priority_end')
47
            ->eq('id', $project_id)
48
            ->findOne();
49
    }
50
51
    /**
52
     * Get default task priority.
53
     *
54
     * @param int $project_id
55
     *
56
     * @return int
57
     */
58
    public function getDefaultPriority($project_id)
59
    {
60
        return $this->db->table(ProjectModel::TABLE)->eq('id', $project_id)->findOneColumn('priority_default') ?: 0;
0 ignored issues
show
Documentation introduced by
The property db does not exist on object<Jitamin\Model\ProjectTaskPriorityModel>. 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...
61
    }
62
63
    /**
64
     * Get priority for a destination project.
65
     *
66
     * @param int $dst_project_id
67
     * @param int $priority
68
     *
69
     * @return int
70
     */
71
    public function getPriorityForProject($dst_project_id, $priority)
72
    {
73
        $settings = $this->getPrioritySettings($dst_project_id);
74
75
        if ($priority >= $settings['priority_start'] && $priority <= $settings['priority_end']) {
76
            return $priority;
77
        }
78
79
        return $settings['priority_default'];
80
    }
81
}
82