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

PCBuilder   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
eloc 12
c 2
b 0
f 0
dl 0
loc 21
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setPart() 0 4 1
A createComputer() 0 11 1
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