Skip to content

Commit

Permalink
Merge pull request #58 from gsteel/spl-priority-queue
Browse files Browse the repository at this point in the history
qa: Improve types for SplPriorityQueue
  • Loading branch information
Ocramius authored Jun 7, 2022
2 parents 92d58cf + 7228d85 commit 20f0787
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
[![Coverage Status](https://coveralls.io/repos/github/laminas/laminas-stdlib/badge.svg?branch=master)](https://coveralls.io/github/laminas/laminas-stdlib?branch=master)

> ## 🇷🇺 Русским гражданам
>
>
> Мы, участники Laminas, родились и живем в разных странах. У многих из нас есть друзья, родственники и коллеги как в России, так и в Украине. Некоторые из нас родились в России. Некоторые из нас живут в России. У некоторых бабушки и дедушки сражались с фашистами во Второй мировой войне. Здесь никто не поддерживает фашизм.
>
>
> У одного из нас есть украинская родственница, которая спаслась из дома вместе с сыном. Поезд задержался из-за бомбежки на дороге впереди. У нас есть друзья, которые прячутся в бомбоубежищах. Мы с тревогой ждем весточки от них после воздушных налетов, которые беспорядочно наносят удары и попадают по больницам, школам, детским садам и домам. Мы не берем это из каких-либо СМИ. Мы наблюдаем это напрямую.
>
>
> Вы доверяете нам достаточно, чтоб использовать наши программы, и мы просим вас довериться нам вновь. Мы нуждаемся в помощи. Выходите и протестуйте против этой бесполезной войны. Остановите кровопролитие. Скажите "Нет войне!"
>
>
> ## 🇺🇸 To Citizens of Russia
>
>
> We at Laminas come from all over the world. Many of us have friends, family and colleagues in both Russia and Ukraine. Some of us were born in Russia. Some of us currently live in Russia. Some have grandparents who fought Nazis in World War II. Nobody here supports fascism.
>
>
> One team member has a Ukrainian relative who fled her home with her son. The train was delayed due to bombing on the road ahead. We have friends who are hiding in bomb shelters. We anxiously follow up on them after the air raids, which indiscriminately fire at hospitals, schools, kindergartens and houses. We're not taking this from any media. These are our actual experiences.
>
>
> You trust us enough to use our software. We ask that you trust us to say the truth on this. We need your help. Go out and protest this unnecessary war. Stop the bloodshed. Say "stop the war!"
`Laminas\Stdlib` is a set of components that implements general purpose utility
Expand Down
6 changes: 0 additions & 6 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,6 @@
<MethodSignatureMismatch occurrences="1">
<code>public function insert($datum, $priority)</code>
</MethodSignatureMismatch>
<MixedAssignment occurrences="4">
<code>$array[]</code>
<code>$data[]</code>
<code>$item</code>
<code>$item</code>
</MixedAssignment>
</file>
<file src="src/StringUtils.php">
<DocblockTypeContradiction occurrences="1">
Expand Down
16 changes: 13 additions & 3 deletions src/SplPriorityQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
*
* Also, provides predictable heap order for datums added with the same priority
* (i.e., they will be emitted in the same order they are enqueued).
*
* @psalm-type InternalPriority = array{0: mixed, 1: int}
* @template TValue
* @template TPriority of InternalPriority
* @extends \SplPriorityQueue<TPriority, TValue>
*/
class SplPriorityQueue extends \SplPriorityQueue implements Serializable
{
Expand All @@ -35,15 +40,18 @@ class SplPriorityQueue extends \SplPriorityQueue implements Serializable
* Utilizes {@var $serial} to ensure that values of equal priority are
* emitted in the same order in which they are inserted.
*
* @param mixed $datum
* @param mixed $priority
* @param TValue $datum
* @param TPriority|mixed $priority
* @return void
*/
public function insert($datum, $priority)
{
if (! is_array($priority)) {
$priority = [$priority, $this->serial--];
}

/** @psalm-var TPriority $priority */

parent::insert($datum, $priority);
}

Expand All @@ -52,7 +60,7 @@ public function insert($datum, $priority)
*
* Array will be priority => data pairs
*
* @return array
* @return list<TValue>
*/
public function toArray()
{
Expand Down Expand Up @@ -140,6 +148,8 @@ public function __unserialize($data)
$priority = (int) $item['priority'];
}

/** @psalm-var TValue $item['data'] */

$this->insert($item['data'], $priority);
}
}
Expand Down

0 comments on commit 20f0787

Please sign in to comment.