Conditions | 4 |
Paths | 4 |
Total Lines | 23 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
29 | public function createPhoto($data = null, $add = true) |
||
30 | { |
||
31 | $faker = \Faker\Factory::create(); |
||
32 | $photo = new Entity\Photo(); |
||
33 | $metadata = [ |
||
34 | 'id' => $faker->unique()->randomDigitNotNull(), |
||
35 | 'name' => $faker->name, |
||
36 | 'description' => $faker->sentence(3), |
||
37 | 'file' => $faker->imageUrl(640, 480), |
||
38 | 'size' => '640x480', |
||
39 | 'album_id' => $faker->unique()->randomDigitNotNull() |
||
40 | ]; |
||
41 | if(!is_null($data)) { |
||
42 | foreach ($data as $key => $value) { |
||
43 | $metadata[$key] = $value; |
||
44 | } |
||
45 | } |
||
46 | $photo->map($metadata); |
||
47 | if($add) { |
||
48 | $this->photos->add($photo); |
||
49 | } |
||
50 | return $photo; |
||
51 | } |
||
52 | } |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: