BarcodeChecker   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 8
c 0
b 0
f 0
dl 0
loc 20
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A check() 0 10 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Loevgaard\SyliusBarcodePlugin\BarcodeChecker;
6
7
use Loevgaard\SyliusBarcodePlugin\Event\PostBarcodeCheckEvent;
8
use Loevgaard\SyliusBarcodePlugin\Event\PreBarcodeCheckEvent;
9
use Loevgaard\SyliusBarcodePlugin\Model\BarcodeAwareInterface;
10
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
11
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
12
use violuke\Barcodes\BarcodeValidator;
13
14
final class BarcodeChecker implements BarcodeCheckerInterface
15
{
16
    /** @var LegacyEventDispatcherProxy */
17
    private $eventDispatcher;
18
19
    public function __construct(EventDispatcherInterface $eventDispatcher)
20
    {
21
        $this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher);
22
    }
23
24
    public function check(BarcodeAwareInterface $barcodeAware): void
25
    {
26
        $this->eventDispatcher->dispatch(new PreBarcodeCheckEvent($barcodeAware), PreBarcodeCheckEvent::NAME);
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

26
        $this->eventDispatcher->dispatch(new PreBarcodeCheckEvent($barcodeAware), /** @scrutinizer ignore-deprecated */ PreBarcodeCheckEvent::NAME);

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...
27
28
        $validator = new BarcodeValidator($barcodeAware->getBarcode());
29
        $valid = (bool) $validator->isValid();
30
31
        $barcodeAware->markBarcodeAsChecked($valid);
32
33
        $this->eventDispatcher->dispatch(new PostBarcodeCheckEvent($barcodeAware, $valid, (string) $validator->getType()), PostBarcodeCheckEvent::NAME);
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

33
        $this->eventDispatcher->dispatch(new PostBarcodeCheckEvent($barcodeAware, $valid, (string) $validator->getType()), /** @scrutinizer ignore-deprecated */ PostBarcodeCheckEvent::NAME);

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...
34
    }
35
}
36