Passed
Pull Request — develop (#169)
by
unknown
03:14 queued 01:21
created

Company::fromModel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 14
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 18
rs 9.7998
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 Core\Domain\Common\Model\VO\ContactUuid;
19
use Core\Domain\Common\Model\VO\EmailField;
20
use Core\Domain\Common\Model\VO\NameField;
21
use Core\Domain\Common\Model\VO\PhoneField;
22
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...
23
24
/**
25
 * @ORM\Table(name="company")
26
 * @ORM\Entity(repositoryClass="Company\Infrastructure\Doctrine\Repository\CompanyRepository")
27
 */
28
class Company extends Contact
29
{
30
    public function __construct(Contact $contact)
31
    {
32
        parent::__construct(
33
            $contact->uuid,
34
            $contact->companyName,
35
            $contact->address,
36
            $contact->zipCode,
37
            $contact->town,
38
            $contact->country,
39
            $contact->phone,
40
            $contact->facsimile,
41
            $contact->email,
42
            $contact->contactName,
43
            $contact->cellphone,
44
            $contact->slug
45
        );
46
    }
47
48
    public static function fromModel(CompanyModel $companyModel): self
49
    {
50
        $contact = Contact::create(
51
            $companyModel->uuid(),
52
            $companyModel->companyName(),
53
            $companyModel->address(),
54
            $companyModel->zipCode(),
55
            $companyModel->town(),
56
            $companyModel->country(),
57
            $companyModel->phone(),
58
            $companyModel->facsimile(),
59
            $companyModel->email(),
60
            $companyModel->contactName(),
61
            $companyModel->cellphone(),
62
            $companyModel->slug()
63
        );
64
65
        return new self($contact);
66
    }
67
68
    public function toModel(): CompanyModel
69
    {
70
        return CompanyModel::create(
71
            ContactUuid::fromString($this->getUuid()),
72
            NameField::fromString($this->getCompanyName()),
73
            $this->getAddress(),
74
            $this->getZipCode(),
75
            $this->getTown(),
76
            $this->getCountry(),
77
            PhoneField::fromString($this->getPhone()),
78
            PhoneField::fromString($this->getFacsimile()),
79
            EmailField::fromString($this->getEmail()),
80
            $this->getContactName(),
81
            PhoneField::fromString($this->getCellphone())
82
        );
83
    }
84
85
    public function update(CompanyModel $companyModel): self
86
    {
87
        $this->companyName = $companyModel->companyName();
88
        $this->address = $companyModel->address();
89
        $this->zipCode = $companyModel->zipCode();
90
        $this->town = $companyModel->town();
91
        $this->country = $companyModel->country();
92
        $this->phone = $companyModel->phone();
93
        $this->facsimile = $companyModel->facsimile();
94
        $this->email = $companyModel->email();
95
        $this->contactName = $companyModel->contactName();
96
        $this->cellphone = $companyModel->cellphone();
97
98
        return $this;
99
    }
100
}
101