Passed
Push — master ( 785691...679eaf )
by Ross
39:28
created

Session   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 83.33%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A getSession() 7 7 1
A startSession() 6 6 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * A two factor authentication module that protects both the admin and customer logins
4
 * Copyright (C) 2017  Ross Mitchell
5
 *
6
 * This file is part of Rossmitchell/Twofactor.
7
 *
8
 * Rossmitchell/Twofactor is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20
 */
21
22
namespace Rossmitchell\Twofactor\Model\Admin;
23
24
use Magento\Backend\Model\Auth\Session\Proxy;
25
use Rossmitchell\Twofactor\Interfaces\SessionInterface;
26
use Rossmitchell\Twofactor\Traits\SessionTrait;
27
28 View Code Duplication
class Session implements SessionInterface
0 ignored issues
show
Duplication introduced by
This class 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...
29
{
30
    use SessionTrait;
31
32
    /**
33
     * @var Proxy
34
     */
35
    private $adminSession;
36
37
    /**
38
     * Session constructor.
39
     *
40
     * @param Proxy $adminSession
41
     */
42 6
    public function __construct(Proxy $adminSession)
43
    {
44 6
        $this->adminSession = $adminSession;
45 6
    }
46
47 16
    public function getSession()
48
    {
49 16
        $session = $this->adminSession;
50 16
        $this->startSession($session);
51
52 16
        return $session;
53
    }
54
55 16
    private function startSession(Proxy $session)
56
    {
57 16
        if ($session->isSessionExists() === false) {
58
            $session->start();
59
        }
60 16
    }
61
}
62