Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Commit b4113a7

Browse files
JoshVeeweierophinney
authored andcommitted
Fix count increment on insert in PriorityList
This patch fixes an issue with count incrementation in PriorityList, ensuring incrementation only occurs if the item was not previously in the list.
1 parent a5dd7fd commit b4113a7

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/PriorityList.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,11 @@ class PriorityList implements Iterator, Countable
6262
*/
6363
public function insert($name, $value, $priority = 0)
6464
{
65+
if (!isset($this->items[$name])) {
66+
$this->count++;
67+
}
68+
6569
$this->sorted = false;
66-
$this->count++;
6770

6871
$this->items[$name] = array(
6972
'data' => $value,

test/PriorityListTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,24 @@ public function testInsert()
3535
}
3636
}
3737

38+
public function testInsertDuplicates()
39+
{
40+
$this->list->insert('foo', new \stdClass());
41+
$this->list->insert('bar', new \stdClass());
42+
43+
$this->assertEquals(2, count($this->list));
44+
45+
$this->list->insert('foo', new \stdClass());
46+
$this->list->insert('foo', new \stdClass());
47+
$this->list->insert('bar', new \stdClass());
48+
49+
$this->assertEquals(2, count($this->list));
50+
51+
$this->list->remove('foo');
52+
53+
$this->assertEquals(1, count($this->list));
54+
}
55+
3856
public function testRemove()
3957
{
4058
$this->list->insert('foo', new \stdClass(), 0);

0 commit comments

Comments
 (0)