FastConsistencyValidator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 28
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A validateConsistency() 0 16 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Maba\DatabaseInconsistencyFinder\Service;
5
6
use Maba\DatabaseInconsistencyFinder\Database\QueryExecutor;
7
use Maba\DatabaseInconsistencyFinder\Entity\Interval;
8
use Maba\DatabaseInconsistencyFinder\Entity\ReferencesConfiguration;
9
10
class FastConsistencyValidator
11
{
12
    private $referencesConfiguration;
13
    private $queryExecutor;
14
15 8
    public function __construct(ReferencesConfiguration $referencesConfiguration, QueryExecutor $queryExecutor)
16
    {
17 8
        $this->referencesConfiguration = $referencesConfiguration;
18 8
        $this->queryExecutor = $queryExecutor;
19 8
    }
20
21 8
    public function validateConsistency(Interval $interval): bool
22
    {
23 8
        $expectedSum = $this->queryExecutor->calculateHashForInterval(
24 8
            $this->referencesConfiguration->getReferencedColumn(),
25 8
            $interval
26
        );
27 8
        $actualSum = 0;
28 8
        foreach ($this->referencesConfiguration->getTableReferencesList() as $tableReferences) {
29 8
            $actualSum += $this->queryExecutor->calculateHashInRelatedTablesForInterval(
30 8
                $tableReferences,
31 8
                $interval
32
            );
33
        }
34
35 8
        return $expectedSum === $actualSum;
36
    }
37
}
38