AbstractServiceFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 5
eloc 5
c 2
b 0
f 1
dl 0
loc 20
ccs 0
cts 8
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A instance() 0 3 1
A commit() 0 3 1
A pledge() 0 3 1
A getNullable() 0 3 2
1
<?php
2
3
namespace Panamax\Factories;
4
5
use Closure;
6
use Panamax\Contracts\ServiceFactoryInterface;
7
use Panamax\ServiceEnclosure;
8
use Psr\Container\ContainerInterface;
9
10
abstract class AbstractServiceFactory implements ServiceFactoryInterface
11
{
12
    public function pledge(ContainerInterface $container, array $args = []): Closure
13
    {
14
        return fn () => $this->create($container, $args);
15
    }
16
17
    public function commit(ContainerInterface $container, array $args = []): Closure
18
    {
19
        return ServiceEnclosure::enclose($this->pledge($container, $args));
20
    }
21
22
    protected function getNullable(string $service, ContainerInterface $container)
23
    {
24
        return $container->has($service) ? $container->get($service) : null;
25
    }
26
27
    public static function instance(): ServiceFactoryInterface
28
    {
29
        return new static();
30
    }
31
}
32