RunningSuit::executeInjectedString()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 3
dl 0
loc 7
ccs 4
cts 5
cp 0.8
crap 2.032
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is a part of "Axessors" library.
4
 *
5
 * @author <[email protected]>
6
 * @license GPL
7
 */
8
9
namespace NoOne4rever\Axessors;
10
11
/**
12
 * Class RunningSuit.
13
 * 
14
 * Stores running configuration.
15
 * 
16
 * @package NoOne4rever\Axessors
17
 */
18
abstract class RunningSuit
19
{
20
    public const INPUT_MODE = 4;
21
    public const OUTPUT_MODE = 8;
22
    
23
    /** @var object|null object */
24
    protected $object;
25
    /** @var PropertyData property data */
26
    protected $propertyData;
27
    /** @var string class */
28
    protected $class;
29
    /** @var int running mode */
30
    protected $mode;
31
32
    /**
33
     * RunningSuit constructor.
34
     * 
35
     * @param int $mode running mode
36
     * @param PropertyData $data property data
37
     * @param string $class class name
38
     * @param object|null $object object with called method
39
     */
40 92
    public function __construct(int $mode, PropertyData $data, string $class, $object = null)
41
    {
42 92
        $this->mode = $mode;
43 92
        $this->propertyData = $data;
44 92
        $this->class = $class;
45 92
        $this->object = $object;
46 92
    }
47
48
    /**
49
     * Runs *injected* callback or condition.
50
     * 
51
     * @param string $expr *injected* string
52
     * @param mixed $var variable to process 
53
     * @param bool $mode mode of execution
54
     * @return mixed the result of *injected* string execution
55
     */
56 9
    protected function executeInjectedString(string $expr, $var, bool $mode)
57
    {
58 9
        $handler = str_replace('\\`', '`', substr($expr, 1, strlen($expr) - 2));
59 9
        if (is_null($this->object)) {
60
            return call_user_func("{$this->class}::__axessorsExecuteStatic", $handler, $var, $mode);
61
        } else {
62 9
            return $this->object->__axessorsExecute($handler, $var, $mode);
63
        }
64
    }
65
}