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

ServiceProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A has() 0 3 1
A getProvidedServices() 0 3 1
A get() 0 7 2
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