1 | <?php |
||
14 | class Tinker |
||
15 | { |
||
16 | /** @var \Symfony\Component\Console\Output\BufferedOutput */ |
||
17 | protected $output; |
||
18 | |||
19 | /** @var \Psy\Shell */ |
||
20 | protected $shell; |
||
21 | |||
22 | public static function execute(string $phpCode): string |
||
26 | |||
27 | public function __construct() |
||
33 | |||
34 | public function run(string $phpCode): string |
||
46 | |||
47 | protected function createShell(BufferedOutput $output): Shell |
||
71 | |||
72 | public function removeComments(string $code): string |
||
73 | { |
||
74 | $tokens = collect(token_get_all("<?php\n".$code.'?>')); |
||
75 | |||
76 | return $tokens->reduce(function ($carry, $token) { |
||
77 | if (is_string($token)) { |
||
78 | return $carry . $token; |
||
79 | } |
||
80 | |||
81 | // Destructure token array |
||
82 | [$id, $text] = $token; |
||
83 | |||
84 | // Ingore comments and php tags |
||
85 | if ($id === T_COMMENT) { |
||
86 | return $carry; |
||
87 | } |
||
88 | if ($id === T_DOC_COMMENT) { |
||
89 | return $carry; |
||
90 | } |
||
91 | if ($id === T_OPEN_TAG) { |
||
92 | return $carry; |
||
93 | } |
||
94 | if ($id === T_CLOSE_TAG) { |
||
95 | return $carry; |
||
96 | } |
||
97 | |||
98 | return $carry . $text; |
||
99 | }, ''); |
||
100 | } |
||
101 | |||
102 | protected function cleanOutput(string $output): string |
||
108 | } |
||
109 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.