Failed Conditions
Pull Request — master (#246)
by Maximo
02:52
created

Api::handleException()   B

Complexity

Conditions 7
Paths 16

Size

Total Lines 31

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 0
Metric Value
cc 7
nc 16
nop 1
dl 0
loc 31
ccs 0
cts 26
cp 0
crap 56
rs 8.4906
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Canvas\Bootstrap;
6
7
use function Canvas\Core\appPath;
8
use Phalcon\Di\FactoryDefault;
9
use Phalcon\Mvc\Micro;
10
use Canvas\Http\Response;
11
use Throwable;
12
13
/**
14
 * Class Api.
15
 *
16
 * @package Canvas\Bootstrap
17
 *
18
 * @property Micro $application
19
 */
20
class Api extends AbstractBootstrap
21
{
22
    /**
23
     * Run the application.
24
     *
25
     * @return mixed
26
     */
27
    public function run()
28
    {
29
        try {
30
            return $this->application->handle();
31
        } catch (Throwable $e) {
32
            $response = new Response();
33
            $response->handleException($e)->send();
34
        }
35
    }
36
37
    /**
38
     * @return mixed
39
     */
40
    public function setup()
41
    {
42
        //set the default DI
43
        $this->container = new FactoryDefault();
44
        //set all the services
45
46
        /**
47
        * @todo Find a better way to handle unit test file include
48
        */
49
        $this->providers = require appPath('api/config/providers.php');
50
51
        //run my parents setup
52
        parent::setup();
53
    }
54
}
55