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

Builder::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
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