ClientTrait::shutdown()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/*
3
 * This file is part of the Pomm's Foundation package.
4
 *
5
 * (c) 2014 - 2017 Grégoire HUBERT <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace PommProject\Foundation\Client;
11
12
use PommProject\Foundation\Session\Session;
13
use PommProject\Foundation\Exception\FoundationException;
14
15
/**
16
 * ClientTrait
17
 *
18
 * Abstract class for Session clients.
19
 *
20
 * @package   Foundation
21
 * @copyright 2014 - 2017 Grégoire HUBERT
22
 * @author    Grégoire HUBERT
23
 * @license   X11 {@link http://opensource.org/licenses/mit-license.php}
24
 * @see       ClientInterface
25
 */
26
trait ClientTrait
27
{
28
    private $session;
29
30
    /**
31
     * @see ClientInterface
32
     */
33
    public function initialize(Session $session)
34
    {
35
        $this->session = $session;
36
    }
37
38
    /**
39
     * Most of the time, there is nothing to be done at shutdown.
40
     * @see ClientInterface
41
     */
42
    public function shutdown()
43
    {
44
    }
45
46
    /**
47
     * getSession
48
     *
49
     * All subclasses of Client have to use this method to access the session.
50
     *
51
     * @throws  FoundationException if Session is not set.
52
     * @return Session
53
     */
54 View Code Duplication
    protected function getSession()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
    {
56
        if ($this->session === null) {
57
            throw new FoundationException(
58
                sprintf(
59
                    "Client '%s' is not initialized hence does not have a session.",
60
                    get_class($this)
61
                )
62
            );
63
        }
64
65
        return $this->session;
66
    }
67
}
68