Completed
Push — master ( 3ee25f...4f2315 )
by Anton
01:29
created

src/Job/Entities/Job.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 DateTimeInterface;
22
use Illuminate\Support\Carbon;
23
24
final class Job implements JobContract
25
{
26
    private $type;
27
28
    private $id;
29
30
    private $status;
31
32
    private $process;
33
34
    private $requirement;
35
36
    private $createdAt;
37
38
    public function __construct(
39
        string $type,
40
        string $id,
41
        string $status,
42
        DateTimeInterface $createdAt,
43
        ProcessContract $process,
44
        ?RequirementContract $requirement = null
45
    ) {
46
        $this->type = $type;
47
        $this->id = $id;
48
        $this->status = $status;
49
        $this->createdAt = $createdAt;
50
        $this->process = $process;
51
        $this->requirement = $requirement;
52
    }
53
54
    public static function fromArray(array $job): JobContract
55
    {
56
        return new self(
57
            $job['type'],
58
            $job['id'],
59
            $job['status'],
60
            Carbon::createFromFormat(DATE_RFC3339_EXTENDED, $job['createdAt']),
0 ignored issues
show
It seems like \Illuminate\Support\Carb...DED, $job['createdAt']) targeting Carbon\Carbon::createFromFormat() can also be of type false; however, Cog\Laravel\Paket\Job\Entities\Job::__construct() does only seem to accept object<DateTimeInterface>, did you maybe forget to handle an error condition?
Loading history...
61
            Process::fromArray($job['process']),
62
            Requirement::fromArray($job['requirement'])
63
        );
64
    }
65
66
    public function toArray(): array
67
    {
68
        return [
69
            'type' => $this->getType(),
70
            'id' => $this->getId(),
71
            'status' => $this->status,
72
            'requirement' => $this->requirement->toArray(),
73
            'process' => $this->process->toArray(),
74
            'createdAt' => $this->createdAt->format(DATE_RFC3339_EXTENDED),
75
        ];
76
    }
77
78
    public function getType(): string
79
    {
80
        return $this->type;
81
    }
82
83
    public function getId(): string
84
    {
85
        return $this->id;
86
    }
87
88
    public function getRequirement(): RequirementContract
89
    {
90
        return $this->requirement;
91
    }
92
}
93