AggregationHandler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 0
loc 36
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A registerSnapshot() 0 10 1
1
<?php
2
3
namespace Spiral\Snapshotter;
4
5
use Spiral\Core\Service;
6
use Spiral\Debug\SnapshotInterface;
7
use Spiral\Snapshotter\AggregationHandler\Database\IncidentRecord;
8
use Spiral\Snapshotter\AggregationHandler\Database\SnapshotRecord;
9
use Spiral\Snapshotter\AggregationHandler\Database\Sources\IncidentSource;
10
use Spiral\Snapshotter\AggregationHandler\Services\SnapshotService;
11
12
class AggregationHandler extends Service implements HandlerInterface
13
{
14
    /** @var IncidentSource */
15
    private $source;
16
17
    /** @var SnapshotService */
18
    private $service;
19
20
    /**
21
     * Aggregation constructor.
22
     *
23
     * @param IncidentSource  $snapshots
24
     * @param SnapshotService $service
25
     */
26
    public function __construct(IncidentSource $snapshots, SnapshotService $service)
27
    {
28
        $this->source = $snapshots;
29
        $this->service = $service;
30
    }
31
32
    /**
33
     * Create snapshot aggregation and aggregated snapshot and tie them together.
34
     *
35
     * @param SnapshotInterface $snapshot
36
     */
37
    public function registerSnapshot(SnapshotInterface $snapshot)
38
    {
39
        /** @var IncidentRecord $incident */
40
        $incident = $this->source->createFromSnapshot($snapshot);
41
42
        /** @var SnapshotRecord $snapshotRecord */
43
        $snapshotRecord = $this->service->getByHash($this->service->makeHash($snapshot));
44
        $snapshotRecord->pushIncident($incident);
45
        $snapshotRecord->save();
46
    }
47
}