Completed
Push — master ( 015490...3fff3d )
by diego
06:23 queued 04:33
created

Target::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 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 2
    public function __construct(ImportServiceInterface $importService, Dispatcher $dispatcher)
34
    {
35 2
        $this->importService = $importService;
36 2
        $this->dispatcher = $dispatcher;
37 2
    }
38
39
    /**
40
     * @param TargetInterface $target
41
     * @param mixed $entry
42
     * @param Import $import
43
     * @param int $pointer
44
     *
45
     * @throws \Exception
46
     */
47 2
    public function process(TargetInterface $target, $entry, Import $import, $pointer)
48
    {
49
        try {
50 2
            $entry = $this->emitEntrySignal('preProcess', $target->getConfiguration(), $entry);
51 2
            $result = $target->processEntry($entry);
52 1
            $import->increaseCount($result);
53 1
        } catch (\Exception $e) {
54 1
            $import->increaseCount(TargetInterface::RESULT_ERROR);
55 1
            $this->importService->updateImport($import, $pointer + 1);
56 1
            throw $e;
57
        }
58 1
    }
59
60
    /**
61
     * @param string $name
62
     * @param array $configuration
63
     * @param mixed $entry
64
     *
65
     * @return mixed
66
     */
67 2
    protected function emitEntrySignal($name, array $configuration, $entry)
68
    {
69 2
        $result = $this->dispatcher->dispatch(
70 2
            __CLASS__,
71
            $name,
72 2
            [$configuration, $entry]
73
        );
74
75 2
        return $result[1];
76
    }
77
}
78