Completed
Push — master ( 86437d...3559e6 )
by diego
08:58
created

Target   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 63
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A process() 0 12 2
A emitEntrySignal() 0 10 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace HDNET\Importr\Processor;
6
7
use HDNET\Importr\Domain\Model\Import;
8
use HDNET\Importr\Service\ImportServiceInterface;
9
use HDNET\Importr\Service\Targets\TargetInterface;
10
use TYPO3\CMS\Extbase\SignalSlot\Dispatcher;
11
12
/**
13
 * Target
14
 */
15
class Target
16
{
17
    /**
18
     * @var ImportServiceInterface
19
     */
20
    protected $importService;
21
22
    /**
23
     * @var Dispatcher
24
     */
25
    protected $dispatcher;
26
27
    /**
28
     * Target constructor.
29
     *
30
     * @param ImportServiceInterface $importService
31
     * @param Dispatcher $dispatcher
32
     */
33
    public function __construct(ImportServiceInterface $importService, Dispatcher $dispatcher)
34
    {
35
        $this->importService = $importService;
36
        $this->dispatcher = $dispatcher;
37
    }
38
39
    /**
40
     * @param TargetInterface $target
41
     * @param mixed $entry
42
     * @param Import $import
43
     * @param int $pointer
44
     *
45
     * @throws \Exception
46
     */
47
    public function process(TargetInterface $target, $entry, Import $import, $pointer)
48
    {
49
        try {
50
            $entry = $this->emitEntrySignal('preProcess', $target->getConfiguration(), $entry);
51
            $result = $target->processEntry($entry);
52
            $import->increaseCount($result);
53
        } catch (\Exception $e) {
54
            $import->increaseCount(TargetInterface::RESULT_ERROR);
55
            $this->importService->updateImport($import, $pointer + 1);
56
            throw $e;
57
        }
58
    }
59
60
    /**
61
     * @param string $name
62
     * @param array $configuration
63
     * @param mixed $entry
64
     *
65
     * @return mixed
66
     */
67
    protected function emitEntrySignal($name, array $configuration, $entry)
68
    {
69
        $result = $this->dispatcher->dispatch(
70
            __CLASS__,
71
            $name,
72
            [$configuration, $entry]
73
        );
74
75
        return $result[1];
76
    }
77
}
78