Completed
Push — master ( f71faa...7b17ad )
by Tom
03:02
created

ValueData::callFunc()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 3
1
<?php
2
/* @description     Transformation Style Sheets - Revolutionising PHP templating    *
3
 * @author          Tom Butler [email protected]                                             *
4
 * @copyright       2015 Tom Butler <[email protected]> | https://r.je/                      *
5
 * @license         http://www.opensource.org/licenses/bsd-license.php  BSD License *
6
 * @version         1.0                                                             */
7
namespace Transphporm\Parser;
8
/** Holds the data used by `ValueParser` */
9
class ValueData {
10
	private $data;
11
12
	public function __construct($data) {
13
		$this->data = $data;
14
	}
15
16
	public function traverse($key) {
17
		if (isset($this->data->{$key})) $this->data = $this->data->{$key};
18 View Code Duplication
		else if (is_array($this->data) && isset($this->data[$key])) $this->data = $this->data[$key];
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
	}
20
21
	public function read($value) {
22
		if (is_array($this->data)) {
23
			if (isset($this->data[$value])) return $this->data[$value];
24
		}
25
		else if (is_scalar($value) && isset($this->data->$value)) return $this->data->$value;
26
		else return false;
27
	}
28
29
	public function isFunctionSet() {
30
		return $this->data instanceof \Transphporm\Functioset;
0 ignored issues
show
Bug introduced by
The class Transphporm\Functioset does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
31
	}
32
33
	public function call($func, $args) {
34
		return $this->data->$func(...$args);
35
	}
36
37
	public function parseNested($parser, $token, $funcName) {
38
		$args = $parser->parseTokens($token['value'], $this->data);
39
		if ($args[0] == $this->data) $args = [];
40
		return $this->callFunc($funcName, $args, $this->data);
41
	}
42
43
	private function callFunc($name, $args, $data) {
0 ignored issues
show
Unused Code introduced by
The parameter $data is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
44
		return $this->callFuncOnObject($this->data, $name, $args);
45
	}
46
47
	private function callFuncOnObject($obj, $func, $args) {
48
		if (isset($obj->$func) && is_callable($obj->$func)) return call_user_func_array($obj->$func, $args);
49
		else return call_user_func_array([$obj, $func], $args);
50
	}
51
52
	public function extract($last, $autoLookup) {
53
		if ($autoLookup && isset($this->data->{$last})) {
54
			return $this->data->{$last};
55
		}
56 View Code Duplication
		else if (is_array($this->data) && isset($this->data[$last])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
57
			return $this->data[$last];
58
		}
59
		throw new \UnexpectedValueException('Not found');
60
	}
61
}