Completed
Push — newinternal ( 65a0f5...5b021c )
by Simon
08:29
created

NotIdentifiedException   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 51
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getReadableError() 0 20 3
A getSecurityManager() 0 4 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\User;
12
use Waca\Fragments\NavigationMenuAccessControl;
13
use Waca\PdoDatabase;
14
use Waca\Security\SecurityManager;
15
16
class NotIdentifiedException extends ReadableException
17
{
18
    use NavigationMenuAccessControl;
19
    /**
20
     * @var SecurityManager
21
     */
22
    private $securityManager;
23
24
    /**
25
     * NotIdentifiedException constructor.
26
     *
27
     * @param SecurityManager $securityManager
0 ignored issues
show
Documentation introduced by
Should the type for parameter $securityManager not be null|SecurityManager?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
28
     */
29
    public function __construct(SecurityManager $securityManager = null)
30
    {
31
        $this->securityManager = $securityManager;
32
    }
33
34
    /**
35
     * Returns a readable HTML error message that's displayable to the user using templates.
36
     * @return string
37
     */
38
    public function getReadableError()
39
    {
40
        if (!headers_sent()) {
41
            header("HTTP/1.1 403 Forbidden");
42
        }
43
44
        $this->setUpSmarty();
45
46
        // uck. We should still be able to access the database in this situation though.
47
        $database = PdoDatabase::getDatabaseConnection('acc');
48
        $currentUser = User::getCurrent($database);
49
        $this->assign('currentUser', $currentUser);
50
        $this->assign("loggedIn", (!$currentUser->isCommunityUser()));
51
52
        if($this->securityManager !== null) {
53
            $this->setupNavMenuAccess($currentUser);
54
        }
55
56
        return $this->fetchTemplate("exception/not-identified.tpl");
57
    }
58
59
    /**
60
     * @return SecurityManager
61
     */
62
    protected function getSecurityManager()
63
    {
64
        return $this->securityManager;
65
    }
66
}