Completed
Pull Request — master (#23)
by Karl
04:20
created

TestingDatabaseSeeder::createPremiumUsers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 1
eloc 10
nc 1
nop 1
1
<?php
2
3
use Faker\Factory as Faker;
4
use Illuminate\Database\Seeder;
5
use JobApis\JobsToMail\Models\User;
6
use JobApis\JobsToMail\Models\Recruiter;
7
use JobApis\JobsToMail\Models\Search;
8
use JobApis\JobsToMail\Models\Token;
9
10
class TestingDatabaseSeeder extends Seeder
11
{
12
    public function run()
13
    {
14
        $this->faker = Faker::create();
0 ignored issues
show
Bug introduced by
The property faker does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
15
        $this->createActiveUsers();
16
        $this->createPremiumUsers();
17
        $this->createDeletedUsers();
18
        $this->createUnconfirmedUsers();
19
    }
20
21
    private function createActiveUsers($num = 10)
22
    {
23
        return factory(User::class, $num)
0 ignored issues
show
Bug introduced by
The method each does only exist in Illuminate\Database\Eloquent\Collection, but not in Illuminate\Database\Eloquent\Model.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
24
            ->states('active')
25
            ->create()
26
            ->each(function(User $user) {
27
                $user->tokens()->save(
28
                    factory(Token::class)->make()
29
                );
30
            })->each(function(User $user) {
31
                factory(Search::class, rand(1, 3))->create([
32
                    'user_id' => $user->id
33
                ]);
34
            });
35
    }
36
37
    private function createPremiumUsers($num = 2)
38
    {
39
        return factory(User::class, $num)
0 ignored issues
show
Bug introduced by
The method each does only exist in Illuminate\Database\Eloquent\Collection, but not in Illuminate\Database\Eloquent\Model.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
40
            ->states('active', 'premium')
41
            ->create()
42
            ->each(function(User $user) {
43
                $user->tokens()->save(
44
                    factory(Token::class)->make()
45
                );
46
            })->each(function(User $user) {
47
                factory(Search::class, rand(2, 10))->create([
48
                    'user_id' => $user->id
49
                ]);
50
            });
51
    }
52
53
    private function createDeletedUsers($num = 10)
54
    {
55
        return factory(User::class, $num)
0 ignored issues
show
Bug introduced by
The method each does only exist in Illuminate\Database\Eloquent\Collection, but not in Illuminate\Database\Eloquent\Model.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
56
            ->states('active', 'deleted')
57
            ->create()
58
            ->each(function(User $user) {
59
                $user->tokens()->save(
60
                    factory(Token::class)->make()
61
                );
62
            });
63
    }
64
65
    private function createUnconfirmedUsers($num = 10)
66
    {
67
        return factory(User::class, $num)
0 ignored issues
show
Bug introduced by
The method each does only exist in Illuminate\Database\Eloquent\Collection, but not in Illuminate\Database\Eloquent\Model.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
68
            ->create()
69
            ->each(function(User $user) {
70
                $user->tokens()->save(
71
                    factory(Token::class)->make()
72
                );
73
            });
74
    }
75
}
76