Application   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Test Coverage

Coverage 88.24%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 16
dl 0
loc 65
ccs 15
cts 17
cp 0.8824
rs 10
c 1
b 0
f 1
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A middleware() 0 21 1
A bootstrapCli() 0 9 2
A bootstrap() 0 15 3
1
<?php
2
/**
3
 * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
4
 * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
5
 *
6
 * Licensed under The MIT License
7
 * For full copyright and license information, please see the LICENSE.txt
8
 * Redistributions of files must retain the above copyright notice.
9
 *
10
 * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
11
 * @link      https://cakephp.org CakePHP(tm) Project
12
 * @since     3.3.0
13
 * @license   https://opensource.org/licenses/mit-license.php MIT License
14
 */
15
16
namespace App;
17
18
use Cake\Core\Configure;
19
use Cake\Core\Exception\MissingPluginException;
20
use Cake\Error\Middleware\ErrorHandlerMiddleware;
21
use Cake\Http\BaseApplication;
22
use Cake\Http\MiddlewareQueue;
23
use Cake\Routing\Middleware\AssetMiddleware;
24
use Cake\Routing\Middleware\RoutingMiddleware;
25
use DebugKit\Plugin;
26
27
use const PHP_SAPI;
28
29
/**
30
 * Application setup class.
31
 *
32
 * This defines the bootstrapping logic and middleware layers you
33
 * want to use in your application.
34
 */
35
class Application extends BaseApplication
36
{
37
    /**
38
     * {@inheritDoc}
39
     *
40
     * @return void
41
     */
42 168
    public function bootstrap(): void
43
    {
44
        // Call parent to load bootstrap from files.
45 168
        parent::bootstrap();
46
47 168
        if (PHP_SAPI === 'cli') {
48 168
            $this->bootstrapCli();
49
        }
50
51
        /*
52
         * Only try to load DebugKit in development mode
53
         * Debug Kit should not be installed on a production system
54
         */
55 168
        if (Configure::read('debug')) {
56
            $this->addPlugin(Plugin::class);
57
        }
58
59
        // Load more plugins here
60 168
    }
61
62
    /**
63
     * Setup the middleware queue your application will use.
64
     *
65
     * @param MiddlewareQueue $middlewareQueue The middleware queue to setup.
66
     * @return MiddlewareQueue The updated middleware queue.
67
     */
68 147
    public function middleware($middlewareQueue): MiddlewareQueue
69
    {
70
        $middlewareQueue
71
            // Catch any exceptions in the lower layers,
72
            // and make an error page/response
73 147
            ->add(new ErrorHandlerMiddleware(Configure::read('Error')))
74
75
            // Handle plugin/theme assets like CakePHP normally does.
76 147
            ->add(new AssetMiddleware([
77 147
                'cacheTime' => Configure::read('Asset.cacheTime'),
78
            ]))
79
80
            // Add routing middleware.
81
            // If you have a large number of routes connected, turning on routes
82
            // caching in production could improve performance. For that when
83
            // creating the middleware instance specify the cache config name by
84
            // using it's second constructor argument:
85
            // `new RoutingMiddleware($this, '_cake_routes_')`
86 147
            ->add(new RoutingMiddleware($this));
87
88 147
        return $middlewareQueue;
89
    }
90
91 168
    protected function bootstrapCli(): void
92
    {
93
        try {
94 168
            $this->addPlugin('Bake');
95
        } catch (MissingPluginException $e) {// phpcs:ignore
96
            // Do not halt if the plugin is missing
97
        }
98
99 168
        $this->addPlugin('Migrations');
100
101
        // Load more plugins here
102 168
    }
103
}
104