Completed
Push — 2.x ( 86616a...8ac5a6 )
by Aleksei
14s queued 11s
created

UpdateLoader   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 46
rs 10
c 1
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A loadData() 0 5 2
A __construct() 0 8 1
A initNode() 0 3 1
A getAlias() 0 3 1
A isLoaded() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\ORM\Select;
6
7
use Cycle\ORM\FactoryInterface;
8
use Cycle\ORM\Parser\AbstractNode;
9
use Cycle\ORM\Parser\StaticNode;
10
use Cycle\ORM\Service\SourceProviderInterface;
11
use Cycle\ORM\SchemaInterface;
12
use Cycle\ORM\Select\Traits\ColumnsTrait;
13
use Cycle\ORM\Select\Traits\ScopeTrait;
14
15
/**
16
 * @internal
17
 */
18
final class UpdateLoader extends AbstractLoader
19
{
20
    use ColumnsTrait;
21
    use ScopeTrait;
22
23
    protected array $options = [
24
        'load' => true,
25
        'scope' => true,
26
    ];
27
28
    /**
29
     * @param non-empty-string $target Entity role or alias.
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
30
     */
31
    public function __construct(
32
        SchemaInterface $ormSchema,
33
        SourceProviderInterface $sourceProvider,
34
        FactoryInterface $factory,
35
        string $target,
36
    ) {
37
        parent::__construct($ormSchema, $sourceProvider, $factory, $target);
38
        $this->columns = $this->normalizeColumns($this->define(SchemaInterface::COLUMNS));
39
    }
40
41
    public function getAlias(): string
42
    {
43
        return $this->target;
44
    }
45
46
    public function loadData(AbstractNode $node, bool $includeRole = false): void
47
    {
48
        // loading child datasets
49
        foreach ($this->load as $relation => $loader) {
50
            $loader->loadData($node->getNode($relation), $includeRole);
51
        }
52
53
        // $this->loadHierarchy($node, $includeRole);
54
    }
55
56
    public function isLoaded(): bool
57
    {
58
        return true;
59
    }
60
61
    protected function initNode(): StaticNode
62
    {
63
        return new StaticNode($this->columnNames(), (array) $this->define(SchemaInterface::PRIMARY_KEY));
64
    }
65
}
66