Completed
Branch develop (2aa849)
by Steve
09:08
created

ParentDelegationBuilder::getParentContext()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace StoutLogic\AcfBuilder;
4
5
/**
6
 * Builds a configuration.
7
 * Can have parent contexts to delegate missing methods to.
8
 */
9
abstract class ParentDelegationBuilder implements Builder
10
{
11
    /**
12
     * The parent Builder, if this is a child Builder
13
     * @var Builder
14
     */
15
    private $parentContext;
16
17
    /**
18
     * Builds the configuration
19
     * @return array configuration
20
     */
21
    abstract public function build();
22
23
    /**
24
     * @param Builder $builder
25
     */
26
    public function setParentContext(Builder $builder)
27
    {
28
        $this->parentContext = $builder;
29
    }
30
31
    /**
32
     * @return Builder
33
     */
34
    public function getParentContext()
35
    {
36
        return $this->parentContext;
37
    }
38
39
    /**
40
     * If a method is missing, check to see if it exist on the $parentContext
41
     * and delegate the call to it.
42
     * @param  string $method
43
     * @param  array $args
44
     * @throws \Exception when a method is not found on the $parentContext
45
     * @return mixed
46
     */
47
    public function __call($method, $args)
48
    {
49
        if ($this->parentContext) {
50
            return call_user_func_array([$this->parentContext, $method], $args);
51
        }
52
53
        throw new \Exception('No such function: '.$method);
54
    }
55
}
56