Test Failed
Push — master ( 1c5165...b7ef6a )
by Kirill
03:37
created

Builder   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 68.75%

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A meta() 0 4 1
A execute() 0 4 1
A nothing() 0 6 2
A extractResult() 0 6 1
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\Processor\DatabaseProcessor;
11
12
use Doctrine\ORM\Mapping\ClassMetadata;
13
use RDS\Hydrogen\Processor\BuilderInterface;
14
use RDS\Hydrogen\Processor\ProcessorInterface;
15
use RDS\Hydrogen\Query;
16
17
/**
18
 * Class Builder
19
 */
20
abstract class Builder implements BuilderInterface
21
{
22
    /**
23
     * @var ProcessorInterface
24
     */
25
    protected $processor;
26
27
    /**
28
     * @var ClassMetadata
29
     */
30
    protected $meta;
31
32
    /**
33
     * Builder constructor.
34
     * @param ClassMetadata $meta
35
     * @param ProcessorInterface $processor
36
     */
37 28
    public function __construct(ClassMetadata $meta, ProcessorInterface $processor)
38
    {
39 28
        $this->meta = $meta;
40 28
        $this->processor = $processor;
41 28
    }
42
43
    /**
44
     * @param string $entity
45
     * @return ClassMetadata
46
     */
47
    protected function meta(string $entity): ClassMetadata
48
    {
49
        return $this->processor->getEntityManager()->getClassMetadata($entity);
50
    }
51
52
    /**
53
     * @param string $entity
54
     * @param Query $query
55
     * @return iterable
56
     */
57
    protected function execute(string $entity, Query $query): iterable
58
    {
59
        return $this->processor->getProcessor($entity)->getResult($query);
60
    }
61
62
    /**
63
     * @return \Generator
64
     */
65 14
    protected function nothing(): \Generator
66
    {
67 14
        if (false) {
68
            yield;
69
        }
70 14
    }
71
72
    /**
73
     * @param \Generator $generator
74
     * @param \Closure $then
75
     * @return \Generator
76
     */
77 8
    protected function extractResult(\Generator $generator, \Closure $then): \Generator
78
    {
79 8
        yield from $generator;
80
81 8
        $then($generator->getReturn());
82 8
    }
83
}
84