BugsnagController   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
eloc 18
c 3
b 0
f 1
dl 0
loc 34
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 16 1
A initial() 0 4 1
1
<?php
2
3
namespace Violet88\BugsnagModule;
4
5
use Psr\Container\NotFoundExceptionInterface;
6
use RuntimeException;
7
use SilverStripe\Control\Controller;
8
use SilverStripe\Control\HTTPResponse;
9
use SilverStripe\Core\Injector\Injector;
10
11
class BugsnagController extends Controller
12
{
13
    private static $allowed_actions = [
14
        'build',
15
        'initial'
16
    ];
17
18
    /**
19
     * Simply sends the given release to Bugsnag, to be used in CLI.
20
     *
21
     * @throws NotFoundExceptionInterface
22
     */
23
    public function build(): HTTPResponse
24
    {
25
        $repository = $_GET['repository'] ?? null;
26
        $revision = $_GET['revision'] ?? null;
27
        $provider = $_GET['provider'] ?? null;
28
        $builderName = $_GET['builderName'] ?? null;
29
        $appVersion = $_GET['revision'] ?? null;
30
31
        $bugsnag = Injector::inst()->get(Bugsnag::class);
32
        $bugsnag
33
            ->setAppVersion($appVersion)
34
            ->notifyBuild($repository, $revision, $provider, $builderName);
35
36
        $response = new HTTPResponse();
37
        $response->setStatusCode(200);
38
        return $response;
39
    }
40
41
    public function initial()
42
    {
43
        $bugsnag = Injector::inst()->get(Bugsnag::class);
44
        $bugsnag->sendException(new RuntimeException("Test error"));
45
    }
46
}
47