Passed
Push — master ( 863ad3...126876 )
by Enrico
02:01
created

Application::resetMiddlewaresQueue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 5
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php 
2
3
/*
4
 * This file is part of the uSilex framework.
5
 *
6
 * (c) Enrico Fagnoni <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace uSilex;
13
14
use Psr\Http\Message\ServerRequestInterface;
15
use Psr\Http\Message\ResponseInterface;
16
use InvalidArgumentException;
17
18
19
class Application extends HttpKernel
20
{
21
    use \uSilex\Pimple\BootManagerTrait;
22
    
23
    /**
24
     * Handles the request and delivers the response.
25
     *
26
     */
27 4
    public function run(string $middlewareServiceName = null) : bool
28
    {
29
        
30 4
        if( !isset($this['request']) ) {
31 1
            throw new InvalidArgumentException('request service must be defined');
32
        }
33 3
        $request = $this['request'];
34
        
35 3
        if( !($request instanceof ServerRequestInterface) ) {
36 1
            throw new InvalidArgumentException('request is not an http server request');
37
        }
38
          
39
        // auto service registration
40 2
        if( $middlewareServiceName ) {
41 2
            $this->registerAsMiddleware($middlewareServiceName);
42
        }
43
     
44 2
        $response = $this->boot()->handle($request);
45 2
        $response = $this->handleResponse($response);
46
        
47 2
        if( isset($this['responseEmitter']) && is_callable($this['responseEmitter'])) {
48 2
            call_user_func($this['responseEmitter'],$response);
49
        } else {
50
            var_dump($response);
1 ignored issue
show
Security Debugging Code introduced by
var_dump($response) looks like debug code. Are you sure you do not want to remove it?
Loading history...
51
        }
52
        
53 2
        return true;
54
    }
55
    
56
}