Completed
Push — master ( f1b857...d82134 )
by Nils
02:25
created

Datatable110Version   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 5
Bugs 0 Features 2
Metric Value
wmc 4
c 5
b 0
f 2
lcom 0
cbo 6
dl 49
loc 49
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A createResponse() 13 13 1
A tableView() 4 4 1
A scriptView() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\Datatable110QueryParser;
9
use OpenSkill\Datatable\Queries\QueryConfiguration;
10
use Symfony\Component\HttpFoundation\JsonResponse;
11
use Symfony\Component\HttpFoundation\RequestStack;
12
13
/**
14
 * Class Datatable110Version
15
 * @package OpenSkill\Datatable\Versions
16
 *
17
 * Version that supports the 1.10 version of datatables
18
 * http://datatables.net/index
19
 *
20
 */
21 View Code Duplication
class Datatable110Version extends DatatableVersion
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
22
{
23
    /**
24
     * Datatable110Version constructor.
25
     *
26
     * @param RequestStack $requestStack The current request
27
     */
28
    public function __construct(RequestStack $requestStack)
29
    {
30
        parent::__construct($requestStack, new Datatable110QueryParser());
31
    }
32
33
    /**
34
     * Is responsible to take the generated data and prepare a response for it.
35
     * @param ResponseData $data The processed data.
36
     * @param QueryConfiguration $queryConfiguration the query configuration for the current request.
37
     * @param ColumnConfiguration[] $columnConfigurations the column configurations for the current data table.
38
     * @return JsonResponse the response that should be returned to the client.
39
     */
40
    public function createResponse(
41
        ResponseData $data,
42
        QueryConfiguration $queryConfiguration,
43
        array $columnConfigurations
44
    ) {
45
        $responseData = [
46
            'draw' => $queryConfiguration->drawCall(),
47
            'recordsTotal' => $data->totalDataCount(),
48
            'recordsFiltered' => $data->data()->count(),
49
            'data' => $data->data()->toArray()
50
        ];
51
        return new JsonResponse($responseData);
52
    }
53
54
    /**
55
     * @return string The name of the view that this version should use fot the table.
56
     */
57
    public function tableView()
58
    {
59
        return "datatable::table";
60
    }
61
62
    /**
63
     * @return string The name of the view that this version should use for the script.
64
     */
65
    public function scriptView()
66
    {
67
        return "datatable::datatable110";
68
    }
69
}