Passed
Push — master ( 789ab6...490312 )
by Brian
01:34 queued 11s
created

Plugin::middleware()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 5
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Plugin Definitions
4
 */
5
6
namespace Fr3nch13\Jira;
7
8
use Cake\Core\BasePlugin;
9
use Cake\Core\Configure;
10
use Cake\Core\Configure\Engine\PhpConfig;
11
use Cake\Core\PluginApplicationInterface;
12
use Cake\Event\EventManager;
13
use Cake\Routing\RouteBuilder;
14
use Cake\Routing\Router;
15
use Cake\Routing\Route\DashedRoute;
16
17
/**
18
 * Plugin Definitions
19
 */
20
class Plugin extends BasePlugin
21
{
22
    /**
23
     * Bootstraping for this specific plugin.
24
     *
25
     * @param \Cake\Core\PluginApplicationInterface $app The app object.
26
     * @return void
27
     */
28 22
    public function bootstrap(PluginApplicationInterface $app)
29
    {
30
        // Add constants, load configuration defaults,
31
        // and initiate any required cakephp plugins.
32
33
        // detect which major version of php we're running,
34
        // and only filter if the version is greater than 7.
35 22
        $jiraHost = env('JIRA_HOST', false);
36 22
        if ($jiraHost) {
37 22
            $version = explode('.', PHP_VERSION);
38 22
            if ((int)$version[0] >= 7) {
39 22
                $jiraHost = filter_var($jiraHost, FILTER_VALIDATE_DOMAIN);
40
            }
41
        }
42
43 22
        if (!Configure::read('Jira')) {
44 22
            Configure::write('Jira', [
45 22
                'schema' => env('JIRA_SCHEMA', 'https'),
46 22
                'host' => $jiraHost,
47 22
                'username' => env('JIRA_USERNAME', null),
48 22
                'apiKey' => env('JIRA_API_KEY', null),
49 22
                'projectKey' => env('JIRA_PROJECT_KEY', null),
50
            ]);
51
        }
52
53
        // By default will load `config/bootstrap.php` in the plugin.
54 22
        parent::bootstrap($app);
55 22
    }
56
57
    /**
58
     * Add plugin specific routes here.
59
     *
60
     * @param object $routes The passed routes object.
61
     * @return void
62
     */
63 3
    public function routes($routes)
64
    {
65
        // Add routes.
66 3
        Router::plugin(
67 3
            'Fr3nch13/Jira',
68 3
            ['path' => '/jira'],
69 3
            function (RouteBuilder $routes) {
70 3
                $routes->fallbacks(DashedRoute::class);
71 3
            }
72
        );
73
74
        // By default will load `config/routes.php` in the plugin.
75
        parent::routes($routes);
76
    }
77
}
78