GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

SessionManager   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 60
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isAuthenticated() 0 4 1
A getUsername() 0 4 1
A store() 0 7 1
A clear() 0 7 1
A getSession() 0 13 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * (c) Christian Gripp <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Core23\FacebookBundle\Session;
13
14
use Core23\FacebookBundle\Session\Session as FacebookSession;
15
use Symfony\Component\HttpFoundation\Session\Session;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Core23\FacebookBundle\Session\Session.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
16
17
final class SessionManager implements SessionManagerInterface
18
{
19
    private const SESSION_FB_EXPIRES = '_CORE23_FACEBOOK_EXPIRES';
20
21
    private const SESSION_FB_NAME    = '_CORE23_FACEBOOK_NAME';
22
23
    private const SESSION_FB_ID      = '_CORE23_FACEBOOK_ID';
24
25
    private const SESSION_FB_TOKEN   = '_CORE23_FACEBOOK_TOKEN';
26
27
    /**
28
     * @var Session
29
     */
30
    private $session;
31
32
    public function __construct(Session $session)
33
    {
34
        $this->session = $session;
35
    }
36
37
    public function isAuthenticated(): bool
38
    {
39
        return (bool) $this->session->get(static::SESSION_FB_TOKEN);
40
    }
41
42
    public function getUsername(): ?string
43
    {
44
        return $this->session->get(static::SESSION_FB_NAME);
45
    }
46
47
    public function store(SessionInterface $session): void
48
    {
49
        $this->session->set(static::SESSION_FB_ID, $session->getFacebookId());
50
        $this->session->set(static::SESSION_FB_NAME, $session->getName());
51
        $this->session->set(static::SESSION_FB_TOKEN, $session->getToken());
52
        $this->session->set(static::SESSION_FB_EXPIRES, $session->getExpireDate());
53
    }
54
55
    public function clear(): void
56
    {
57
        $this->session->remove(static::SESSION_FB_ID);
58
        $this->session->remove(static::SESSION_FB_NAME);
59
        $this->session->remove(static::SESSION_FB_TOKEN);
60
        $this->session->remove(static::SESSION_FB_EXPIRES);
61
    }
62
63
    public function getSession(): ?SessionInterface
64
    {
65
        if (!$this->isAuthenticated()) {
66
            return null;
67
        }
68
69
        return new FacebookSession(
70
            $this->session->get(static::SESSION_FB_ID),
71
            $this->session->get(static::SESSION_FB_NAME),
72
            $this->session->get(static::SESSION_FB_TOKEN),
73
            $this->session->get(static::SESSION_FB_EXPIRES)
74
        );
75
    }
76
}
77