Completed
Pull Request — master (#306)
by Benoît
33:19
created

ScopeFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 2
c 2
b 0
f 1
lcom 0
cbo 1
dl 0
loc 33
ccs 8
cts 8
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createScopeFor() 0 4 1
A createChildScopeFor() 0 12 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
     * @param Manager $manager
20
     * @param ResourceInterface $resource
21
     * @param string|null $scopeIdentifier
22
     * @return Scope
23
     */
24 36
    public function createScopeFor(Manager $manager, ResourceInterface $resource, $scopeIdentifier = null)
25
    {
26 36
        return new Scope($manager, $resource, $scopeIdentifier);
27
    }
28
29
    /**
30
     * @param Manager $manager
31
     * @param Scope $parentScopeInstance
32
     * @param ResourceInterface $resource
33
     * @param string|null $scopeIdentifier
34
     * @return Scope
35
     */
36 30
    public function createChildScopeFor(Manager $manager, Scope $parentScopeInstance, ResourceInterface $resource, $scopeIdentifier = null)
37
    {
38 30
        $scopeInstance = $this->createScopeFor($manager, $resource, $scopeIdentifier);
39
40
        // This will be the new children list of parents (parents parents, plus the parent)
41 30
        $scopeArray = $parentScopeInstance->getParentScopes();
42 30
        $scopeArray[] = $parentScopeInstance->getScopeIdentifier();
43
44 30
        $scopeInstance->setParentScopes($scopeArray);
45
46 30
        return $scopeInstance;
47
    }
48
}
49