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.
Completed
Push — master ( 780712...bc7eb6 )
by Christian
09:30
created

SessionManager::clear()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
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
    /**
33
     * SessionManager constructor.
34
     *
35
     * @param Session $session
36
     */
37
    public function __construct(Session $session)
38
    {
39
        $this->session = $session;
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function isAuthenticated(): bool
46
    {
47
        return (bool) $this->session->get(static::SESSION_FB_TOKEN);
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function getUsername(): ?string
54
    {
55
        return $this->session->get(static::SESSION_FB_NAME);
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function store(SessionInterface $session): void
62
    {
63
        $this->session->set(static::SESSION_FB_ID, $session->getFacebookId());
64
        $this->session->set(static::SESSION_FB_NAME, $session->getName());
65
        $this->session->set(static::SESSION_FB_TOKEN, $session->getToken());
66
        $this->session->set(static::SESSION_FB_EXPIRES, $session->getExpireDate());
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72
    public function clear(): void
73
    {
74
        $this->session->remove(static::SESSION_FB_ID);
75
        $this->session->remove(static::SESSION_FB_NAME);
76
        $this->session->remove(static::SESSION_FB_TOKEN);
77
        $this->session->remove(static::SESSION_FB_EXPIRES);
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83
    public function getSession(): ?SessionInterface
84
    {
85
        if (!$this->isAuthenticated()) {
86
            return null;
87
        }
88
89
        return new FacebookSession(
90
            $this->session->get(static::SESSION_FB_ID),
91
            $this->session->get(static::SESSION_FB_NAME),
92
            $this->session->get(static::SESSION_FB_TOKEN),
93
            $this->session->get(static::SESSION_FB_EXPIRES)
94
        );
95
    }
96
}
97