Completed
Push — master ( 65c91b...7e9231 )
by Guillaume
15:59
created

TemplateController::putAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
dl 7
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
namespace Starkerxp\CampagneBundle\Controller;
4
5
6
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7
use Symfony\Component\HttpFoundation\JsonResponse;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\OptionsResolver\OptionsResolver;
10
11
12
class TemplateController extends Controller
13
{
14
15
    public function cgetAction(Request $request)
16
    {
17
        $manager = $this->get("starkerxp_campagne.manager.template");
18
        try {
19
            $options = $this->resolveParams()->resolve($request->query->all());
20
21
            $orderBy = !empty($options['sort']) ? array_map(
22
                function ($r) {
23
                    return [substr($r, 1) => substr($r, 0, 1) == '+' ? 'ASC' : 'DESC'];
24
                },
25
                explode(',', $options['sort'])
26
            ) : [];
27
28
            $manager->findBy([], $orderBy, $options['limit'], $options['offset']);
29
        } catch (\Exception $e) {
30
            return new JsonResponse(["payload" => $e->getMessage()], 400); //400
31
        }
32
33
        return new JsonResponse(["payload" => $options]); //400
34
    }
35
36
    public function resolveParams()
37
    {
38
        $resolver = new OptionsResolver();
39
        $resolver->setDefaults(
40
            [
41
                'offset' => 0,
42
                'limit'  => 15,
43
                //'fields' => "*",
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
44
                'sort'   => "",
45
                //'filter' => "",
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
46
            ]
47
        );
48
49
        return $resolver;
50
    }
51
52
    public function getAction(Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
53
    {
54
        $manager = $this->get("starkerxp_campagne.manager.template");
0 ignored issues
show
Unused Code introduced by
$manager is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
55
56
        return new JsonResponse(["payload" => []]);//400
57
    }
58
59 View Code Duplication
    public function postAction(Request $request)
0 ignored issues
show
Duplication introduced by
This method 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...
60
    {
61
        $manager = $this->get("starkerxp_campagne.manager.template");
62
        $options = $manager->getPostOptionResolver()->resolve($request->request->all());
0 ignored issues
show
Unused Code introduced by
$options is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
63
64
        return new JsonResponse(["payload" => ""], 201);//400
65
    }
66
67 View Code Duplication
    public function putAction(Request $request)
0 ignored issues
show
Duplication introduced by
This method 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...
68
    {
69
        $manager = $this->get("starkerxp_campagne.manager.template");
70
        $options = $manager->getPutOptionResolver()->resolve($request->request->all());
0 ignored issues
show
Unused Code introduced by
$options is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
71
72
        return new JsonResponse(["payload" => ""], 303); //400
73
    }
74
75
    public function deleteAction(Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
76
    {
77
        $manager = $this->get("starkerxp_campagne.manager.template");
0 ignored issues
show
Unused Code introduced by
$manager is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
78
79
        return new JsonResponse(["payload" => ""], 204); //404 /400
80
    }
81
82
}
83