SetEncodingAttributeMiddlewareFactory   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 15
ccs 6
cts 6
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 11 1
1
<?php
2
3
namespace Alchemy\RestProvider\Middleware;
4
5
use Symfony\Component\HttpFoundation\Request;
6
7
class SetEncodingAttributeMiddlewareFactory
8
{
9
10
    public function __invoke($decodeRequest = true, $encodeResponse = true)
11
    {
12 4
        return function (Request $request) use ($decodeRequest, $encodeResponse) {
13 4
            $restAttribute = $request->attributes->get('_rest', array());
14
15 4
            $restAttribute['decode_request'] = (bool) $decodeRequest;
16 4
            $restAttribute['encode_response'] = (bool) $encodeResponse;
17
18 4
            $request->attributes->set('_rest', $restAttribute);
19 4
        };
20
    }
21
}
22