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

GridMetadata   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 0
Metric Value
wmc 12
lcom 2
cbo 0
dl 0
loc 75
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getName() 0 4 1
A getColumns() 0 4 1
A getPageSize() 0 4 1
A getFilters() 0 4 1
A getActions() 0 4 1
A attachClassMetadata() 0 10 2
A getClassMetadata() 0 8 2
A hasQuery() 0 4 1
A getQuery() 0 4 1
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