ServiceProvider::has()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TMV\Laminas\Messenger;
6
7
use Laminas\ServiceManager\Exception\ServiceNotFoundException;
8
use Symfony\Contracts\Service\ServiceProviderInterface;
9
10
/**
11
 * @internal
12
 *
13
 * @template-implements ServiceProviderInterface<mixed>
14
 */
15
class ServiceProvider implements ServiceProviderInterface
16
{
17
    /**
18
     * @var array<string, callable>
19
     */
20
    protected array $factories;
21
22
    /**
23
     * @param array<string, callable> $factories
24
     */
25
    public function __construct(array $factories)
26
    {
27
        $this->factories = $factories;
28
    }
29
30
    public function get(string $id): mixed
31
    {
32
        if (! array_key_exists($id, $this->factories)) {
33
            throw new ServiceNotFoundException(sprintf('Service %s not found', $id));
34
        }
35
36
        return $this->factories[$id]();
37
    }
38
39
    public function has(string $id): bool
40
    {
41
        return array_key_exists($id, $this->factories);
42
    }
43
44
    public function getProvidedServices(): array
45
    {
46
        return $this->providedServices;
0 ignored issues
show
Bug Best Practice introduced by
The property providedServices does not exist on TMV\Laminas\Messenger\ServiceProvider. Did you maybe forget to declare it?
Loading history...
47
    }
48
}
49