Completed
Push — ezp26297-rest_embedding_http_c... ( 123323 )
by
unknown
80:28 queued 54:58
created

CachedValueUnwrapperController::__call()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 2
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
4
 * @license For full copyright and license information view LICENSE file distributed with this source code.
5
 */
6
namespace eZ\Publish\Core\REST\Server\HttpCache\Controller;
7
8
use eZ\Publish\Core\REST\Server\Values\CachedValue;
9
10
/**
11
 * A proxy controller that unwraps value objects from CachedValue objects.
12
 *
13
 * Used to deprecate returning a CachedValue from a controller directly,
14
 * and enforce usage of an HttpCache proxy controller.
15
 */
16
class CachedValueUnwrapperController
17
{
18
    private $innerController;
19
20
    public function __construct($innerController)
21
    {
22
        $this->innerController = $innerController;
23
    }
24
25
    public function __call($method, $arguments)
26
    {
27
        $value = call_user_func_array([$this->innerController, $method], $arguments);
28
29
        if ($value instanceof CachedValue) {
30
            @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...
31
                'Returning CachedValue objects from REST controllers is deprecated',
32
                E_USER_DEPRECATED
33
            );
34
            return $value->value;
35
        } else {
36
            return $value;
37
        }
38
    }
39
}
40