Passed
Push — master ( b2b84f...109e7c )
by Thomas Mauro
03:02
created

ServiceProvider::has()   A

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
class ServiceProvider implements ServiceProviderInterface
14
{
15
    /**
16
     * @var array<string, callable>
17
     */
18
    protected array $factories;
19
20
    /**
21
     * @param array<string, callable> $factories
22
     */
23
    public function __construct(array $factories)
24
    {
25
        $this->factories = $factories;
26
    }
27
28
    public function get(string $id): mixed
29
    {
30
        if (! array_key_exists($id, $this->factories)) {
31
            throw new ServiceNotFoundException(sprintf('Service %s not found', $id));
32
        }
33
34
        return $this->factories[$id]();
35
    }
36
37
    public function has(string $id): bool
38
    {
39
        return array_key_exists($id, $this->factories);
40
    }
41
42
    public function getProvidedServices(): array
43
    {
44
        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...
45
    }
46
}
47