BarcodeCheckerSpec::it_invalidates()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace spec\Loevgaard\SyliusBarcodePlugin\BarcodeChecker;
6
7
use Loevgaard\SyliusBarcodePlugin\BarcodeChecker\BarcodeChecker;
8
use Loevgaard\SyliusBarcodePlugin\Event\PostBarcodeCheckEvent;
9
use Loevgaard\SyliusBarcodePlugin\Event\PreBarcodeCheckEvent;
10
use Loevgaard\SyliusBarcodePlugin\Model\BarcodeAwareInterface;
11
use PhpSpec\ObjectBehavior;
12
use Prophecy\Argument;
13
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
14
15
class BarcodeCheckerSpec extends ObjectBehavior
16
{
17
    public function it_is_initializable(): void
18
    {
19
        $this->shouldHaveType(BarcodeChecker::class);
20
    }
21
22
    public function let(EventDispatcherInterface $eventDispatcher): void
23
    {
24
        $this->beConstructedWith($eventDispatcher);
25
    }
26
27
    public function it_invalidates(BarcodeAwareInterface $barcodeAware): void
28
    {
29
        $barcodeAware->getBarcode()->willReturn('invalid');
30
        $barcodeAware->markBarcodeAsChecked(false)->shouldBeCalled();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $barcodeAware->markBarcodeAsChecked(false) targeting Loevgaard\SyliusBarcodeP...:markBarcodeAsChecked() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
31
32
        $this->check($barcodeAware);
0 ignored issues
show
Bug introduced by
The method check() does not exist on spec\Loevgaard\SyliusBar...cker\BarcodeCheckerSpec. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

32
        $this->/** @scrutinizer ignore-call */ 
33
               check($barcodeAware);
Loading history...
33
    }
34
35
    public function it_validates(BarcodeAwareInterface $barcodeAware): void
36
    {
37
        $barcodeAware->getBarcode()->willReturn('4006381333931');
38
        $barcodeAware->markBarcodeAsChecked(true)->shouldBeCalled();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $barcodeAware->markBarcodeAsChecked(true) targeting Loevgaard\SyliusBarcodeP...:markBarcodeAsChecked() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
39
40
        $this->check($barcodeAware);
41
    }
42
43
    public function it_dispatches_events(EventDispatcherInterface $eventDispatcher, BarcodeAwareInterface $barcodeAware): void
44
    {
45
        $eventDispatcher->dispatch(Argument::type(PreBarcodeCheckEvent::class), PreBarcodeCheckEvent::NAME)->shouldBeCalledOnce();
0 ignored issues
show
Deprecated Code introduced by
The constant Loevgaard\SyliusBarcodeP...BarcodeCheckEvent::NAME has been deprecated: will be removed in v2 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

45
        $eventDispatcher->dispatch(Argument::type(PreBarcodeCheckEvent::class), /** @scrutinizer ignore-deprecated */ PreBarcodeCheckEvent::NAME)->shouldBeCalledOnce();

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
Unused Code introduced by
The call to Symfony\Contracts\EventD...erInterface::dispatch() has too many arguments starting with Loevgaard\SyliusBarcodeP...BarcodeCheckEvent::NAME. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

45
        $eventDispatcher->/** @scrutinizer ignore-call */ 
46
                          dispatch(Argument::type(PreBarcodeCheckEvent::class), PreBarcodeCheckEvent::NAME)->shouldBeCalledOnce();

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
46
        $eventDispatcher->dispatch(Argument::type(PostBarcodeCheckEvent::class), PostBarcodeCheckEvent::NAME)->shouldBeCalledOnce();
0 ignored issues
show
Deprecated Code introduced by
The constant Loevgaard\SyliusBarcodeP...BarcodeCheckEvent::NAME has been deprecated: will be removed in v2 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

46
        $eventDispatcher->dispatch(Argument::type(PostBarcodeCheckEvent::class), /** @scrutinizer ignore-deprecated */ PostBarcodeCheckEvent::NAME)->shouldBeCalledOnce();

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
47
48
        $this->check($barcodeAware);
49
    }
50
}
51