Completed
Push — master ( 0d7c83...11b403 )
by Vitaly
02:57
created

Service::__construct()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
rs 9.6666
cc 3
eloc 5
nc 2
nop 1
1
<?php declare(strict_types = 1);
2
/**
3
 * Created by PhpStorm.
4
 * User: root
5
 * Date: 27.07.2016
6
 * Time: 1:55.
7
 */
8
namespace samsonframework\container\collection\configurator;
9
10
use samsonframework\container\collection\CollectionKeyConfiguratorInterface;
11
use samsonframework\container\configurator\ServiceConfigurator;
12
use samsonframework\container\metadata\ClassMetadata;
13
14
/**
15
 * Service collection configurator class.
16
 * @see    \samsonframework\container\configurator\ServiceConfigurator
17
 *
18
 * @author Vitaly Egorov <[email protected]>
19
 */
20
class Service extends ServiceConfigurator implements CollectionKeyConfiguratorInterface
21
{
22
    use CollectionConfiguratorTrait;
23
24
    public function __construct(array $scopeData)
25
    {
26
        // Check for name attribute
27
        if (array_key_exists('@attributes', $scopeData) && array_key_exists('name', $scopeData['@attributes'])) {
28
            parent::__construct($scopeData['@attributes']['name']);
29
        } else {
30
            throw new \InvalidArgumentException('Cannot configure service without name attribute');
31
        }
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function resolve($data)
0 ignored issues
show
Unused Code introduced by
The parameter $data is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
38
    {
39
        $classMetadata = new ClassMetadata();
40
        $classMetadata->name = $this->serviceName;
41
        $classMetadata->scopes[] = $this->scopeName;
42
43
        return $classMetadata;
44
    }
45
}
46