Completed
Pull Request — master (#2)
by Anton
01:19
created

Job::ofType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
c 0
b 0
f 0
rs 9.9666
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of Laravel Paket.
5
 *
6
 * (c) Anton Komarev <[email protected]>
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
declare(strict_types=1);
13
14
namespace Cog\Laravel\Paket\Job\Entities;
15
16
use Cog\Contracts\Paket\Job\Entities\Job as JobContract;
17
use Cog\Contracts\Paket\Process\Entities\Process as ProcessContract;
18
use Cog\Contracts\Paket\Requirement\Entities\Requirement as RequirementContract;
19
use Cog\Laravel\Paket\Process\Entities\Process;
20
use Cog\Laravel\Paket\Requirement\Entities\Requirement;
21
22
final class Job implements JobContract
23
{
24
    private $type;
25
26
    private $id;
27
28
    private $status;
29
30
    private $process;
31
32
    private $requirement;
33
34
    public function __construct(
35
        string $type,
36
        string $id,
37
        string $status,
38
        ProcessContract $process,
39
        ?RequirementContract $requirement = null
40
    )
41
    {
42
        $this->type = $type;
43
        $this->id = $id;
44
        $this->status = $status;
45
        $this->process = $process;
46
        $this->requirement = $requirement;
47
    }
48
49
    public static function fromArray(array $job): JobContract
50
    {
51
        return new self(
52
            $job['type'],
53
            $job['id'],
54
            $job['status'],
55
            Process::fromArray($job['process']),
56
            Requirement::fromArray($job['requirement'])
57
        );
58
    }
59
60
    public function toArray(): array
61
    {
62
        return [
63
            'type' => $this->getType(),
64
            'id' => $this->getId(),
65
            'status' => $this->status,
66
            'requirement' => $this->requirement->toArray(),
67
            'process' => $this->process->toArray(),
68
        ];
69
    }
70
71
    public function getType(): string
72
    {
73
        return $this->type;
74
    }
75
76
    public function getId(): string
77
    {
78
        return $this->id;
79
    }
80
}
81