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
|
|
|
else if (is_array($this->data) && isset($this->data[$key])) $this->data = $this->data[$key]; |
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 (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; |
|
|
|
|
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) { |
|
|
|
|
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
|
|
|
$value = $this->read($last); |
54
|
|
|
if ($value && ($autoLookup || is_array($this->data)) ) { |
55
|
|
|
return $value; |
56
|
|
|
} |
57
|
|
|
throw new \UnexpectedValueException('Not found'); |
58
|
|
|
} |
59
|
|
|
} |
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 thecomposer.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
orrequire-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 you have not tested against this specific condition, such errors might go unnoticed.