RequestResolver::setResource()   A
last analyzed

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
2
3
namespace Knp\RadBundle\Resource\Resolver;
4
5
use Symfony\Component\HttpFoundation\Request;
6
use Knp\RadBundle\HttpFoundation\RequestManipulator;
7
8
class RequestResolver
9
{
10
    public function __construct(ResourceResolver $resourceResolver, RequestManipulator $requestManipulator = null)
11
    {
12
        $this->resourceResolver = $resourceResolver;
0 ignored issues
show
Bug introduced by
The property resourceResolver 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...
13
        $this->requestManipulator = $requestManipulator ?: new RequestManipulator();
0 ignored issues
show
Bug introduced by
The property requestManipulator 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...
14
    }
15
16
    public function resolveResource(Request $request, $name)
17
    {
18
        $options = $this->getResourceOptions($request, $name);
19
        $resource = $this->resourceResolver->resolveResource($request, $options);
20
        $this->setResource($request, $name, $resource);
21
22
        return $resource;
23
    }
24
25
    public function hasResourceOptions(Request $request, $name)
26
    {
27
        if (false === $this->requestManipulator->hasAttribute($request, '_resources')) {
28
            return false;
29
        }
30
31
        $resources = $this->requestManipulator->getAttribute($request, '_resources');
32
33
        return array_key_exists($name, $resources);
34
    }
35
36
    public function getResourceOptions(Request $request, $name)
37
    {
38
        $resources = $this->requestManipulator->getAttribute($request, '_resources');
39
40
        return $resources[$name];
41
    }
42
43
    public function setResource(Request $request, $name, $resource)
44
    {
45
        $this->requestManipulator->setAttribute($request, $name, $resource);
46
    }
47
}
48