Completed
Pull Request — master (#306)
by Benoît
04:15
created

ScopeFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 1
cbo 1
dl 0
loc 42
ccs 11
cts 11
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A createScopeFor() 0 4 1
A createChildScopeFor() 0 13 1
1
<?php
2
3
/*
4
 * This file is part of the League\Fractal package.
5
 *
6
 * (c) Phil Sturgeon <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace League\Fractal;
13
14
use League\Fractal\Resource\ResourceInterface;
15
16
class ScopeFactory implements ScopeFactoryInterface
17
{
18
    /**
19
     * @var Manager
20
     */
21
    private $manager;
22
23 35
    public function __construct(Manager $manager)
24
    {
25 35
        $this->manager = $manager;
26 35
    }
27
28
    /**
29
     * @param ResourceInterface $resource
30
     * @param string|null $scopeIdentifier
31
     * @return Scope
32
     */
33 34
    public function createScopeFor(ResourceInterface $resource, $scopeIdentifier = null)
34
    {
35 34
        return new Scope($this->manager, $resource, $scopeIdentifier);
36
    }
37
38
    /**
39
     * @param Scope $parentScopeInstance
40
     * @param ResourceInterface $resource
41
     * @param string|null $scopeIdentifier
42
     * @return Scope
43
     */
44 28
    public function createChildScopeFor(Scope $parentScopeInstance, ResourceInterface $resource, $scopeIdentifier = null)
45
    {
46 28
        $scopeInstance = $this->createScopeFor($resource, $scopeIdentifier);
47
48
        // This will be the new children list of parents (parents parents, plus the parent)
49 28
        $scopeArray = $parentScopeInstance->getParentScopes();
50 28
        $scopeArray[] = $parentScopeInstance->getScopeIdentifier();
51
52 28
        $scopeInstance->setParentScopes($scopeArray);
53
54
55 28
        return $scopeInstance;
56
    }
57
}
58