Completed
Pull Request — 1.0 (#2)
by David
04:25
created

ServiceFactory::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 3
1
<?php
2
3
4
namespace TheCodingMachine\Yaco\ServiceProvider;
5
6
/**
7
 * This utility class is used to instantiate services from a service provider (if the services are not
8
 * static methods).
9
 *
10
 * Note: this calls the 'getServices' method of the service provider. Hence, this is suboptimal compared to
11
 * a call to a static method
12
 */
13
class ServiceFactory
14
{
15
    public function create(string $serviceProviderClassName, string $serviceName, array $params)
16
    {
17
        $services = call_user_func([$serviceProviderClassName, 'getServices']);
18
19
        return call_user_func_array($services[$serviceName], $params);
20
    }
21
}
22