Issues (1)

src/Entity/Gears.php (1 issue)

Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PierInfor\Gears\Entity;
6
7
use PierInfor\Gears\Entity\Gear;
8
9
/**
10
 * Gears entity accessors
11
 *
12
 */
13
class Gears extends Serializable implements \JsonSerializable, GearsInterface
14
{
15
    use JsonSerializer;
16
17
    /** @var Gear[] */
18
    protected array $gears;
19
20
    /**
21
     * ctor
22
     */
23
    public function __construct()
24
    {
25
    }
26
27
    /**
28
     * returns gears
29
     * @return Gear[]
30
     */
31 5
    public function getGears(): array
32
    {
33 5
        return $this->gears;
34
    }
35
36
    /**
37
     * set gears
38
     * @param Gear[] $gears
39
     * @return Gears
40
     */
41 3
    public function setGears(array $gears): Gears
42
    {
43 3
        $gstack = [];
44 3
        if ($gears[0] instanceof Gear) {
0 ignored issues
show
$gears[0] is always a sub-type of PierInfor\Gears\Entity\Gear.
Loading history...
45 1
            $this->gears = $gears;
46 1
            return $this;
47
        }
48 3
        foreach ($gears as $p) {
49 3
            if ($p instanceof \stdClass) {
50 3
                $gstack[] = (new Gear())->hydrate($p);
51
            }
52
        }
53 3
        $this->gears = $gstack;
54 3
        return $this;
55
    }
56
}
57