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

CreatedResourceInterceptor   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 27
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A invoke() 0 11 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