Passed
Push — master ( 2af18a...ebd8c1 )
by Alexander
03:43
created

View   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 5
eloc 8
c 2
b 1
f 0
dl 0
loc 35
ccs 13
cts 13
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createAfterRenderEvent() 0 6 1
A createBeforeRenderEvent() 0 3 1
A beginPage() 0 7 2
A endPage() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\View;
6
7
use Psr\EventDispatcher\StoppableEventInterface;
8
use Yiisoft\View\Event\AfterRenderEventInterface;
9
use Yiisoft\View\Event\View\AfterRender;
10
use Yiisoft\View\Event\View\BeforeRender;
11
use Yiisoft\View\Event\View\PageBegin;
12
use Yiisoft\View\Event\View\PageEnd;
13
14
/**
15
 * View represents a view object in the MVC pattern.
16
 *
17
 * View provides a set of methods (e.g. {@see View::render()}) for rendering purpose.
18
 *
19
 * For more details and usage information on View, see the [guide article on views](guide:structure-views).
20
 */
21
final class View extends BaseView
22
{
23
    /**
24
     * Marks the beginning of a view.
25
     */
26 1
    public function beginPage(): void
27
    {
28 1
        ob_start();
29
        /** @psalm-suppress PossiblyFalseArgument */
30 1
        PHP_VERSION_ID >= 80000 ? ob_implicit_flush(false) : ob_implicit_flush(0);
31
32 1
        $this->eventDispatcher->dispatch(new PageBegin($this));
33 1
    }
34
35
    /**
36
     * Marks the ending of a view.
37
     */
38 1
    public function endPage(): void
39
    {
40 1
        $this->eventDispatcher->dispatch(new PageEnd($this));
41
42 1
        ob_end_flush();
43 1
    }
44
45 6
    protected function createBeforeRenderEvent(string $viewFile, array $parameters): StoppableEventInterface
46
    {
47 6
        return new BeforeRender($this, $viewFile, $parameters);
48
    }
49
50 6
    protected function createAfterRenderEvent(
51
        string $viewFile,
52
        array $parameters,
53
        string $result
54
    ): AfterRenderEventInterface {
55 6
        return new AfterRender($this, $viewFile, $parameters, $result);
56
    }
57
}
58