Completed
Push — master ( 4fea39...872a00 )
by Troy
01:28
created

CreateTenant::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
namespace MultiTenantLaravel\App\Commands;
4
5
use Illuminate\Console\Command;
6
7
class CreateTenant extends Command
8
{
9
    /**
10
     * The name and signature of the console command.
11
     *
12
     * @var string
13
     */
14
    protected $signature = 'tenant:create {--fake}';
15
16
    /**
17
     * The console command description.
18
     *
19
     * @var string
20
     */
21
    protected $description = 'Create a new tenant';
22
23
    /**
24
     * Create a new command instance.
25
     *
26
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
27
     */
28
    public function __construct()
29
    {
30
        parent::__construct();
31
    }
32
33
    /**
34
     * Execute the console command.
35
     *
36
     * @return mixed
37
     */
38
    public function handle()
39
    {
40
        $count = (int) $this->ask('How many would you like to create?');
41
42
        while ($count > 0) {
43
            if (!$this->option('fake')) {
44
                $this->createNewTenant();
0 ignored issues
show
Unused Code introduced by
The call to the method MultiTenantLaravel\App\C...nant::createNewTenant() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
45
            } else {
46
                $this->createFakeTenant();
47
            }
48
49
            $count--;
50
        }
51
52
    }
53
54
    private function createFakeTenant()
55
    {
56
        // Start faker and create a fake tenant
57
        $faker = new Faker\Generator();
58
59
        dd($faker);
60
    }
61
62
    private function createNewTenant()
63
    {
64
        // Ask for some user input and create a new tenant
65
    }
66
}
67