Completed
Push — master ( 2eb0ca...af375c )
by Marko
14s
created

HelperController::setObjectFieldValueAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 44 and the first side effect is on line 31.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\AdminBundle\Controller;
15
16
use Sonata\AdminBundle\Action\AppendFormFieldElementAction;
17
use Sonata\AdminBundle\Action\GetShortObjectDescriptionAction;
18
use Sonata\AdminBundle\Action\RetrieveAutocompleteItemsAction;
19
use Sonata\AdminBundle\Action\RetrieveFormFieldElementAction;
20
use Sonata\AdminBundle\Action\SetObjectFieldValueAction;
21
use Sonata\AdminBundle\Admin\AdminHelper;
22
use Sonata\AdminBundle\Admin\Pool;
23
use Symfony\Component\HttpFoundation\JsonResponse;
24
use Symfony\Component\HttpFoundation\Request;
25
use Symfony\Component\HttpFoundation\Response;
26
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
27
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
28
use Symfony\Component\Validator\Validator\ValidatorInterface;
29
use Twig\Environment;
30
31
@trigger_error(
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
32
    'The '.__NAMESPACE__.'\HelperController class is deprecated since version 3.x and will be removed in 4.0.'
33
    .' Use actions inside Sonata\AdminBundle\Action instead.',
34
    E_USER_DEPRECATED
35
);
36
37
/**
38
 * NEXT_MAJOR: remove this class.
39
 *
40
 * @deprecated since version 3.1, to be removed in 4.0. Use Sonata\AdminBundle\AbstractAdmin instead
41
 *
42
 * @author Thomas Rabaix <[email protected]>
43
 */
44
class HelperController
45
{
46
    /**
47
     * @var \Twig_Environment
48
     */
49
    protected $twig;
50
51
    /**
52
     * @var AdminHelper
53
     */
54
    protected $helper;
55
56
    /**
57
     * @var Pool
58
     */
59
    protected $pool;
60
61
    /**
62
     * @var ValidatorInterface
63
     */
64
    protected $validator;
65
66
    /**
67
     * @param ValidatorInterface $validator
68
     */
69
    public function __construct(Environment $twig, Pool $pool, AdminHelper $helper, $validator)
70
    {
71
        // NEXT_MAJOR: Move ValidatorInterface check to method signature
72
        if (!($validator instanceof ValidatorInterface)) {
73
            throw new \InvalidArgumentException(
74
                'Argument 4 is an instance of '.get_class($validator).', expecting an instance of'
75
                .' \Symfony\Component\Validator\Validator\ValidatorInterface'
76
            );
77
        }
78
79
        $this->twig = $twig;
80
        $this->pool = $pool;
81
        $this->helper = $helper;
82
        $this->validator = $validator;
83
    }
84
85
    /**
86
     * @throws NotFoundHttpException
87
     *
88
     * @return Response
89
     */
90
    public function appendFormFieldElementAction(Request $request)
91
    {
92
        $action = new AppendFormFieldElementAction($this->twig, $this->pool, $this->helper);
0 ignored issues
show
Compatibility introduced by
$this->twig of type object<Twig_Environment> is not a sub-type of object<Twig\Environment>. It seems like you assume a child class of the class Twig_Environment to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
93
94
        return $action($request);
95
    }
96
97
    /**
98
     * @throws NotFoundHttpException
99
     *
100
     * @return Response
101
     */
102
    public function retrieveFormFieldElementAction(Request $request)
103
    {
104
        $action = new RetrieveFormFieldElementAction($this->twig, $this->pool, $this->helper);
0 ignored issues
show
Compatibility introduced by
$this->twig of type object<Twig_Environment> is not a sub-type of object<Twig\Environment>. It seems like you assume a child class of the class Twig_Environment to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
105
106
        return $action($request);
107
    }
108
109
    /**
110
     * @throws NotFoundHttpException|\RuntimeException
111
     *
112
     * @return Response
113
     */
114
    public function getShortObjectDescriptionAction(Request $request)
115
    {
116
        $action = new GetShortObjectDescriptionAction($this->twig, $this->pool);
0 ignored issues
show
Compatibility introduced by
$this->twig of type object<Twig_Environment> is not a sub-type of object<Twig\Environment>. It seems like you assume a child class of the class Twig_Environment to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
117
118
        return $action($request);
119
    }
120
121
    /**
122
     * @return Response
123
     */
124
    public function setObjectFieldValueAction(Request $request)
125
    {
126
        $action = new SetObjectFieldValueAction($this->twig, $this->pool, $this->validator);
0 ignored issues
show
Compatibility introduced by
$this->twig of type object<Twig_Environment> is not a sub-type of object<Twig\Environment>. It seems like you assume a child class of the class Twig_Environment to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
127
128
        return $action($request);
129
    }
130
131
    /**
132
     * Retrieve list of items for autocomplete form field.
133
     *
134
     * @throws \RuntimeException
135
     * @throws AccessDeniedException
136
     *
137
     * @return JsonResponse
138
     */
139
    public function retrieveAutocompleteItemsAction(Request $request)
140
    {
141
        $action = new RetrieveAutocompleteItemsAction($this->pool);
142
143
        return $action($request);
144
    }
145
}
146