Completed
Push — 1.x ( abde83...7c6f23 )
by Akihito
13s
created

CreatedResourceInterceptor::invoke()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 4
nop 1
crap 3
1
<?php
2
/**
3
 * This file is part of the BEAR.Package package.
4
 *
5
 * @license http://opensource.org/licenses/MIT MIT
6
 */
7
namespace BEAR\Package\Provide\Representation;
8
9
use Ray\Aop\MethodInterceptor;
10
use Ray\Aop\MethodInvocation;
11
12
class CreatedResourceInterceptor implements MethodInterceptor
13
{
14
    /**
15
     * @var CreatedResourceRenderer
16
     */
17
    private $renderer;
18
19 5
    public function __construct(CreatedResourceRenderer $renderer)
20
    {
21 5
        $this->renderer = $renderer;
22 5
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 4
    public function invoke(MethodInvocation $invocation)
28
    {
29 4
        $ro = $invocation->proceed();
30 4
        $isCreated = $ro->code === 201 && isset($ro->headers['Location']);
31 4
        if (! $isCreated) {
32 1
            return $ro;
33
        }
34 3
        $ro->setRenderer($this->renderer);
35
36 3
        return $ro;
37
    }
38
}
39