ExamplesComponent   B
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 16

Importance

Changes 0
Metric Value
dl 0
loc 63
rs 8.4614
c 0
b 0
f 0
wmc 7
lcom 1
cbo 16

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 4 1
B onDispatch() 0 22 5
A onRender() 0 18 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 24 and the first side effect is on line 19.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Webino Examples
4
 */
5
6
use WebinoAppLib\Event\DispatchEvent;
7
use WebinoAppLib\Event\RouteEvent;
8
use WebinoAppLib\Response\ViewResponse;
9
use WebinoAppLib\Router\DefaultRoute;
10
use WebinoAppLib\View\SourcePreviewComponent;
11
use WebinoDomLib\Event\RenderEvent;
12
use WebinoHtmlLib\Html;
13
use WebinoViewLib\Component\AbstractViewComponent;
14
use WebinoViewLib\Component\OnDispatchInterface;
15
use WebinoViewLib\Component\Stylesheet;
16
use WebinoViewLib\Feature\CommonView;
17
use WebinoViewLib\Feature\NodeView;
18
19
require __DIR__ . '/../vendor/autoload.php';
20
21
/**
22
 * Custom view component
23
 */
24
class ExamplesComponent extends AbstractViewComponent implements OnDispatchInterface
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
25
{
26
    /**
27
     * @var string
28
     */
29
    private $api;
30
31
    /**
32
     * @param NodeView $node
33
     */
34
    public function configure(NodeView $node)
35
    {
36
        $node->setLocator('examples');
37
    }
38
39
    /**
40
     * @param DispatchEvent $event
41
     */
42
    public function onDispatch(DispatchEvent $event)
43
    {
44
        $examples = [];
45
        foreach ($event->getApp()->file()->listContents() as $info) {
46
            if ('dir' !== $info['type']) {
47
                continue;
48
            }
49
50
            list($section) = explode('-', $info['filename'], 2);
51
            $label = ucwords(str_replace('-', ' ', $info['filename']));
52
            $examples[ucfirst($section)][] = new Html\Url($info['filename'], $label) . new Html\LineBreak;
53
        }
54
55
        $this->api = '';
56
        foreach ($examples as $section => $items) {
57
            $this->api .= new Html\Title4($section);
58
            foreach ($items as $item) {
59
                $this->api .= $item;
60
            }
61
            $this->api .= new Html\LineBreak;
62
        }
63
    }
64
65
    /**
66
     * @param RenderEvent $event
67
     */
68
    public function onRender(RenderEvent $event)
69
    {
70
        $col = (new Html\Block)->setClass('col-md-4');
71
72
        $event->getNode()->replace([
73
            (new Html\Block([
74
                new Html\Title('Webino Examples'),
75
76
                (new Html\Text('Showcase of :link prototype usage.'))
77
                    ->format([':link' => new Html\Url('https://github.com/webino/Webino', 'Webino™')])
78
            ]))->setClass('text-center'),
79
80
            new Html\HorizontalLine,
81
            (clone $col)->setValue(new Html\FieldSet(new Html\Title2('API'), new Html\Html($this->api))),
82
            (clone $col)->setValue(new Html\FieldSet(new Html\Title2('Cookbook'), 'TODO...')),
83
            (clone $col)->setValue(new Html\FieldSet(new Html\Title2('Applications'), 'TODO...')),
84
        ]);
85
    }
86
}
87
88
$config = Webino::config([
89
    new CommonView([
90
        new Stylesheet\BootstrapV3,
91
        new SourcePreviewComponent(__FILE__),
92
93
        (new NodeView('content'))
94
            ->setLocator('body')
95
            ->setHtml('<div class="container jumbotron"><examples/></div><source-preview/>'),
96
97
        new ExamplesComponent,
98
    ]),
99
]);
100
101
$app = Webino::application($config, Webino::debugger(Webino::debuggerOptions()->setBar()))->bootstrap();
102
103
$app->bind(DefaultRoute::class, function (RouteEvent $event) {
104
    $event->setResponse(new ViewResponse);
105
});
106
107
$app->dispatch();
108