PCBuilder::setPart()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 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
    /**
19
     * Assembles a computer
20
     * --------------------
21
     * Собирает компьютер
22
     *
23
     * @return ComputerInterface
24
     */
25
    public function createComputer(): ComputerInterface
26
    {
27
        $this
28
            ->setPart(new Hardware\Motherboard(Order::MB))
29
            ->setPart(new Hardware\Cpu(Order::CPU))
30
            ->setPart(new Hardware\Ram(Order::RAM))
31
            ->setPart(new Hardware\Gpu(Order::GPU))
32
            ->setPart(new Hardware\Ssd(Order::SSD))
33
            ->setPart(new Hardware\Hdd(Order::HDD));
34
35
        return new Desktop($this->components);
36
    }
37
38
    /**
39
     * Adds a computer element
40
     * ----------------------------
41
     * Добавляет элемент компьютера
42
     *
43
     * @param  AbstractPart     $part
44
     * @return BuilderInterface
45
     */
46
    private function setPart(AbstractPart $part): BuilderInterface
47
    {
48
        $this->components[get_class($part)] = $part;
49
        return $this;
50
    }
51
}
52