Completed
Pull Request — master (#42)
by Daniel
01:54
created

GridMetadata::getQuery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Psi\Component\Grid\Metadata;
6
7
final class GridMetadata
8
{
9
    private $name;
10
    private $columns;
11
    private $pageSize;
12
    private $filters;
13
    private $actions;
14
    private $query;
15
    private $classMetadata;
16
17
    public function __construct(string $name, array $columns, array $filters, array $actions, int $pageSize, string $query = null)
18
    {
19
        $this->name = $name;
20
        $this->columns = $columns;
21
        $this->filters = $filters;
22
        $this->actions = $actions;
23
        $this->pageSize = $pageSize;
24
        $this->query = $query;
25
    }
26
27
    public function getName(): string
28
    {
29
        return $this->name;
30
    }
31
32
    public function getColumns(): array
33
    {
34
        return $this->columns;
35
    }
36
37
    public function getPageSize(): int
38
    {
39
        return $this->pageSize;
40
    }
41
42
    public function getFilters(): array
43
    {
44
        return $this->filters;
45
    }
46
47
    public function getActions(): array
48
    {
49
        return $this->actions;
50
    }
51
52
    public function attachClassMetadata(ClassMetadata $classMetadata)
53
    {
54
        if ($this->classMetadata) {
55
            throw new \RuntimeException(
56
                'Class metadata has already been attached to grid metadata.'
57
            );
58
        }
59
60
        $this->classMetadata = $classMetadata;
61
    }
62
63
    public function getClassMetadata()
64
    {
65
        if (!$this->classMetadata) {
66
            throw new \RuntimeException('Class metadata has not been attached to grid.');
67
        }
68
69
        return $this->classMetadata;
70
    }
71
72
    public function hasQuery(): bool
73
    {
74
        return null !== $this->query;
75
    }
76
77
    public function getQuery(): string
78
    {
79
        return $this->query;
80
    }
81
}
82