Completed
Pull Request — master (#4)
by Woody
02:12
created

Text   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 3
c 3
b 0
f 2
lcom 0
cbo 1
dl 0
loc 30
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A value() 0 4 1
1
<?php
2
3
namespace Equip\ValueObject;
4
5
use function Assert\that;
6
7
class Text
8
{
9
    /**
10
     * @var string|null
11
     */
12
    private $value;
13
14
    /**
15
     * @param string|null $value
16
     * @param string|null $regex
17
     */
18 12
    public function __construct($value, $regex = null)
19
    {
20 12
        $assert = that($value)->nullOr()->string();
21
22 7
        if ($regex) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $regex of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
23 4
            $assert->regex($regex);
24 2
        }
25
26 5
        $this->value = $value;
27 5
    }
28
29
    /**
30
     * @return string|null
31
     */
32 5
    public function value()
33
    {
34 5
        return $this->value;
35
    }
36
}
37