Passed
Pull Request — master (#105)
by Romain
02:51
created

NotificationStatus::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * Copyright (C) 2018
5
 * Nathan Boiron <[email protected]>
6
 * Romain Canon <[email protected]>
7
 *
8
 * This file is part of the TYPO3 NotiZ project.
9
 * It is free software; you can redistribute it and/or modify it
10
 * under the terms of the GNU General Public License, either
11
 * version 3 of the License, or any later version.
12
 *
13
 * For the full copyright and license information, see:
14
 * http://www.gnu.org/licenses/gpl-3.0.html
15
 */
16
17
namespace CuyZ\Notiz\Backend\Report;
18
19
use CuyZ\Notiz\Core\Definition\DefinitionService;
20
use CuyZ\Notiz\Service\Container;
21
use CuyZ\Notiz\Service\LocalizationService;
22
use CuyZ\Notiz\Service\ViewService;
23
use TYPO3\CMS\Core\SingletonInterface;
24
use TYPO3\CMS\Reports\Status;
25
use TYPO3\CMS\Reports\StatusProviderInterface;
26
27
/**
28
 * Adds an entry to the status report handled by TYPO3.
29
 *
30
 * If an error is found in the definition, an error report is added to the
31
 * queue, making it easier for administrators to see that something is wrong
32
 * with the extension.
33
 */
34
class NotificationStatus implements StatusProviderInterface, SingletonInterface
35
{
36
    /**
37
     * @var DefinitionService
38
     */
39
    protected $definitionService;
40
41
    /**
42
     * @var ViewService
43
     */
44
    protected $viewService;
45
46
    /**
47
     * Manual dependency injection.
48
     */
49
    public function __construct()
50
    {
51
        $this->definitionService = Container::get(DefinitionService::class);
52
        $this->viewService = Container::get(ViewService::class);
53
    }
54
55
    /**
56
     * @return array
57
     */
58
    public function getStatus()
59
    {
60
        $result = $this->definitionService->getValidationResult();
61
62
        $viewMessage = $this->viewService->getStandaloneView('Backend/Report/NotificationStatus');
63
        $viewButtons = $this->viewService->getStandaloneView('Backend/Report/NotificationStatusButtons');
64
65
        $viewMessage->assign('result', $result);
66
        $viewButtons->assign('result', $result);
67
68
        return [
69
            Container::get(
70
                Status::class,
71
                LocalizationService::localize('Backend/Report/Report:status.definition'),
72
                $viewMessage->render(),
73
                $viewButtons->render(),
74
                $result->hasErrors()
75
                    ? Status::ERROR
76
                    : Status::OK
77
            )
78
        ];
79
    }
80
}
81