Issues (26)

src/Checks/BooleanCheck.php (1 issue)

Labels
Severity
1
<?php declare(strict_types=1);
2
3
4
namespace Pitchart\Phlunit\Checks;
5
6
use PHPUnit\Framework\Assert;
7
use Pitchart\Phlunit\Checks\Mixin\ConstraintCheck;
8
use Pitchart\Phlunit\Checks\Mixin\FluentChecks;
9
use Pitchart\Phlunit\Checks\Mixin\TypeCheck;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Pitchart\Phlunit\Checks\TypeCheck. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
10
use Pitchart\Phlunit\Checks\Mixin\WithMessage;
11
12
/**
13
 * Class BooleanCheck
14
 *
15
 * @package Pitchart\Phlunit\Checks
16
 *
17
 * @author Julien VITTE <[email protected]>
18
 *
19
 * @implements FluentCheck<boolean>
20
 */
21
class BooleanCheck implements FluentCheck
22
{
23 1
    use TypeCheck, FluentChecks, WithMessage, ConstraintCheck;
24
25
    /**
26
     * @var mixed
27
     */
28
    private $value;
29
30
    /**
31
     * BooleanCheck constructor.
32
     *
33
     * @param bool $value
34
     */
35 144
    public function __construct(bool $value)
36
    {
37 144
        $this->value = $value;
38 144
    }
39
40 95
    public function isTrue(): self
41
    {
42 95
        Assert::assertTrue($this->value);
43 95
        return $this;
44
    }
45
46 43
    public function isFalse(): self
47
    {
48 43
        Assert::assertFalse($this->value);
49 43
        return $this;
50
    }
51
}
52