HarvestProject::rules()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 35
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 29
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 35
rs 9.456
1
<?php
2
/**
3
 * SaaS Link plugin for Craft CMS 3.x
4
 *
5
 * @link      https://workingconcept.com
6
 * @copyright Copyright (c) 2018 Working Concept Inc.
7
 */
8
9
namespace workingconcept\saaslink\models\harvest;
10
11
use craft\base\Model;
12
13
/**
14
 * Harvest Project Model
15
 * https://help.getharvest.com/api-v2/projects-api/projects/projects/
16
 */
17
18
class HarvestProject extends Model
19
{
20
    // Properties
21
    // =========================================================================
22
23
    /**
24
     * @var int Unique ID for the project.
25
     */
26
    public $id;
27
28
    /**
29
     * @var HarvestClient An object containing the project’s client id, name, and currency.
30
     */
31
    private $_client;
32
33
    /**
34
     * @var string Unique name for the project.
35
     */
36
    public $name;
37
38
    /**
39
     * @var string The code associated with the project.
40
     */
41
    public $code;
42
43
    /**
44
     * @var bool Whether the project is active or archived.
45
     */
46
    public $is_active;
47
48
    /**
49
     * @var bool Whether the project is billable or not.
50
     */
51
    public $is_billable;
52
53
    /**
54
     * @var bool Whether the project is a fixed-fee project or not.
55
     */
56
    public $is_fixed_fee;
57
58
    /**
59
     * @var string The method by which the project is invoiced.
60
     */
61
    public $bill_by;
62
63
    /**
64
     * @var float Rate for projects billed by Project Hourly Rate.
65
     */
66
    public $hourly_rate;
67
68
    /**
69
     * @var float The budget in hours for the project when budgeting by time.
70
     */
71
    public $budget;
72
73
    /**
74
     * @var string The method by which the project is budgeted.
75
     */
76
    public $budget_by;
77
78
    /**
79
     * @var bool Option to have the budget reset every month.
80
     */
81
    public $budget_is_monthly;
82
83
    /**
84
     * @var bool Whether project managers should be notified when the project goes over budget.
85
     */
86
    public $notify_when_over_budget;
87
88
    /**
89
     * @var float Percentage value used to trigger over budget email alerts.
90
     */
91
    public $over_budget_notification_percentage;
92
93
    /**
94
     * @var string Date of last over budget notification. If none have been sent, this will be null.
95
     */
96
    public $over_budget_notification_date;
97
98
    /**
99
     * @var boolean Option to show project budget to all employees. Does not apply to Total Project Fee projects.
100
     */
101
    public $show_budget_to_all;
102
103
    /**
104
     * @var float The monetary budget for the project when budgeting by money.
105
     */
106
    public $cost_budget;
107
108
    /**
109
     * @var boolean Option for budget of Total Project Fees projects to include tracked expenses.
110
     */
111
    public $cost_budget_include_expenses;
112
113
    /**
114
     * @var float The amount you plan to invoice for the project. Only used by fixed-fee projects.
115
     */
116
    public $fee;
117
118
    /**
119
     * @var string Project notes.
120
     */
121
    public $notes;
122
123
    /**
124
     * @var string Date the project was started.
125
     */
126
    public $starts_on;
127
128
    /**
129
     * @var string Date the project will end.
130
     */
131
    public $ends_on;
132
133
    /**
134
     * @var string Date and time the project was created.
135
     */
136
    public $created_at;
137
138
    /**
139
     * @var string Date and time the project was last updated.
140
     */
141
    public $updated_at;
142
143
144
    // Public Methods
145
    // =========================================================================
146
147
    /**
148
     * Gets the project's client.
149
     *
150
     * @return HarvestClient
151
     */
152
    public function getClient(): HarvestClient
153
    {
154
        return $this->_client;
155
    }
156
157
    /**
158
     * Sets the project's client.
159
     *
160
     * @param \stdClass|HarvestClient $client Project client.
161
     *
162
     * @return HarvestClient
163
     */
164
    public function setClient($client)
165
    {
166
        if (is_object($client))
167
        {
168
            $client = new HarvestClient($client);
0 ignored issues
show
Bug introduced by
$client of type stdClass|workingconcept\...s\harvest\HarvestClient is incompatible with the type array expected by parameter $config of workingconcept\saaslink\...stClient::__construct(). ( Ignorable by Annotation )

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

168
            $client = new HarvestClient(/** @scrutinizer ignore-type */ $client);
Loading history...
169
        }
170
171
        return $this->_client = $client;
172
    }
173
174
    /**
175
     * @inheritdoc
176
     */
177
    public function rules(): array
178
    {
179
        return [
180
            [[
181
                'id', 
182
             ], 'number', 'integerOnly' => true],
183
            [['id'], 'required'],
184
            [[
185
                'hourly_rate', 
186
                'budget',
187
                'over_budget_notification_percentage',
188
                'cost_budget',
189
                'fee',
190
             ], 'number', 'integerOnly' => false],
191
            [[
192
                'name', 
193
                'code', 
194
                'bill_by', 
195
                'budget_by', 
196
                'over_budget_notification_date', 
197
                'notes', 
198
                'starts_on', 
199
                'ends_on', 
200
                'created_at', 
201
                'updated_at', 
202
             ], 'string'],
203
            [[
204
                'is_active', 
205
                'is_billable', 
206
                'is_fixed_fee', 
207
                'budget_is_monthly', 
208
                'notify_when_over_budget', 
209
                'show_budget_to_all', 
210
                'cost_budget_include_expenses', 
211
             ], 'boolean'],
212
        ];
213
    }
214
215
}
216