Completed
Push — 3.x ( 5349d6...5ea965 )
by Grégoire
04:11
created

PolyfillControllerTrait::render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 3
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 26 and the first side effect is on line 67.

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
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\AdminBundle\Controller;
13
14
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
15
use Symfony\Bundle\FrameworkBundle\Controller\ControllerTrait;
16
use Symfony\Component\DependencyInjection\ContainerInterface;
17
use Symfony\Component\HttpFoundation\Response;
18
19
/**
20
 * Polyfills the FrameworkBundle's original ControllerTrait.
21
 *
22
 * NEXT_MAJOR: Remove this file.
23
 *
24
 * @author Christian Kraus <[email protected]>
25
 */
26
trait PolyfillControllerTrait
27
{
28
    public function __call($methodName, $arguments)
29
    {
30
        $this->proxyToController($methodName, $arguments);
0 ignored issues
show
Bug introduced by
The method proxyToController() does not exist on Sonata\AdminBundle\Contr...PolyfillControllerTrait. Did you maybe mean proxyToControllerClass()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
31
    }
32
33
    public function render($view, array $parameters = [], Response $response = null)
34
    {
35
        return $this->__call('render', [$view, $parameters, $response]);
36
    }
37
38
    /**
39
     * @internal
40
     */
41
    final protected function proxyToControllerClass($methodName, $arguments)
42
    {
43
        if (!method_exists(Controller::class, $methodName)) {
44
            throw new \LogicException('Call to undefined method '.__CLASS__.'::'.$methodName);
45
        }
46
47
        $controller = new PolyfillProxyContainer($this->container);
0 ignored issues
show
Bug introduced by
The property container does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
48
49
        return $controller->proxyCall($methodName, $arguments);
50
    }
51
}
52
53
class PolyfillProxyContainer extends Controller
0 ignored issues
show
Coding Style Compatibility introduced by
Each trait must be in a file by itself

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
54
{
55
    public function __construct(ContainerInterface $container)
56
    {
57
        $this->setContainer($container);
58
    }
59
60
    public function proxyCall($method, $arguments)
61
    {
62
        return call_user_func_array([$this, $method], $arguments);
63
    }
64
}
65
66
if (!trait_exists(ControllerTrait::class)) {
67
    class_alias(PolyfillControllerTrait::class, ControllerTrait::class);
68
}
69