ShouldStringify::these()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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