Lines 0.00% 0 / 3
Functions and Methods 0.00% 0 / 3
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
AppOverrideCollection 0.00% 0 / 3 0.00% 0 / 3 12 0.00% 0 / 1
 keyedByAppId 0.00% 0 / 1 0.00% 0 / 1 2
 find 0.00% 0 / 1 0.00% 0 / 1 2
 findMatchingApp 0.00% 0 / 1 0.00% 0 / 1 2
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Runtime\Config\Collection;
6
7use Stewart\Contracts\App\AppId;
8use Stewart\Contracts\Collection\KeyedCollection;
9use Stewart\Runtime\Config\AppOverride;
10
11/** @extends KeyedCollection<string, AppOverride> */
12final readonly class AppOverrideCollection extends KeyedCollection
13{
14    /** @param iterable<AppOverride> $overrides */
15    public static function keyedByAppId(iterable $overrides): self
16    {
17        return self::keyedBy($overrides, static fn(AppOverride $override): string => $override->id->value);
18    }
19
20    public function find(AppId $id): ?AppOverride
21    {
22        return $this->elementAt($id->value);
23    }
24
25    // Environment variable names spell "my-app" as MY_APP, so an override may name its app either way.
26    public function findMatchingApp(AppId $id): ?AppOverride
27    {
28        return $this->find($id) ?? $this->findFirstWhere(static fn(AppOverride $override): bool => $override->id->collidesWith($id));
29    }
30}