Worlds::getWorlds()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Igorsgm\TibiaDataApi\Models;
4
5
use Igorsgm\TibiaDataApi\Models\Worlds\World;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Igorsgm\TibiaDataApi\Models\World.

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...
6
use Igorsgm\TibiaDataApi\Traits\ImmutableTrait;
7
use Igorsgm\TibiaDataApi\Traits\SerializableTrait;
8
use Illuminate\Support\Collection;
9
10 View Code Duplication
class Worlds
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
11
{
12
    use ImmutableTrait, SerializableTrait;
13
14
    /**
15
     * @var int
16
     */
17
    private $online;
18
19
    /**
20
     * @var array
21
     */
22
    private $worlds;
23
24
    /**
25
     * Worlds constructor.
26
     * @param  int  $online
27
     * @param  array  $worlds
28
     * @throws \Igorsgm\TibiaDataApi\Exceptions\ImmutableException
29
     */
30
    public function __construct(int $online, Collection $worlds)
31
    {
32
        $this->handleImmutableConstructor();
33
34
        $this->online = $online;
35
        $this->worlds = $worlds;
0 ignored issues
show
Documentation Bug introduced by
It seems like $worlds of type object<Illuminate\Support\Collection> is incompatible with the declared type array of property $worlds.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
36
    }
37
38
    /**
39
     * @return int
40
     */
41
    public function getOnline(): int
42
    {
43
        return $this->online;
44
    }
45
46
    /**
47
     * @return World[]
48
     */
49
    public function getWorlds(): Collection
50
    {
51
        return $this->worlds;
52
    }
53
}
54