Passed
Push — master ( 6b0e6b...43789e )
by Stephen
03:30
created

TrackingRelationships::planManagement()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Sfneal\Tracking\Models\Traits;
4
5
use Domain\Plans\Models\Plan;
0 ignored issues
show
Bug introduced by
The type Domain\Plans\Models\Plan was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Domain\Plans\Models\PlanManagement;
0 ignored issues
show
Bug introduced by
The type Domain\Plans\Models\PlanManagement was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Domain\Projects\Models\Project;
0 ignored issues
show
Bug introduced by
The type Domain\Projects\Models\Project was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Domain\Tasks\Models\Task;
0 ignored issues
show
Bug introduced by
The type Domain\Tasks\Models\Task was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Domain\Tasks\Models\TaskRecord;
0 ignored issues
show
Bug introduced by
The type Domain\Tasks\Models\TaskRecord was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Illuminate\Database\Eloquent\Relations\BelongsTo;
11
12
// todo: probably move back to project
13
trait TrackingRelationships
14
{
15
    /**
16
     * Retrieve the TrackActivity instances Plan model if one exists.
17
     *
18
     * @return mixed|null
19
     */
20
    public function model()
21
    {
22
        // Plan
23
        if ($this->model_table == 'plan') {
24
            return $this->plan;
25
        } elseif (inString($this->model_table, 'plan_management')) {
26
            // Return Plan model if it exists
27
            if ($this->planManagement->plan) {
28
                return $this->planManagement->plan;
29
            }
30
31
            // Otherwise return the Project model
32
            else {
33
                return $this->planManagement->project;
34
            }
35
        }
36
37
        // Project
38
        elseif ($this->model_table == 'project') {
39
            return $this->project;
40
        }
41
42
        // Task
43
        elseif ($this->model_table == 'task_record' && $this->taskRecord && $this->taskRecord->task && $this->taskRecord->task->project) {
44
            return $this->taskRecord->task->project;
45
        } elseif ($this->model_table == 'task' && $this->task && $this->task->project) {
46
            return $this->task->project;
47
        }
48
49
        return null;
50
    }
51
52
    /**
53
     * Retrieve a route for this model.
54
     *
55
     * @return string
56
     */
57
    public function modelRoute()
58
    {
59
        // Plan
60
        if ($this->model() instanceof Plan) {
61
            return route('plans.plan.show', ['plan'=>$this->model()->getKey(), 'modal'=>1]);
62
        }
63
64
        // Project
65
        elseif ($this->model() instanceof Project) {
66
            return route('projects.show', ['project'=>$this->model()->getKey()]);
67
        }
68
    }
69
70
    /**
71
     * Retrieve the link class.
72
     *
73
     * @return string
74
     */
75
    public function linkClass(): string
76
    {
77
        if ($this->model() instanceof Plan) {
78
            return 'modal-link';
79
        } else {
80
            return '';
81
        }
82
    }
83
84
    /**
85
     * Plan relationship.
86
     *
87
     * @return BelongsTo
88
     */
89
    public function plan()
90
    {
91
        return $this->belongsTo(Plan::class, 'model_key', 'plan_id');
0 ignored issues
show
Bug introduced by
It seems like belongsTo() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

91
        return $this->/** @scrutinizer ignore-call */ belongsTo(Plan::class, 'model_key', 'plan_id');
Loading history...
92
    }
93
94
    /**
95
     * Plan management relationship.
96
     *
97
     * @return BelongsTo
98
     */
99
    public function planManagement()
100
    {
101
        return $this->belongsTo(PlanManagement::class, 'model_key', 'project_id');
102
    }
103
104
    /**
105
     * Project relationship.
106
     *
107
     * @return BelongsTo
108
     */
109
    public function project()
110
    {
111
        return $this->belongsTo(Project::class, 'model_key', 'project_id');
112
    }
113
114
    /**
115
     * Task relationship.
116
     *
117
     * @return BelongsTo
118
     */
119
    public function task()
120
    {
121
        return $this->belongsTo(Task::class, 'model_key', 'task_id');
122
    }
123
124
    /**
125
     * Task relationship.
126
     *
127
     * @return BelongsTo
128
     */
129
    public function taskRecord()
130
    {
131
        return $this->belongsTo(TaskRecord::class, 'model_key', 'record_id');
132
    }
133
}
134