Passed
Pull Request — 1.x (#1)
by Kevin
01:50
created

IsTrue   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 15
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 4 2
A __construct() 0 4 1
1
<?php
2
3
namespace Zenstruck\Browser\Assert\Assertion;
4
5
use Zenstruck\Browser\Assert\Assertion;
6
use Zenstruck\Browser\Assert\Exception\AssertionFailed;
7
8
/**
9
 * @author Kevin Bond <[email protected]>
10
 */
11
final class IsTrue implements Assertion
12
{
13
    private bool $expression;
14
    private string $message;
15
16
    public function __construct(bool $expression, string $message, ...$args)
17
    {
18
        $this->expression = $expression;
19
        $this->message = \sprintf($message, ...$args);
20
    }
21
22
    public function __invoke(): void
23
    {
24
        if (!$this->expression) {
25
            throw new AssertionFailed($this->message);
26
        }
27
    }
28
}
29