Test Failed
Branch feature/decoupled (5e8293)
by Webysther
02:49
created

Mirror::remove()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Packagist Mirror.
7
 *
8
 * For the full license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Webs\Mirror;
13
14
use PHPSnippets\DataStructures\CircularArray;
15
16
/**
17
 * Middleware to http operations.
18
 *
19
 * @author Webysther Nunes <[email protected]>
20
 */
21
class Mirror
22
{
23
    /**
24
     * @var string
25
     */
26
    protected $master;
27
28
    /**
29
     * @var array
30
     */
31
    protected $slaves;
32
33
    /**
34
     * @var array
35
     */
36
    protected $all;
37
38
    /**
39
     * @var array
40
     */
41
    protected $data;
42
43
    /**
44
     * @param string $master
45
     * @param array  $slaves
46
     */
47
    public function __construct(string $master, array $slaves)
48
    {
49
        $this->master = $master;
50
        $this->slaves = $slaves;
51
        $this->data = array_unique(array_merge([$master], $slaves));
52
        $this->all = CircularArray::fromArray($this->data);
0 ignored issues
show
Documentation Bug introduced by
It seems like PHPSnippets\DataStructur...:fromArray($this->data) of type PHPSnippets\DataStructures\CircularArray is incompatible with the declared type array of property $all.

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...
53
    }
54
55
    /**
56
     * @return string
57
     */
58
    public function getMaster():string
59
    {
60
        return $this->master;
61
    }
62
63
    /**
64
     * Get all mirrors.
65
     *
66
     * @return CircularArray
67
     */
68
    public function getAll():CircularArray
69
    {
70
        return $this->all;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->all returns the type array which is incompatible with the type-hinted return PHPSnippets\DataStructures\CircularArray.
Loading history...
71
    }
72
73
    /**
74
     * Get next item.
75
     *
76
     * @return string
77
     */
78
    public function getNext():string
79
    {
80
        $this->all->next();
81
82
        return $this->all->current();
83
    }
84
85
    /**
86
     * @param string $value
87
     *
88
     * @return CircularArray
89
     */
90
    public function remove(string $value):CircularArray
91
    {
92
        $this->data = array_diff($this->data, [$value]);
93
        $this->all = CircularArray::fromArray($this->data);
0 ignored issues
show
Documentation Bug introduced by
It seems like PHPSnippets\DataStructur...:fromArray($this->data) of type PHPSnippets\DataStructures\CircularArray is incompatible with the declared type array of property $all.

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...
94
95
        return $this->getAll();
96
    }
97
}
98