ProductCode   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 47
c 0
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A fromString() 0 4 1
A __toString() 0 4 1
A equals() 0 4 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace SyliusCart\Domain\ValueObject;
6
7
use SyliusCart\Domain\Exception\ProductCodeCannotBeEmptyException;
8
9
/**
10
 * @author Arkadiusz Krakowiak <[email protected]>
11
 */
12
final class ProductCode
13
{
14
    /**
15
     * @var string
16
     */
17
    private $code;
18
19
    /**
20
     * @param string $code
21
     */
22
    private function __construct(string $code)
23
    {
24
        if ('' === $code) {
25
            throw new ProductCodeCannotBeEmptyException();
26
        }
27
28
        $this->code = $code;
29
    }
30
31
    /**
32
     * @param string $code
33
     *
34
     * @return self
35
     */
36
    public static function fromString($code): self
37
    {
38
        return new self($code);
39
    }
40
41
    /**
42
     * @return string
43
     */
44
    public function __toString(): string
45
    {
46
        return $this->code;
47
    }
48
49
    /**
50
     * @param ProductCode $productCode
51
     *
52
     * @return bool
53
     */
54
    public function equals(ProductCode $productCode): bool
55
    {
56
        return  $productCode->__toString() === $this->code;
57
    }
58
}
59