ResetTwoFactorCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 7 1
A execute() 0 19 3
1
<?php
2
3
/*
4
 * This file is part of Jitamin.
5
 *
6
 * Copyright (C) Jitamin Team
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 Jitamin\Console;
13
14
use Symfony\Component\Console\Input\InputArgument;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Output\OutputInterface;
17
18
/**
19
 * Reset two factor command class.
20
 */
21
class ResetTwoFactorCommand extends BaseCommand
22
{
23
    /**
24
     * Configure the console command.
25
     *
26
     * @return void
27
     */
28
    protected function configure()
29
    {
30
        $this
31
            ->setName('user:reset-2fa')
32
            ->setDescription('Remove two-factor authentication for a user')
33
            ->addArgument('username', InputArgument::REQUIRED, 'Username');
34
    }
35
36
    /**
37
     * Execute the console command.
38
     *
39
     * @param InputInterface  $output
40
     * @param OutputInterface $output
41
     *
42
     * @return void
43
     */
44
    protected function execute(InputInterface $input, OutputInterface $output)
45
    {
46
        $username = $input->getArgument('username');
47
        $userId = $this->userModel->getIdByUsername($username);
0 ignored issues
show
Documentation introduced by
The property userModel does not exist on object<Jitamin\Console\ResetTwoFactorCommand>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
48
49
        if (empty($userId)) {
50
            $output->writeln('<error>User not found</error>');
51
52
            return 1;
53
        }
54
55
        if (!$this->userModel->update(['id' => $userId, 'twofactor_activated' => 0, 'twofactor_secret' => ''])) {
0 ignored issues
show
Documentation introduced by
The property userModel does not exist on object<Jitamin\Console\ResetTwoFactorCommand>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
56
            $output->writeln('<error>Unable to update user profile</error>');
57
58
            return 1;
59
        }
60
61
        $output->writeln('<info>Two-factor authentication disabled</info>');
62
    }
63
}
64