Passed
Push — develop ( e3219b...3a1d34 )
by Laurent
01:38
created

Company::toModel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 14
rs 9.8666
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the G.L.S.R. Apps package.
7
 *
8
 * (c) Dev-Int Création <[email protected]>.
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Company\Infrastructure\Doctrine\Entity;
15
16
use Administration\Infrastructure\Persistence\DoctrineOrm\Entities\Contact;
17
use Company\Domain\Model\Company as CompanyModel;
18
use Company\Domain\Storage\Company\CompanyEntity;
19
use Core\Domain\Common\Model\VO\ContactUuid;
20
use Core\Domain\Common\Model\VO\EmailField;
21
use Core\Domain\Common\Model\VO\NameField;
22
use Core\Domain\Common\Model\VO\PhoneField;
23
use Doctrine\ORM\Mapping as ORM;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\Mapping was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
25
/**
26
 * @ORM\Table(name="company")
27
 * @ORM\Entity(repositoryClass="Company\Infrastructure\Doctrine\Repository\CompanyRepository")
28
 */
29
class Company extends Contact implements CompanyEntity
30
{
31
    public function __construct(Contact $contact)
32
    {
33
        parent::__construct(
34
            $contact->uuid,
35
            $contact->companyName,
36
            $contact->address,
37
            $contact->zipCode,
38
            $contact->town,
39
            $contact->country,
40
            $contact->phone,
41
            $contact->facsimile,
42
            $contact->email,
43
            $contact->contactName,
44
            $contact->cellphone,
45
            $contact->slug
46
        );
47
    }
48
49
    public static function fromModel(CompanyModel $companyModel): self
50
    {
51
        $contact = Contact::create(
52
            $companyModel->uuid(),
53
            $companyModel->companyName(),
54
            $companyModel->address(),
55
            $companyModel->zipCode(),
56
            $companyModel->town(),
57
            $companyModel->country(),
58
            $companyModel->phone(),
59
            $companyModel->facsimile(),
60
            $companyModel->email(),
61
            $companyModel->contactName(),
62
            $companyModel->cellphone(),
63
            $companyModel->slug()
64
        );
65
66
        return new self($contact);
67
    }
68
69
    public function toModel(): CompanyModel
70
    {
71
        return CompanyModel::create(
72
            ContactUuid::fromString($this->uuid),
73
            NameField::fromString($this->companyName),
74
            $this->address,
75
            $this->zipCode,
76
            $this->town,
77
            $this->country,
78
            PhoneField::fromString($this->phone),
79
            PhoneField::fromString($this->facsimile),
80
            EmailField::fromString($this->email),
81
            $this->contactName,
82
            PhoneField::fromString($this->cellphone),
83
        );
84
    }
85
86
    public function update(CompanyModel $companyModel): self
87
    {
88
        $this->companyName = $companyModel->companyName();
89
        $this->address = $companyModel->address();
90
        $this->zipCode = $companyModel->zipCode();
91
        $this->town = $companyModel->town();
92
        $this->country = $companyModel->country();
93
        $this->phone = $companyModel->phone();
94
        $this->facsimile = $companyModel->facsimile();
95
        $this->email = $companyModel->email();
96
        $this->contactName = $companyModel->contactName();
97
        $this->cellphone = $companyModel->cellphone();
98
99
        return $this;
100
    }
101
}
102