FakeCitiesSeeder::__construct()   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
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
use Angelov\Storgman\LocalCommittees\Cities\Commands\StoreCityCommand;
4
use Angelov\Storgman\LocalCommittees\Cities\Location;
5
use Illuminate\Database\Seeder;
6
use Symfony\Component\HttpFoundation\File\File;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, File.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
7
8
class FakeCitiesSeeder extends Seeder
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
{
10
    protected $faker;
11
12
    public function __construct(\Faker\Factory $fakerFactory)
13
    {
14
        $this->faker = $fakerFactory->create();
15
    }
16
17
    public function run()
18
    {
19
        for ($i=0; $i<10; $i++) {
20
21
            $name = $this->faker->city;
22
            $country = $this->faker->country;
23
            $location = new Location($this->faker->latitude, $this->faker->longitude); // this may not be in europe
24
            $details = $this->faker->realText();
25
26
            $image = $this->faker->image('/tmp', 640, 480, 'city');
27
            $image = new File($image);
28
29
            dispatch(new StoreCityCommand($name, $country, $location, $image, $details));
30
31
        }
32
    }
33
}
34