Guilds::getActive()   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\Exceptions\ImmutableException;
6
use Igorsgm\TibiaDataApi\Models\Guilds\Guild;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Igorsgm\TibiaDataApi\Models\Guild.

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
use Igorsgm\TibiaDataApi\Traits\ImmutableTrait;
8
use Igorsgm\TibiaDataApi\Traits\SerializableTrait;
9
use Illuminate\Support\Collection;
10
11 View Code Duplication
class Guilds
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...
12
{
13
    use ImmutableTrait, SerializableTrait;
14
15
    /**
16
     * @var string
17
     */
18
    private $world;
19
20
    /**
21
     * @var Collection
22
     */
23
    private $active;
24
25
    /**
26
     * @var Collection
27
     */
28
    private $formation;
29
30
    /**
31
     * Guilds constructor.
32
     * @param  string  $world
33
     * @param  array  $active
34
     * @param  array  $formation
35
     * @throws ImmutableException
36
     */
37
    public function __construct(string $world, Collection $active, Collection $formation)
38
    {
39
        $this->handleImmutableConstructor();
40
41
        $this->world = $world;
42
        $this->active = $active;
43
        $this->formation = $formation;
44
    }
45
46
    /**
47
     * @return string
48
     */
49
    public function getWorld(): string
50
    {
51
        return $this->world;
52
    }
53
54
    /**
55
     * @return Guild[]
56
     */
57
    public function getActive(): Collection
58
    {
59
        return $this->active;
60
    }
61
62
    /**
63
     * @return Guild[]
64
     */
65
    public function getFormation(): Collection
66
    {
67
        return $this->formation;
68
    }
69
}
70