Passed
Pull Request — master (#19)
by Thijs
07:55
created

MetaRefresh   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
c 0
b 0
f 0
dl 0
loc 61
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A main() 0 20 2
A setAuthUtils() 0 3 1
A __construct() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\Module\metarefresh\Controller;
6
7
use Exception;
8
use SimpleSAML\Auth;
9
use SimpleSAML\Configuration;
10
use SimpleSAML\Error;
11
use SimpleSAML\Logger;
12
use SimpleSAML\Module\metarefresh\MetaLoader;
13
use SimpleSAML\Session;
14
use SimpleSAML\Utils;
15
use SimpleSAML\XHTML\Template;
16
use Symfony\Component\HttpFoundation\Response;
17
use Symfony\Component\HttpFoundation\Request;
18
19
/**
20
 * Controller class for the metarefresh module.
21
 *
22
 * This class serves the different views available in the module.
23
 *
24
 * @package SimpleSAML\Module\metarefresh
25
 */
26
27
class MetaRefresh
28
{
29
    /** @var \SimpleSAML\Configuration */
30
    protected Configuration $config;
31
32
    /**
33
     * @var \SimpleSAML\Utils\Auth
34
     */
35
    protected $authUtils;
36
37
38
    /**
39
     * Controller constructor.
40
     *
41
     * It initializes the global configuration and auth source configuration for the controllers implemented here.
42
     *
43
     * @param \SimpleSAML\Configuration              $config The configuration to use by the controllers.
44
     *
45
     * @throws \Exception
46
     */
47
    public function __construct(
48
        Configuration $config
49
    ) {
50
        $this->config = $config;
51
        $this->authUtils = new Utils\Auth();
52
    }
53
54
55
    /**
56
     * Inject the \SimpleSAML\Utils\Auth dependency.
57
     *
58
     * @param \SimpleSAML\Utils\Auth $authUtils
59
     */
60
    public function setAuthUtils(Utils\Auth $authUtils): void
61
    {
62
        $this->authUtils = $authUtils;
63
    }
64
65
    /**
66
     * @return \SimpleSAML\XHTML\Template
67
     */
68
    public function main(): Template
69
    {
70
        $this->authUtils->requireAdmin();
71
72
        Logger::setCaptureLog(true);
73
74
        try {
75
            $mf = new \SimpleSAML\Module\metarefresh\MetaRefresh();
76
	    $mf->runRefresh();
77
78
        } catch (Exception $e) {
79
            $e = Error\Exception::fromException($e);
80
            $e->logWarning();
81
        }
82
83
        $logentries = Logger::getCapturedLog();
84
85
        $t = new Template($this->config, 'metarefresh:fetch.twig');
86
        $t->data['logentries'] = $logentries;
87
        return $t;
88
    }
89
}
90