AbstractServiceFactory::commit()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 2
crap 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