Completed
Push — fm-support ( 624fa6...b0af51 )
by Konstantinos
09:12 queued 04:41
created

MaintenanceController::showAction()   B

Complexity

Conditions 5
Paths 8

Size

Total Lines 30
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 30
rs 8.439
cc 5
eloc 16
nc 8
nop 0
1
<?php
2
3
use Symfony\Component\HttpFoundation\JsonResponse;
4
5
class MaintenanceController extends JSONController
6
{
7
    public function showAction()
8
    {
9
        $text = $this->container->getParameter('bzion.miscellaneous.maintenance');
10
11
        if (is_string($text)) {
12
            $defaultText = $text;
13
        } else {
14
            $defaultText = "Services are currently down for maintenance. Please try again later.";
15
        }
16
17
        if ($this->isJson()) {
18
            return new JsonResponse(array(
19
                'success' => false,
20
                'content' => $defaultText
21
            ));
22
        }
23
24
        // Return plain text if we were using a controller that didn't return
25
        // HTML
26
        $attributes = $this->getRequest()->attributes;
27
        if ($attributes->has('_controller')) {
28
            if (\Controller::getController($attributes) instanceof \PlainTextController) {
29
                return $defaultText;
30
            }
31
        }
32
33
        return array(
34
            'text' => $text
35
        );
36
    }
37
}
38