ShouldStringify   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 29
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isSatisfiedBy() 0 8 3
A __construct() 0 3 1
A these() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Stratadox\EntityState\Internal;
5
6
use Stratadox\Specification\Contract\Satisfiable;
7
8
/**
9
 * Constraint to check if the extractor should stringify the object.
10
 *
11
 * @internal
12
 * @author Stratadox
13
 */
14
final class ShouldStringify implements Satisfiable
15
{
16
    private $types;
17
18
    private function __construct(string ...$types)
19
    {
20
        $this->types = $types;
21
    }
22
23
    /**
24
     * Produces a constraint to stringify these classes.
25
     *
26
     * @param string ...$classes Fully qualified class or interface names.
27
     * @return ShouldStringify   The constraint.
28
     */
29
    public static function these(string ...$classes): self
30
    {
31
        return new self(...$classes);
32
    }
33
34
    /** @inheritdoc */
35
    public function isSatisfiedBy($object): bool
36
    {
37
        foreach ($this->types as $stringifyIt) {
38
            if ($object instanceof $stringifyIt) {
39
                return true;
40
            }
41
        }
42
        return false;
43
    }
44
}
45