Test Failed
Push — main ( 6ea8e5...17888d )
by Chema
03:03
created

AliasRegistry   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 28
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 3 1
A has() 0 3 1
A add() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Container;
6
7
/**
8
 * Manages service name aliases.
9
 * Allows accessing the same service with multiple identifiers.
10
 */
11
final class AliasRegistry
12
{
13
    /** @var array<string,string> */
14
    private array $aliases = [];
15
16
    /**
17
     * Create an alias for a service.
18
     */
19
    public function add(string $alias, string $id): void
20
    {
21
        $this->aliases[$alias] = $id;
22
    }
23
24
    /**
25
     * Resolve an alias to its actual service ID.
26
     * Returns the input if no alias exists.
27
     */
28
    public function resolve(string $id): string
29
    {
30
        return $this->aliases[$id] ?? $id;
31
    }
32
33
    /**
34
     * Check if an alias exists.
35
     */
36
    public function has(string $alias): bool
37
    {
38
        return isset($this->aliases[$alias]);
39
    }
40
}
41