Creators::createPhoto()   B
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 23
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 23
rs 8.7972
c 1
b 0
f 0
cc 4
eloc 17
nc 4
nop 2
1
<?php
2
3
namespace JeroenG\LaravelPhotoGallery\Traits; 
4
use JeroenG\LaravelPhotoGallery\Entities as Entity;
5
6
trait Creators
7
{
8
    public function createAlbum($data = null, $add = true)
9
    {
10
        $faker = \Faker\Factory::create();
11
        $album = new Entity\Album();
12
        $metadata = [
13
            'id' => $faker->unique()->randomDigitNotNull(),
14
            'name' => $faker->name,
15
            'description' => $faker->sentence(3)
16
        ];
17
        if(!is_null($data)) {
18
            foreach ($data as $key => $value) {
19
                $metadata[$key] = $value;
20
            }
21
        }
22
        $album->map($metadata);
23
        if($add) {
24
            $this->albums->add($album);
0 ignored issues
show
Bug introduced by
The property albums 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...
25
        }
26
        return $album;
27
    }
28
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);
0 ignored issues
show
Bug introduced by
The property photos 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
        }
50
        return $photo;
51
    }
52
}