MultiUserMultiMonthBookings::getBookingsForUser()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace JhFlexiTimeTest\Fixture;
4
5
use Doctrine\Common\DataFixtures\AbstractFixture;
6
use Doctrine\Common\Persistence\ObjectManager;
7
use JhFlexiTime\Entity\Booking;
8
use JhUser\Entity\User;
9
use JhFlexiTime\DateTime\DateTime;
10
11
/**
12
 * Class MultiUserMultiMonthBookings
13
 * @package JhUserTest\Fixture
14
 * @author Aydin Hassan <[email protected]>
15
 */
16
class MultiUserMultiMonthBookings extends AbstractFixture
17
{
18
    /**
19
     * @var Booking[]
20
     */
21
    protected $bookingsForUser = [];
22
23
    /**
24
     * @var User[]
25
     */
26
    protected $users;
27
28
    /**
29
     * @var User
30
     */
31
    protected $user;
32
33
    /**
34
     * @var string[]
35
     */
36
    protected $months = [];
37
38
    /**
39
     * @var DateTime
40
     */
41
    protected $expectedDate;
42
43
    /**
44
     * @param User $user
45
     */
46
    public function __construct(User $user)
47
    {
48
        $this->dates = [
0 ignored issues
show
Bug introduced by
The property dates 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...
49
            new DateTime("1 April 2014"),
50
            new DateTime("2 April 2014"),
51
            new DateTime("3 April 2014"),
52
            new DateTime("4 April 2014"),
53
            new DateTime("5 April 2014"),
54
            new DateTime("6 May 2014"),
55
            new DateTime("7 May 2014"),
56
            new DateTime("8 May 2014"),
57
            new DateTime("9 May 2014"),
58
            new DateTime("10 May 2014"),
59
            new DateTime("1 September 2014"),
60
            new DateTime("2 September 2014"),
61
            new DateTime("3 September 2014"),
62
            new DateTime("4 September 2014"),
63
            new DateTime("5 September 2014"),
64
        ];
65
66
        //the user we are looking for
67
        $this->user = $user;
68
69
        $this->users = [
70
            $user,
71
        ];
72
    }
73
74
    /**
75
     * {inheritDoc}
76
     */
77
    public function load(ObjectManager $manager)
78
    {
79
        $randomUser1 = new User;
80
        $randomUser1
81
            ->setEmail('[email protected]')
82
            ->setPassword("password");
83
        $this->users[] = $randomUser1;
84
85
        $randomUser2 = new User;
86
        $randomUser2
87
            ->setEmail('[email protected]')
88
            ->setPassword("password");
89
        $this->users[] = $randomUser2;
90
91
        foreach ($this->users as $user) {
92
            $manager->persist($user);
93
        }
94
        $manager->flush();
95
96
97
        foreach ($this->dates as $date) {
98
            foreach ($this->users as $user) {
99
                $booking = new Booking();
100
                $booking->setUser($user);
101
                $manager->persist($booking);
102
                $booking->setDate($date);
103
104
                if ($user === $this->user) {
105
                    $this->bookingsForUser[] = $booking;
106
                }
107
            }
108
        }
109
110
        $manager->flush();
111
    }
112
113
    /**
114
     * @return Booking[]
115
     */
116
    public function getBookingsForUser()
117
    {
118
        return $this->bookingsForUser;
119
    }
120
}
121