filter(function (TaskInterface $task) use ($context) { return $task->canRunInContext($context); }); } public function filterByTestSuite(?TestSuiteInterface $testSuite = null): self { if (null === $testSuite) { return $this; } return $this->filter(function (TaskInterface $task) use ($testSuite) { return \in_array($task->getConfig()->getName(), $testSuite->getTaskNames(), true); }); } /** * @param string[] $tasks */ public function filterByTaskNames(array $tasks): self { if (empty($tasks)) { return $this; } return $this->filter(function (TaskInterface $task) use ($tasks) { return \in_array($task->getConfig()->getName(), $tasks, true); }); } /** * This method sorts the tasks by highest priority first. */ public function sortByPriority(): self { $priorityQueue = new SplPriorityQueue(); $stableSortIndex = PHP_INT_MAX; /** @var TaskInterface $task */ foreach ($this->getIterator() as $task) { $metadata = $task->getConfig()->getMetadata(); $priorityQueue->insert($task, [$metadata->priority(), $stableSortIndex--]); } return new self(array_values(iterator_to_array($priorityQueue))); } }