CallbackProcessor::item()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2.1481

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 4
ccs 2
cts 3
cp 0.6667
crap 2.1481
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the DataImporter package.
7
 *
8
 * (c) Loïc Sapone <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace IQ2i\DataImporter\Processor;
15
16
use IQ2i\DataImporter\Exchange\Message;
17
18
class CallbackProcessor implements ProcessorInterface
19
{
20
    private readonly ?\Closure $begin;
21
22
    private readonly ?\Closure $item;
23
24
    private readonly ?\Closure $end;
25
26 1
    public function __construct(?callable $begin = null, ?callable $item = null, ?callable $end = null)
27
    {
28 1
        $this->begin = $begin ? $begin(...) : null;
0 ignored issues
show
Bug introduced by
The property begin is declared read-only in IQ2i\DataImporter\Processor\CallbackProcessor.
Loading history...
29 1
        $this->item = $item ? $item(...) : null;
0 ignored issues
show
Bug introduced by
The property item is declared read-only in IQ2i\DataImporter\Processor\CallbackProcessor.
Loading history...
30 1
        $this->end = $end ? $end(...) : null;
0 ignored issues
show
Bug introduced by
The property end is declared read-only in IQ2i\DataImporter\Processor\CallbackProcessor.
Loading history...
31
    }
32
33 1
    public function begin(Message $message): void
34
    {
35 1
        if (null !== $this->begin) {
36
            ($this->begin)($message);
37
        }
38
    }
39
40 1
    public function item(Message $message): void
41
    {
42 1
        if (null !== $this->item) {
43
            ($this->item)($message);
44
        }
45
    }
46
47 1
    public function end(Message $message): void
48
    {
49 1
        if (null !== $this->end) {
50
            ($this->end)($message);
51
        }
52
    }
53
}
54