Completed
Push — master ( 724c66...28e474 )
by Tim
03:54 queued 01:56
created

DatatableVersion   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 5
c 2
b 0
f 1
lcom 1
cbo 3
dl 0
loc 55
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A canParseRequest() 0 4 1
A parseRequest() 0 4 1
A getRequest() 0 9 2
1
<?php
2
3
namespace OpenSkill\Datatable\Versions;
4
5
6
use OpenSkill\Datatable\Columns\ColumnConfiguration;
7
use OpenSkill\Datatable\Data\ResponseData;
8
use OpenSkill\Datatable\Queries\Parser\QueryParser;
9
use OpenSkill\Datatable\Queries\QueryConfiguration;
10
use Symfony\Component\HttpFoundation\JsonResponse;
11
use Symfony\Component\HttpFoundation\RequestStack;
12
13
abstract class DatatableVersion extends Version
14
{
15
    /**
16
     * @var QueryParser
17
     */
18
    protected $queryParser;
19
20
    /**
21
     * DatatableVersion constructor.
22
     * @param RequestStack $requestStack
23
     * @param QueryParser $queryParser
24
     */
25
    public function __construct(RequestStack $requestStack, QueryParser $queryParser)
26
    {
27
        parent::__construct($requestStack);
28
        $this->queryParser = $queryParser;
29
    }
30
31
    /**
32
     * Method to determine if this parser can handle the query parameters. If so then the parser should return true
33
     * and be able to return a DTQueryConfiguration
34
     *
35
     * @return bool true if the parser is able to parse the query parameters and to return a DTQueryConfiguration
36
     */
37
    public function canParseRequest()
38
    {
39
        return $this->queryParser->canParse($this->getRequest());
40
    }
41
42
    /**
43
     * Method that should parse the request and return a DTQueryConfiguration
44
     *
45
     * @param ColumnConfiguration[] $columnConfiguration The configuration of the columns
46
     * @return QueryConfiguration the configuration the provider can use to prepare the data
47
     */
48
    public function parseRequest(array $columnConfiguration)
49
    {
50
        return $this->queryParser->parse($this->getRequest(), $columnConfiguration);
51
    }
52
53
    /**
54
     * Get the request out of the request stack
55
     * @return \Symfony\Component\HttpFoundation\Request
56
     * @throws \InvalidArgumentException when the current request is empty/null
57
     */
58
    private function getRequest()
59
    {
60
        $request = $this->requestStack->getCurrentRequest();
61
        if (is_null($request)) {
62
            throw new \InvalidArgumentException("Can not parse a request that is null");
63
        }
64
65
        return $request;
66
    }
67
}