Completed
Pull Request — master (#5)
by Daniel
01:51
created

Table   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 3
dl 0
loc 43
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A getHeaders() 0 14 3
A getBody() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Psi\Component\Grid;
6
7
use Psi\Component\Grid\Metadata\GridMetadata;
8
use Psi\Component\View\ViewFactory;
9
10
class Table
11
{
12
    private $viewFactory;
13
    private $gridMetadata;
14
    private $collection;
15
    private $orderings;
16
17
    public function __construct(
18
        ViewFactory $viewFactory,
19
        GridMetadata $gridMetadata,
20
        \Traversable $collection,
21
        array $orderings
22
    ) {
23
        $this->viewFactory = $viewFactory;
24
        $this->gridMetadata = $gridMetadata;
25
        $this->collection = $collection;
26
        $this->orderings = $orderings;
27
    }
28
29
    public function getHeaders()
30
    {
31
        $headers = [];
32
        foreach(array_keys($this->gridMetadata->getColumns()) as $headerName) {
33
            $sort = null;
34
            if (isset($this->orderings[$headerName])) {
35
                $sort = $this->orderings[$headerName];
36
            }
37
38
            $headers[$headerName] = new Header($headerName, null !== $sort, $sort === 'asc');
39
        }
40
41
        return $headers;
42
    }
43
44
    public function getBody()
45
    {
46
        return new Body(
47
            $this->viewFactory,
48
            $this->gridMetadata,
49
            $this->collection
50
        );
51
    }
52
}
53