injitools /
cms-Inji
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Inji; |
||
| 4 | /** |
||
| 5 | * Code generator |
||
| 6 | * |
||
| 7 | * @author Alexey Krupskiy <[email protected]> |
||
| 8 | * @link http://inji.ru/ |
||
| 9 | * @copyright 2015 Alexey Krupskiy |
||
| 10 | * @license https://github.com/injitools/cms-Inji/blob/master/LICENSE |
||
| 11 | */ |
||
| 12 | class CodeGenerator { |
||
| 13 | |||
| 14 | 9 | public static function genArray($data, $level = 0) { |
|
| 15 | 9 | $return = ''; |
|
| 16 | 9 | if ($level == 0) |
|
| 17 | 9 | $return = "["; |
|
| 18 | 9 | foreach ($data as $key => $item) { |
|
| 19 | 9 | $return .= "\n" . str_repeat(' ', ($level * 4 + 4)) . "'{$key}' => "; |
|
| 20 | 9 | if (!is_array($item)) { |
|
| 21 | 9 | if (is_bool($item)) { |
|
| 22 | $item = $item ? 'true' : 'false'; |
||
| 23 | $return .= "{$item},"; |
||
| 24 | 9 | } elseif (is_null($item)) { |
|
| 25 | $return .= "null,"; |
||
| 26 | 9 | } elseif (is_int($item) || is_float($item)) { |
|
| 27 | 9 | $return .= "{$item},"; |
|
| 28 | } else { |
||
| 29 | 9 | $return .= "'" . addcslashes($item, "'") . "',"; |
|
| 30 | } |
||
| 31 | } else { |
||
| 32 | 5 | $return .= "["; |
|
| 33 | 5 | $return .= rtrim(self::genArray($item, $level + 1), ','); |
|
| 34 | 9 | $return .= "\n" . str_repeat(' ', ($level * 4 + 4)) . "],"; |
|
| 35 | } |
||
| 36 | } |
||
| 37 | 9 | if ($level == 0) { |
|
| 38 | 9 | $return = rtrim($return, ',') . "\n];"; |
|
| 39 | } |
||
| 40 | |||
| 41 | 9 | return $return; |
|
| 42 | } |
||
| 43 | |||
| 44 | public static function parseClass($path) { |
||
| 45 | $code = file_get_contents($path); |
||
| 46 | |||
| 47 | $parser = new PhpParser\Parser(new PhpParser\Lexer\Emulative); |
||
|
0 ignored issues
–
show
The type
Inji\PhpParser\Parser was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 48 | |||
| 49 | try { |
||
| 50 | $stmts = $parser->parse($code); |
||
| 51 | $class = new CodeGenerator\ClassGenerator(); |
||
| 52 | $class->name = $stmts[0]->name; |
||
| 53 | $class->extends = implode(',', $stmts[0]->extends->parts); |
||
| 54 | foreach ($stmts[0]->stmts as $stmt) { |
||
| 55 | if (get_class($stmt) == 'PhpParser\Node\Stmt\ClassMethod') { |
||
| 56 | $class->addMethod($stmt->name); |
||
| 57 | } |
||
| 58 | } |
||
| 59 | return $class; |
||
| 60 | // $stmts is an array of statement nodes |
||
| 61 | } catch (PhpParser\Error $e) { |
||
|
0 ignored issues
–
show
The type
Inji\PhpParser\Error was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 62 | echo 'Parse Error: ', $e->getMessage(); |
||
| 63 | exit(); |
||
|
0 ignored issues
–
show
|
|||
| 64 | } |
||
| 65 | } |
||
| 66 | |||
| 67 | } |
||
| 68 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths