Completed
Pull Request — master (#6194)
by Vincent
05:04
created

PolyfillControllerTrait::__call()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
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 Symfony\Bundle\FrameworkBundle\Controller\Controller;
17
use Symfony\Bundle\FrameworkBundle\Controller\ControllerTrait;
18
use Symfony\Component\DependencyInjection\ContainerInterface;
19
use Symfony\Component\HttpFoundation\Response;
20
21
/**
22
 * Polyfills the FrameworkBundle's original ControllerTrait.
23
 *
24
 * NEXT_MAJOR: Remove this file.
25
 *
26
 * @author Christian Kraus <[email protected]>
27
 */
28
trait PolyfillControllerTrait
29
{
30
    public function __call($methodName, $arguments)
31
    {
32
        $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...
33
    }
34
35
    public function render($view, array $parameters = [], ?Response $response = null)
36
    {
37
        return $this->__call('render', [$view, $parameters, $response]);
38
    }
39
40
    /**
41
     * @internal
42
     */
43
    final protected function proxyToControllerClass($methodName, $arguments)
44
    {
45
        if (!method_exists(Controller::class, $methodName)) {
46
            throw new \LogicException(sprintf('Call to undefined method %s::%s', __CLASS__, $methodName));
47
        }
48
49
        $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...
50
51
        return $controller->proxyCall($methodName, $arguments);
52
    }
53
}
54
55
class PolyfillProxyContainer extends Controller
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Bundle\Framework...e\Controller\Controller has been deprecated with message: since Symfony 4.2, use "Symfony\Bundle\FrameworkBundle\Controller\AbstractController" instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

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