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
use Ramsey\Uuid\Uuid;
22
23
final class Job implements JobContract
24
{
25
    private $type;
26
27
    private $id;
28
29
    private $status;
30
31
    private $process;
32
33
    private $requirement;
34
35
    public function __construct(
36
        string $type,
37
        string $id,
38
        string $status,
39
        ProcessContract $process,
40
        ?RequirementContract $requirement = null
41
    )
42
    {
43
        $this->type = $type;
44
        $this->id = $id;
45
        $this->status = $status;
46
        $this->process = $process;
47
        $this->requirement = $requirement;
48
    }
49
50
    public static function fromArray(array $job): JobContract
51
    {
52
        return new self(
53
            $job['type'],
54
            $job['id'],
55
            $job['status'],
56
            Process::fromArray($job['process']),
57
            Requirement::fromArray($job['requirement'])
58
        );
59
    }
60
61
    public function toArray(): array
62
    {
63
        return [
64
            'type' => $this->getType(),
65
            'id' => $this->getId(),
66
            'status' => $this->status,
67
            'requirement' => $this->requirement->toArray(),
68
            'process' => $this->process->toArray(),
69
        ];
70
    }
71
72
    public function getType(): string
73
    {
74
        return $this->type;
75
    }
76
77
    public function getId(): string
78
    {
79
        return $this->id;
80
    }
81
}
82