JobProgress::findByJobId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace slavkluev\JobProgress\models;
6
7
use yii\db\ActiveRecord;
8
9
class JobProgress extends ActiveRecord
10
{
11 9
    public static function tableName()
12
    {
13 9
        return '{{%job_progress}}';
14
    }
15
16 9
    public function rules()
17
    {
18
        return [
19 9
            [['progress_max', 'progress_now'], 'required'],
20
            [['progress_max', 'progress_now'], 'integer'],
21
        ];
22
    }
23
24
    /**
25
     * @return int
26
     */
27 6
    public function getProgressMax(): int
28
    {
29 6
        return $this->progress_max;
0 ignored issues
show
Bug Best Practice introduced by
The property progress_max does not exist on slavkluev\JobProgress\models\JobProgress. Since you implemented __get, consider adding a @property annotation.
Loading history...
30
    }
31
32
    /**
33
     * @return int
34
     */
35 6
    public function getProgressNow(): int
36
    {
37 6
        return $this->progress_now;
0 ignored issues
show
Bug Best Practice introduced by
The property progress_now does not exist on slavkluev\JobProgress\models\JobProgress. Since you implemented __get, consider adding a @property annotation.
Loading history...
38
    }
39
40
    /**
41
     * @return float
42
     */
43 6
    public function getPercent(): float
44
    {
45 6
        return $this->getProgressMax() !== 0 ? ($this->getProgressNow() / $this->getProgressMax()) * 100 : 0;
46
    }
47
48 9
    public static function findByJobId($jobId): ?JobProgress
49
    {
50 9
        return static::findOne(['job_id' => $jobId]);
51
    }
52
}
53