Completed
Push — master ( b7ef6a...58a002 )
by Kirill
03:12
created

Bootstrap   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 32
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 4 1
A registerDQLFunctions() 0 8 3
1
<?php
2
/**
3
 * This file is part of Hydrogen package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace RDS\Hydrogen;
11
12
use Doctrine\ORM\Configuration;
13
use Doctrine\ORM\EntityManagerInterface;
14
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
15
use RDS\Hydrogen\Fn\FieldFunction;
16
use RDS\Hydrogen\Fn\RawFunction;
17
18
/**
19
 * Class Bootstrap
20
 */
21
class Bootstrap
22
{
23
    /**
24
     * @var string[]|FunctionNode[]
25
     */
26
    private const DQL_FUNCTIONS = [
27
        'RAW'   => RawFunction::class,
28
        'FIELD' => FieldFunction::class,
29
    ];
30
31
    /**
32
     * @param EntityManagerInterface $em
33
     * @return void
34
     */
35 1
    public function register(EntityManagerInterface $em): void
36
    {
37 1
        $this->registerDQLFunctions($em->getConfiguration());
38 1
    }
39
40
    /**
41
     * @param Configuration $config
42
     * @return void
43
     */
44 1
    private function registerDQLFunctions(Configuration $config): void
45
    {
46 1
        foreach (self::DQL_FUNCTIONS as $name => $fn) {
47 1
            if (! $config->getCustomStringFunction($name)) {
48 1
                $config->addCustomStringFunction($name, $fn);
49
            }
50
        }
51 1
    }
52
}
53