NotOverlappedDatesRepository   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 39
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getOverlappedEntities() 0 23 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the zibios/sharep.
7
 *
8
 * (c) Zbigniew Ślązak
9
 */
10
11
namespace App\Repository\Functional;
12
13
use App\Entity\EntityInterface;
14
use App\Enum\Functional\ApplicationEnum;
15
use Doctrine\ORM\EntityManagerInterface;
16
17
class NotOverlappedDatesRepository
18
{
19
    /**
20
     * @var EntityManagerInterface
21
     */
22
    private $entityManager;
23
24 4
    public function __construct(EntityManagerInterface $entityManager)
25
    {
26 4
        $this->entityManager = $entityManager;
27 4
    }
28
29
    /**
30
     * @return array|EntityInterface[]
31
     */
32 4
    public function getOverlappedEntities(
33
        string $entityClass,
34
        string $fromDateProperty,
35
        string $toDateProperty,
36
        \DateTimeInterface $fromDate,
37
        \DateTimeInterface $toDate
38
    ): array {
39 4
        $where = '(e._from >= :fromDate AND e._from <= :toDate) OR (:fromDate >= e._from AND :fromDate <= e._to)';
40 4
        $where = str_replace(['_from', '_to'], [$fromDateProperty, $toDateProperty], $where);
41
42 4
        return $this->entityManager
43 4
            ->createQueryBuilder()
44 4
            ->select('e')
45 4
            ->from($entityClass, 'e')
46 4
            ->where($where)
47 4
            ->setParameters([
48 4
                'fromDate' => $fromDate->format(ApplicationEnum::DATE_FORMAT),
49 4
                'toDate' => $toDate->format(ApplicationEnum::DATE_FORMAT),
50
            ])
51 4
            ->getQuery()
52 4
            ->getResult()
53
        ;
54
    }
55
}
56