Passed
Push — master ( a3992d...97a7b2 )
by Korotkov
02:57 queued 01:22
created

PCBuilder::createComputer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 11
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author  : Jagepard <[email protected]>
7
 * @license https://mit-license.org/ MIT
8
 */
9
10
namespace Creational\Builder;
11
12
use Creational\Builder\{Hardware\AbstractPart, Interfaces\BuilderInterface, Interfaces\ComputerInterface};
13
14
class PCBuilder implements BuilderInterface
15
{
16
    private array $components;
17
18
    public function createComputer(): ComputerInterface
19
    {
20
        $this
21
            ->setPart(new Hardware\Motherboard(Order::MB))
22
            ->setPart(new Hardware\Cpu(Order::CPU))
23
            ->setPart(new Hardware\Ram(Order::RAM))
24
            ->setPart(new Hardware\Gpu(Order::GPU))
25
            ->setPart(new Hardware\Ssd(Order::SSD))
26
            ->setPart(new Hardware\Hdd(Order::HDD));
27
28
        return new Desktop($this->components);
29
    }
30
31
    private function setPart(AbstractPart $part): BuilderInterface
32
    {
33
        $this->components[get_class($part)] = $part;
34
        return $this;
35
    }
36
}
37