Server IP : 127.0.0.2 / Your IP : 13.58.199.13 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/html/vendor/psy/psysh/src/Psy/CodeCleaner/ |
Upload File : |
<?php /* * This file is part of Psy Shell. * * (c) 2012-2017 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Psy\CodeCleaner; use PhpParser\Node; use PhpParser\Node\Scalar\DNumber; use PhpParser\Node\Scalar\LNumber; use PhpParser\Node\Stmt\Break_; use PhpParser\Node\Stmt\Continue_; use PhpParser\Node\Stmt\Do_; use PhpParser\Node\Stmt\For_; use PhpParser\Node\Stmt\Foreach_; use PhpParser\Node\Stmt\Switch_; use PhpParser\Node\Stmt\While_; use Psy\Exception\FatalErrorException; /** * The loop context pass handles invalid `break` and `continue` statements. */ class LoopContextPass extends CodeCleanerPass { private $isPHP54; private $loopDepth; public function __construct() { $this->isPHP54 = version_compare(PHP_VERSION, '5.4.0', '>='); } /** * {@inheritdoc} */ public function beforeTraverse(array $nodes) { $this->loopDepth = 0; } /** * @throws FatalErrorException if the node is a break or continue in a non-loop or switch context * @throws FatalErrorException if the node is trying to break out of more nested structures than exist * @throws FatalErrorException if the node is a break or continue and has a non-numeric argument * @throws FatalErrorException if the node is a break or continue and has an argument less than 1 * * @param Node $node */ public function enterNode(Node $node) { switch (true) { case $node instanceof Do_: case $node instanceof For_: case $node instanceof Foreach_: case $node instanceof Switch_: case $node instanceof While_: $this->loopDepth++; break; case $node instanceof Break_: case $node instanceof Continue_: $operator = $node instanceof Break_ ? 'break' : 'continue'; if ($this->loopDepth === 0) { $msg = sprintf("'%s' not in the 'loop' or 'switch' context", $operator); throw new FatalErrorException($msg, 0, E_ERROR, null, $node->getLine()); } if ($node->num instanceof LNumber || $node->num instanceof DNumber) { $num = $node->num->value; if ($this->isPHP54 && ($node->num instanceof DNumber || $num < 1)) { $msg = sprintf("'%s' operator accepts only positive numbers", $operator); throw new FatalErrorException($msg, 0, E_ERROR, null, $node->getLine()); } if ($num > $this->loopDepth) { $msg = sprintf("Cannot '%s' %d levels", $operator, $num); throw new FatalErrorException($msg, 0, E_ERROR, null, $node->getLine()); } } elseif ($node->num && $this->isPHP54) { $msg = sprintf("'%s' operator with non-constant operand is no longer supported", $operator); throw new FatalErrorException($msg, 0, E_ERROR, null, $node->getLine()); } break; } } /** * @param Node $node */ public function leaveNode(Node $node) { switch (true) { case $node instanceof Do_: case $node instanceof For_: case $node instanceof Foreach_: case $node instanceof Switch_: case $node instanceof While_: $this->loopDepth--; break; } } }