Passed
Push — master ( aebcb6...ddb17c )
by Alexander
07:50
created

Application   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 15
c 3
b 0
f 0
dl 0
loc 38
ccs 20
cts 20
cp 1
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 6 1
A shutdown() 0 3 1
A start() 0 4 1
A __construct() 0 8 1
A afterEmit() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Web;
6
7
use Psr\EventDispatcher\EventDispatcherInterface;
8
use Psr\Http\Message\ResponseInterface;
9
use Psr\Http\Message\ServerRequestInterface;
10
use Yiisoft\Yii\Web\ErrorHandler\ErrorHandler;
11
use Yiisoft\Yii\Web\Event\AfterEmit;
12
use Yiisoft\Yii\Web\Event\AfterRequest;
13
use Yiisoft\Yii\Web\Event\ApplicationShutdown;
14
use Yiisoft\Yii\Web\Event\ApplicationStartup;
15
use Yiisoft\Yii\Web\Event\BeforeRequest;
16
17
/**
18
 * Application is the entry point for a web application.
19
 * For more details and usage information on Application, see the [guide article on
20
 * applications](guide:structure-applications).
21
 */
22
final class Application
23
{
24
    private MiddlewareDispatcher $dispatcher;
25
    private EventDispatcherInterface $eventDispatcher;
26
    private ErrorHandler $errorHandler;
27
28 5
    public function __construct(
29
        MiddlewareDispatcher $dispatcher,
30
        ErrorHandler $errorHandler,
31
        EventDispatcherInterface $eventDispatcher
32
    ) {
33 5
        $this->dispatcher = $dispatcher;
34 5
        $this->errorHandler = $errorHandler;
35 5
        $this->eventDispatcher = $eventDispatcher;
36 5
    }
37
38 1
    public function start(): void
39
    {
40 1
        $this->errorHandler->register();
41 1
        $this->eventDispatcher->dispatch(new ApplicationStartup());
42 1
    }
43
44 1
    public function shutdown(): void
45
    {
46 1
        $this->eventDispatcher->dispatch(new ApplicationShutdown());
47 1
    }
48
49 2
    public function afterEmit(?ResponseInterface $response): void
50
    {
51 2
        $this->eventDispatcher->dispatch(new AfterEmit($response));
52 2
    }
53
54 1
    public function handle(ServerRequestInterface $request): ResponseInterface
55
    {
56 1
        $this->eventDispatcher->dispatch(new BeforeRequest($request));
57 1
        $response = $this->dispatcher->dispatch($request);
58 1
        $this->eventDispatcher->dispatch(new AfterRequest($response));
59 1
        return $response;
60
    }
61
}
62