Admin::impersonate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 7
Ratio 87.5 %

Importance

Changes 0
Metric Value
dl 7
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
/*
4
 * DirectAdmin API Client
5
 * (c) Omines Internetbureau B.V. - https://omines.nl/
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Omines\DirectAdmin\Objects\Users;
12
13
use Omines\DirectAdmin\Context\AdminContext;
14
use Omines\DirectAdmin\Context\UserContext;
15
use Omines\DirectAdmin\DirectAdminException;
16
17
/**
18
 * Admin.
19
 *
20
 * @author Niels Keurentjes <[email protected]>
21
 */
22
class Admin extends Reseller
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function __construct($name, UserContext $context, $config = null)
28
    {
29
        parent::__construct($name, $context, $config);
30
    }
31
32
    /**
33
     * @return AdminContext
34
     */
35 View Code Duplication
    public function impersonate()
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...
36
    {
37
        /** @var AdminContext $context */
38
        if (!($context = $this->getContext()) instanceof AdminContext) {
39
            throw new DirectAdminException('You need to be an admin to impersonate another admin');
40
        }
41
        return $context->impersonateAdmin($this->getUsername());
42
    }
43
}
44