Passed
Push — bugfix ( 149862 )
by Simon
12:39
created

NotIdentifiedException   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
eloc 18
dl 0
loc 54
ccs 0
cts 27
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getSecurityManager() 0 3 1
A getReadableError() 0 19 3
A getDomainAccessManager() 0 3 1
1
<?php
2
/******************************************************************************
3
 * Wikipedia Account Creation Assistance tool                                 *
4
 *                                                                            *
5
 * All code in this file is released into the public domain by the ACC        *
6
 * Development Team. Please see team.json for a list of contributors.         *
7
 ******************************************************************************/
8
9
namespace Waca\Exceptions;
10
11
use Waca\DataObjects\Domain;
12
use Waca\DataObjects\User;
13
use Waca\Fragments\NavigationMenuAccessControl;
14
use Waca\PdoDatabase;
15
use Waca\Security\DomainAccessManager;
16
use Waca\Security\SecurityManager;
17
18
class NotIdentifiedException extends ReadableException
19
{
20
    use NavigationMenuAccessControl;
21
22
    /** @var SecurityManager */
23
    private $securityManager;
24
    /** @var DomainAccessManager */
25
    private $domainAccessManager;
26
27
    /**
28
     * NotIdentifiedException constructor.
29
     *
30
     * @param SecurityManager     $securityManager
31
     * @param DomainAccessManager $domainAccessManager
32
     */
33
    public function __construct(SecurityManager $securityManager, DomainAccessManager $domainAccessManager)
34
    {
35
        $this->securityManager = $securityManager;
36
        $this->domainAccessManager = $domainAccessManager;
37
    }
38
39
    /**
40
     * Returns a readable HTML error message that's displayable to the user using templates.
41
     * @return string
42
     */
43
    public function getReadableError()
44
    {
45
        if (!headers_sent()) {
46
            header("HTTP/1.1 403 Forbidden");
47
        }
48
49
        $this->setUpSmarty();
50
51
        // uck. We should still be able to access the database in this situation though.
52
        $database = PdoDatabase::getDatabaseConnection('acc');
53
        $currentUser = User::getCurrent($database);
54
        $this->assign('currentUser', $currentUser);
55
        $this->assign('currentDomain', Domain::getCurrent($database));
56
57
        if ($this->securityManager !== null) {
58
            $this->setupNavMenuAccess($currentUser);
59
        }
60
61
        return $this->fetchTemplate("exception/not-identified.tpl");
62
    }
63
64
    protected function getSecurityManager(): SecurityManager
65
    {
66
        return $this->securityManager;
67
    }
68
69
    public function getDomainAccessManager(): DomainAccessManager
70
    {
71
        return $this->domainAccessManager;
72
    }
73
}