Passed
Push — master ( fb51bb...c6ef6c )
by Tim
07:46
created

Statistics::stats()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 32
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 32
rs 9.6666
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\Module\consentsimpleadmin\Controller;
6
7
//use Exception;
8
//use SimpleSAML\Auth;
9
use SimpleSAML\Configuration;
10
//use SimpleSAML\Logger;
11
//use SimpleSAML\Module\consent\Auth\Process\Consent;
12
use SimpleSAML\Module\consent\Store;
13
use SimpleSAML\Session;
14
//use SimpleSAML\Metadata\MetaDataStorageHandler;
15
//use SimpleSAML\Module\consent\Store;
16
use SimpleSAML\Utils;
17
use SimpleSAML\XHTML\Template;
18
use Symfony\Component\HttpFoundation\Request;
19
20
/**
21
 * Controller class for the consentsimpleadmin module.
22
 *
23
 * This class serves the different views available in the module.
24
 *
25
 * @package simplesamlphp/simplesamlphp-module-consentsimpleadmin
26
 */
27
class Statistics
28
{
29
    /** @var \SimpleSAML\Configuration */
30
    protected Configuration $config;
31
32
    /** @var \SimpleSAML\Session */
33
    protected Session $session;
34
35
36
    /**
37
     * Controller constructor.
38
     *
39
     * It initializes the global configuration and session for the controllers implemented here.
40
     *
41
     * @param \SimpleSAML\Configuration $config The configuration to use by the controllers.
42
     * @param \SimpleSAML\Session $session The session to use by the controllers.
43
     *
44
     * @throws \Exception
45
     */
46
    public function __construct(
47
        Configuration $config,
48
        Session $session
49
    ) {
50
        $this->config = $config;
51
        $this->session = $session;
52
    }
53
54
55
56
    /**
57
     * @param \Symfony\Component\HttpFoundation\Request $request The current request.
58
     *
59
     * @return \SimpleSAML\XHTML\Template
60
     */
61
    public function stats(Request $request): Template
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

61
    public function stats(/** @scrutinizer ignore-unused */ Request $request): Template

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
62
    {
63
        $authUtils = new Utils\Auth();
64
        $authUtils->requireAdmin();
65
66
        // Get config object
67
        $consentconfig = $this->config::getConfig('module_consentSimpleAdmin.php');
68
69
        // Parse consent config
70
        $consent_storage = Store::parseStoreConfig($consentconfig->getValue('store'));
71
72
        // Get all consents for user
73
        $stats = $consent_storage->getStatistics();
74
75
        // Init template
76
        $t = new Template($config, 'consentSimpleAdmin:consentstats.twig');
77
        $translator = $t->getTranslator();
78
79
        $t->data['stats'] = $stats;
80
        $t->data['total'] = $translator->t(
81
            '{consentSimpleAdmin:consentsimpleadmin:stattotal}',
82
            ['%NO%' => $t->data['stats']['total']]
83
        );
84
        $t->data['statusers'] = $translator->t(
85
            '{consentSimpleAdmin:consentsimpleadmin:statusers}',
86
            ['%NO%' => $t->data['stats']['users']]
87
        );
88
        $t->data['statservices'] = $translator->t(
89
            '{consentSimpleAdmin:consentsimpleadmin:statservices}',
90
            ['%NO%' => $t->data['stats']['services']]
91
        );
92
        return $t;
93
    }
94
}
95