Completed
Push — master ( 9da703...f9ad19 )
by Dmitry
02:41
created

Asserter::visitMethodDimension()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 34
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3.2098

Importance

Changes 0
Metric Value
dl 0
loc 34
c 0
b 0
f 0
ccs 10
cts 14
cp 0.7143
rs 8.8571
cc 3
eloc 23
nc 3
nop 6
crap 3.2098
1
<?php
2
/**
3
 * PHP Billing Library
4
 *
5
 * @link      https://github.com/hiqdev/php-billing
6
 * @package   php-billing
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2017-2018, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\php\billing\formula;
12
13
use Hoa\Ruler\Model;
14
use Hoa\Ruler\Model\Bag\Context;
15
16
/**
17
 * @author Andrii Vasyliev <[email protected]>
18
 */
19
class Asserter extends \Hoa\Ruler\Visitor\Asserter
20
{
21 1
    public function visitModel(Model $element, &$handle = null, $eldnah = null)
22
    {
23 1
        return $element->getExpression()->accept($this, $handle, $eldnah);
24
    }
25
26
    /**
27
     * Visit a method dimension.
28
     *
29
     * @param   mixed &$contextPointer Pointer to the current context.
30
     * @param   array $dimension Dimension bucket.
31
     * @param   int $dimensionNumber Dimension number.
32
     * @param   string $elementId Element name.
33
     * @param   mixed &$handle Handle (reference).
34
     * @param   mixed $eldnah Handle (not reference).
35
     * @return  void
36
     * @throws \Hoa\Ruler\Exception\Asserter
37 1
     */
38
    protected function visitMethodDimension(
39
        &$contextPointer,
40
        array $dimension,
41
        $dimensionNumber,
42
        $elementId,
43
        &$handle = null,
44
        $eldnah  = null
45 1
    ) {
46 1
        $value  = $dimension[Context::ACCESS_VALUE];
47
        $method = $value->getName();
48 1
49
        if (!is_object($contextPointer)) {
50
            throw new \Hoa\Ruler\Exception\Asserter(
51
                'Try to call an undefined method: %s ' .
52
                '(dimension number %d of %s), because it is ' .
53
                'not an object.',
54
                7,
55
                [$method, $dimensionNumber, $elementId]
56
            );
57
        }
58 1
59
        $arguments = [];
60 1
61 1
        foreach ($value->getArguments() as $argument) {
62
            $arguments[] = $argument->accept($this, $handle, $eldnah);
63
        }
64 1
65 1
        $contextPointer = call_user_func_array(
66 1
            [$contextPointer, $method],
67
            $arguments
68
        );
69 1
70
        return;
71
    }
72
}
73