Completed
Branch v2.0.0 (addc15)
by Alexander
03:27
created

Router   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 35
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 8 1
A handleNotFound() 0 11 1
A index() 0 11 1
1
<?php
2
/**
3
 * @author Alexander Torosh <[email protected]>
4
 */
5
6
namespace Api;
7
8
use Api\Controllers\IndexController;
9
use Api\Exception\NotFoundException;
10
use Phalcon\Mvc\Micro;
11
use Phalcon\Mvc\Micro\Collection as MicroCollection;
12
13
class Router
14
{
15
    public function init(Micro $app)
16
    {
17
        // Not Found
18
        $app = $this->handleNotFound($app);
19
20
        // Mount Routes
21
        $app->mount($this->index());
22
    }
23
24
    private function handleNotFound(Micro $app): Micro
25
    {
26
        // Not Found
27
        $app->notFound(
28
            function () use ($app) {
29
                throw new NotFoundException('Page Not Found', 404);
30
            }
31
        );
32
33
        return $app;
34
    }
35
36
    private function index(): MicroCollection
37
    {
38
        $collection = new MicroCollection();
39
        $collection->setHandler(IndexController::class, true);
40
        $collection->setPrefix('/api');
41
42
        $collection->get('/', 'index');
43
        $collection->get('/test', 'test');
44
45
        return $collection;
46
    }
47
}
48