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

NotIdentifiedException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 4
cp 0
crap 2
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
}