mirror of
https://github.com/pestphp/pest.git
synced 2026-03-12 10:47:25 +01:00
feat: add count method for checking message type presence
This commit is contained in:
@ -53,4 +53,20 @@ final class HigherOrderMessageCollection
|
|||||||
$message->call($target);
|
$message->call($target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Count the number of messages with the given name.
|
||||||
|
*
|
||||||
|
* @param string $name A higher order message name (usually a method name)
|
||||||
|
*/
|
||||||
|
public function count(string $name): int
|
||||||
|
{
|
||||||
|
return array_reduce(
|
||||||
|
$this->messages,
|
||||||
|
static function (int $total, HigherOrderMessage $message) use ($name): int {
|
||||||
|
return $total + (int) ($name === $message->name);
|
||||||
|
},
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user