_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q26400
Shell.readline
train
protected function readline() { if (!empty($this->inputBuffer)) { $line = \array_shift($this->inputBuffer); if (!$line instanceof SilentInput) { $this->output->writeln(\sprintf('<aside>%s %s</aside>', static::REPLAY, OutputFormatter::escape($line))); } ...
php
{ "resource": "" }
q26401
Shell.initializeTabCompletion
train
protected function initializeTabCompletion() { if (!$this->config->useTabCompletion()) { return; } $this->autoCompleter = $this->config->getAutoCompleter(); // auto completer needs shell to be linked to configuration because of // the context aware matchers ...
php
{ "resource": "" }
q26402
Shell.addMatchersToAutoCompleter
train
private function addMatchersToAutoCompleter(array $matchers) { foreach ($matchers as $matcher) { if ($matcher instanceof ContextAware) { $matcher->setContext($this->context); } $this->autoCompleter->addMatcher($matcher); } }
php
{ "resource": "" }
q26403
Shell.writeStartupMessage
train
protected function writeStartupMessage() { $message = $this->config->getStartupMessage(); if ($message !== null && $message !== '') { $this->output->writeln($message); } }
php
{ "resource": "" }
q26404
ClassConstantEnumerator.getConstants
train
protected function getConstants(\Reflector $reflector, $noInherit = false) { $className = $reflector->getName(); $constants = []; foreach ($reflector->getConstants() as $name => $constant) { $constReflector = ReflectionClassConstant::create($reflector->name, $name); ...
php
{ "resource": "" }
q26405
ConsoleColorFactory.getConsoleColor
train
public function getConsoleColor() { if ($this->colorMode === Configuration::COLOR_MODE_AUTO) { return $this->getDefaultConsoleColor(); } elseif ($this->colorMode === Configuration::COLOR_MODE_FORCED) { return $this->getForcedConsoleColor(); } elseif ($this->colorMode ...
php
{ "resource": "" }
q26406
Context.get
train
public function get($name) { switch ($name) { case '_': return $this->returnValue; case '_e': if (isset($this->lastException)) { return $this->lastException; } break; case '__out': ...
php
{ "resource": "" }
q26407
Context.setAll
train
public function setAll(array $vars) { foreach (self::$specialNames as $key) { unset($vars[$key]); } foreach (self::$commandScopeNames as $key) { unset($vars[$key]); } $this->scopeVariables = $vars; }
php
{ "resource": "" }
q26408
Context.isSpecialVariableName
train
public static function isSpecialVariableName($name) { return \in_array($name, self::$specialNames) || \in_array($name, self::$commandScopeNames); }
php
{ "resource": "" }
q26409
ThrowUpException.fromThrowable
train
public static function fromThrowable($throwable) { if ($throwable instanceof \Error) { $throwable = ErrorException::fromError($throwable); } if (!$throwable instanceof \Exception) { throw new \InvalidArgumentException('throw-up can only throw Exceptions and Errors');...
php
{ "resource": "" }
q26410
UseStatementPass.enterNode
train
public function enterNode(Node $node) { if ($node instanceof Namespace_) { // If this is the same namespace as last namespace, let's do ourselves // a favor and reload all the aliases... if (\strtolower($node->name) === \strtolower($this->lastNamespace)) { ...
php
{ "resource": "" }
q26411
UseStatementPass.leaveNode
train
public function leaveNode(Node $node) { if ($node instanceof Use_) { // Store a reference to every "use" statement, because we'll need // them in a bit. foreach ($node->uses as $use) { $alias = $use->alias ?: \end($use->name->parts); $this-...
php
{ "resource": "" }
q26412
Enumerator.enumerate
train
public function enumerate(InputInterface $input, \Reflector $reflector = null, $target = null) { $this->filter->bind($input); return $this->listItems($input, $reflector, $target); }
php
{ "resource": "" }
q26413
Configuration.init
train
public function init() { // feature detection $this->hasReadline = \function_exists('readline'); $this->hasPcntl = \function_exists('pcntl_signal') && \function_exists('posix_getpid'); if ($configFile = $this->getConfigFile()) { $this->loadConfigFile($configFile); ...
php
{ "resource": "" }
q26414
Configuration.getConfigFile
train
public function getConfigFile() { if (isset($this->configFile)) { return $this->configFile; } $files = ConfigPaths::getConfigFiles(['config.php', 'rc.php'], $this->configDir); if (!empty($files)) { if ($this->warnOnMultipleConfigs && \count($files) > 1) { ...
php
{ "resource": "" }
q26415
Configuration.loadConfig
train
public function loadConfig(array $options) { foreach (self::$AVAILABLE_OPTIONS as $option) { if (isset($options[$option])) { $method = 'set' . \ucfirst($option); $this->$method($options[$option]); } } // legacy `tabCompletion` option ...
php
{ "resource": "" }
q26416
Configuration.getRuntimeDir
train
public function getRuntimeDir() { if (!isset($this->runtimeDir)) { $this->runtimeDir = ConfigPaths::getRuntimeDir(); } if (!\is_dir($this->runtimeDir)) { \mkdir($this->runtimeDir, 0700, true); } return $this->runtimeDir; }
php
{ "resource": "" }
q26417
Configuration.getHistoryFile
train
public function getHistoryFile() { if (isset($this->historyFile)) { return $this->historyFile; } $files = ConfigPaths::getConfigFiles(['psysh_history', 'history'], $this->configDir); if (!empty($files)) { if ($this->warnOnMultipleConfigs && \count($files) > ...
php
{ "resource": "" }
q26418
Configuration.useReadline
train
public function useReadline() { return isset($this->useReadline) ? ($this->hasReadline && $this->useReadline) : $this->hasReadline; }
php
{ "resource": "" }
q26419
Configuration.getReadline
train
public function getReadline() { if (!isset($this->readline)) { $className = $this->getReadlineClass(); $this->readline = new $className( $this->getHistoryFile(), $this->getHistorySize(), $this->getEraseDuplicates() ); ...
php
{ "resource": "" }
q26420
Configuration.usePcntl
train
public function usePcntl() { return isset($this->usePcntl) ? ($this->hasPcntl && $this->usePcntl) : $this->hasPcntl; }
php
{ "resource": "" }
q26421
Configuration.useTabCompletion
train
public function useTabCompletion() { return isset($this->useTabCompletion) ? ($this->hasReadline && $this->useTabCompletion) : $this->hasReadline; }
php
{ "resource": "" }
q26422
Configuration.getOutput
train
public function getOutput() { if (!isset($this->output)) { $this->output = new ShellOutput( ShellOutput::VERBOSITY_NORMAL, $this->getOutputDecorated(), null, $this->getPager() ); } return $this->output; ...
php
{ "resource": "" }
q26423
Configuration.setPager
train
public function setPager($pager) { if ($pager && !\is_string($pager) && !$pager instanceof OutputPager) { throw new \InvalidArgumentException('Unexpected pager instance'); } $this->pager = $pager; }
php
{ "resource": "" }
q26424
Configuration.getPager
train
public function getPager() { if (!isset($this->pager) && $this->usePcntl()) { if ($pager = \ini_get('cli.pager')) { // use the default pager $this->pager = $pager; } elseif ($less = \exec('which less 2>/dev/null')) { // check for the pr...
php
{ "resource": "" }
q26425
Configuration.addMatchers
train
public function addMatchers(array $matchers) { $this->newMatchers = \array_merge($this->newMatchers, $matchers); if (isset($this->shell)) { $this->doAddMatchers(); } }
php
{ "resource": "" }
q26426
Configuration.doAddMatchers
train
private function doAddMatchers() { if (!empty($this->newMatchers)) { $this->shell->addMatchers($this->newMatchers); $this->newMatchers = []; } }
php
{ "resource": "" }
q26427
Configuration.addCommands
train
public function addCommands(array $commands) { $this->newCommands = \array_merge($this->newCommands, $commands); if (isset($this->shell)) { $this->doAddCommands(); } }
php
{ "resource": "" }
q26428
Configuration.doAddCommands
train
private function doAddCommands() { if (!empty($this->newCommands)) { $this->shell->addCommands($this->newCommands); $this->newCommands = []; } }
php
{ "resource": "" }
q26429
Configuration.setShell
train
public function setShell(Shell $shell) { $this->shell = $shell; $this->doAddCommands(); $this->doAddMatchers(); }
php
{ "resource": "" }
q26430
Configuration.getManualDbFile
train
public function getManualDbFile() { if (isset($this->manualDbFile)) { return $this->manualDbFile; } $files = ConfigPaths::getDataFiles(['php_manual.sqlite'], $this->dataDir); if (!empty($files)) { if ($this->warnOnMultipleConfigs && \count($files) > 1) { ...
php
{ "resource": "" }
q26431
Configuration.getManualDb
train
public function getManualDb() { if (!isset($this->manualDb)) { $dbFile = $this->getManualDbFile(); if (\is_file($dbFile)) { try { $this->manualDb = new \PDO('sqlite:' . $dbFile); } catch (\PDOException $e) { if (...
php
{ "resource": "" }
q26432
Configuration.getPresenter
train
public function getPresenter() { if (!isset($this->presenter)) { $this->presenter = new Presenter($this->getOutput()->getFormatter(), $this->forceArrayIndexes()); } return $this->presenter; }
php
{ "resource": "" }
q26433
Configuration.setColorMode
train
public function setColorMode($colorMode) { $validColorModes = [ self::COLOR_MODE_AUTO, self::COLOR_MODE_FORCED, self::COLOR_MODE_DISABLED, ]; if (\in_array($colorMode, $validColorModes)) { $this->colorMode = $colorMode; } else { ...
php
{ "resource": "" }
q26434
Configuration.getChecker
train
public function getChecker() { if (!isset($this->checker)) { $interval = $this->getUpdateCheck(); switch ($interval) { case Checker::ALWAYS: $this->checker = new GitHubChecker(); break; case Checker::DAILY: ...
php
{ "resource": "" }
q26435
Configuration.setUpdateCheck
train
public function setUpdateCheck($interval) { $validIntervals = [ Checker::ALWAYS, Checker::DAILY, Checker::WEEKLY, Checker::MONTHLY, Checker::NEVER, ]; if (!\in_array($interval, $validIntervals)) { throw new \InvalidArgu...
php
{ "resource": "" }
q26436
SudoCommand.parse
train
private function parse($code) { try { return $this->parser->parse($code); } catch (\PhpParser\Error $e) { if (\strpos($e->getMessage(), 'unexpected EOF') === false) { throw $e; } // If we got an unexpected EOF, let's try it again with ...
php
{ "resource": "" }
q26437
ExecutionLoop.run
train
public function run(Shell $shell) { $this->loadIncludes($shell); $closure = new ExecutionLoopClosure($shell); $closure->execute(); }
php
{ "resource": "" }
q26438
ExecutionLoop.loadIncludes
train
protected function loadIncludes(Shell $shell) { // Load user-defined includes $load = function (Shell $__psysh__) { \set_error_handler([$__psysh__, 'handleError']); foreach ($__psysh__->getIncludes() as $__psysh_include__) { try { include $...
php
{ "resource": "" }
q26439
StrictTypesPass.beforeTraverse
train
public function beforeTraverse(array $nodes) { if (!$this->atLeastPhp7) { return; // @codeCoverageIgnore } $prependStrictTypes = $this->strictTypes; foreach ($nodes as $key => $node) { if ($node instanceof Declare_) { foreach ($node->declares...
php
{ "resource": "" }
q26440
Mirror.get
train
public static function get($value, $member = null, $filter = 15) { if ($member === null && \is_string($value)) { if (\function_exists($value)) { return new \ReflectionFunction($value); } elseif (\defined($value) || ReflectionConstant_::isMagicConstant($value)) { ...
php
{ "resource": "" }
q26441
InterfaceEnumerator.prepareInterfaces
train
protected function prepareInterfaces(array $interfaces) { \natcasesort($interfaces); // My kingdom for a generator. $ret = []; foreach ($interfaces as $name) { if ($this->showItem($name)) { $ret[$name] = [ 'name' => $name, ...
php
{ "resource": "" }
q26442
LegacyEmptyPass.enterNode
train
public function enterNode(Node $node) { if ($this->atLeastPhp55) { return; } if (!$node instanceof Empty_) { return; } if (!$node->expr instanceof Variable) { $msg = \sprintf('syntax error, unexpected %s', $this->getUnexpectedThing($node-...
php
{ "resource": "" }
q26443
ThrowUpCommand.prepareArgs
train
private function prepareArgs($code = null) { if (!$code) { // Default to last exception if nothing else was supplied return [new Arg(new Variable('_e'))]; } if (\strpos('<?', $code) === false) { $code = '<?php ' . $code; } $nodes = $this-...
php
{ "resource": "" }
q26444
ListCommand.initEnumerators
train
protected function initEnumerators() { if (!isset($this->enumerators)) { $mgr = $this->presenter; $this->enumerators = [ new ClassConstantEnumerator($mgr), new ClassEnumerator($mgr), new ConstantEnumerator($mgr), new Fu...
php
{ "resource": "" }
q26445
ListCommand.validateInput
train
private function validateInput(InputInterface $input) { if (!$input->getArgument('target')) { // if no target is passed, there can be no properties or methods foreach (['properties', 'methods', 'no-inherit'] as $option) { if ($input->getOption($option)) { ...
php
{ "resource": "" }
q26446
TimeitVisitor.getEndCall
train
private function getEndCall(Expr $arg = null) { if ($arg === null) { $arg = NoReturnValue::create(); } return new StaticCall(new FullyQualifiedName('Psy\Command\TimeitCommand'), 'markEnd', [new Arg($arg)]); }
php
{ "resource": "" }
q26447
ParseCommand.setPresenter
train
public function setPresenter(Presenter $presenter) { $this->presenter = clone $presenter; $this->presenter->addCasters([ 'PhpParser\Node' => function (Node $node, array $a) { $a = [ Caster::PREFIX_VIRTUAL . 'type' => $node->getType(), ...
php
{ "resource": "" }
q26448
NamespacePass.beforeTraverse
train
public function beforeTraverse(array $nodes) { if (empty($nodes)) { return $nodes; } $last = \end($nodes); if ($last instanceof Namespace_) { $kind = $last->getAttribute('kind'); // Treat all namespace statements pre-PHP-Parser v3.1.2 as "open",...
php
{ "resource": "" }
q26449
ListPass.enterNode
train
public function enterNode(Node $node) { if (!$node instanceof Assign) { return; } if (!$node->var instanceof Array_ && !$node->var instanceof List_) { return; } if (!$this->atLeastPhp71 && $node->var instanceof Array_) { $msg = "syntax er...
php
{ "resource": "" }
q26450
ListPass.isValidArrayItem
train
private static function isValidArrayItem(Expr $item) { $value = ($item instanceof ArrayItem) ? $item->value : $item; while ($value instanceof ArrayDimFetch || $value instanceof PropertyFetch) { $value = $value->var; } // We just kind of give up if it's a method call. We...
php
{ "resource": "" }
q26451
VariableEnumerator.getVariables
train
protected function getVariables($showAll) { $scopeVars = $this->context->getAll(); \uksort($scopeVars, function ($a, $b) { $aIndex = \array_search($a, self::$specialNames); $bIndex = \array_search($b, self::$specialNames); if ($aIndex !== false) { ...
php
{ "resource": "" }
q26452
VariableEnumerator.prepareVariables
train
protected function prepareVariables(array $variables) { // My kingdom for a generator. $ret = []; foreach ($variables as $name => $val) { if ($this->showItem($name)) { $fname = '$' . $name; $ret[$fname] = [ 'name' => $fname, ...
php
{ "resource": "" }
q26453
ErrorException.fromError
train
public static function fromError(\Error $e) { return new self($e->getMessage(), $e->getCode(), 1, $e->getFile(), $e->getLine(), $e); }
php
{ "resource": "" }
q26454
HistoryCommand.extractRange
train
private function extractRange($range) { if (\preg_match('/^\d+$/', $range)) { return [$range, $range + 1]; } $matches = []; if ($range !== '..' && \preg_match('/^(\d*)\.\.(\d*)$/', $range, $matches)) { $start = $matches[1] ? \intval($matches[1]) : 0; ...
php
{ "resource": "" }
q26455
HistoryCommand.getHistorySlice
train
private function getHistorySlice($show, $head, $tail) { $history = $this->readline->listHistory(); // don't show the current `history` invocation \array_pop($history); if ($show) { list($start, $end) = $this->extractRange($show); $length = $end - $start; ...
php
{ "resource": "" }
q26456
ProcessForker.beforeRun
train
public function beforeRun(Shell $shell) { list($up, $down) = \stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP); if (!$up) { throw new \RuntimeException('Unable to create socket pair'); } $pid = \pcntl_fork(); if ($pid < 0) { ...
php
{ "resource": "" }
q26457
ProcessForker.afterLoop
train
public function afterLoop(Shell $shell) { // if there's an old savegame hanging around, let's kill it. if (isset($this->savegame)) { \posix_kill($this->savegame, SIGKILL); \pcntl_signal_dispatch(); } }
php
{ "resource": "" }
q26458
ProcessForker.createSavegame
train
private function createSavegame() { // the current process will become the savegame $this->savegame = \posix_getpid(); $pid = \pcntl_fork(); if ($pid < 0) { throw new \RuntimeException('Unable to create savegame fork'); } elseif ($pid > 0) { // we're ...
php
{ "resource": "" }
q26459
ProcessForker.serializeReturn
train
private function serializeReturn(array $return) { $serializable = []; foreach ($return as $key => $value) { // No need to return magic variables if (Context::isSpecialVariableName($key)) { continue; } // Resources and Closures don't e...
php
{ "resource": "" }
q26460
Command.argumentsAsText
train
private function argumentsAsText() { $max = $this->getMaxWidth(); $messages = []; $arguments = $this->getArguments(); if (!empty($arguments)) { $messages[] = '<comment>Arguments:</comment>'; foreach ($arguments as $argument) { if (null !== $ar...
php
{ "resource": "" }
q26461
Command.optionsAsText
train
private function optionsAsText() { $max = $this->getMaxWidth(); $messages = []; $options = $this->getOptions(); if ($options) { $messages[] = '<comment>Options:</comment>'; foreach ($options as $option) { if ($option->acceptValue() && null !=...
php
{ "resource": "" }
q26462
Command.getMaxWidth
train
private function getMaxWidth() { $max = 0; foreach ($this->getOptions() as $option) { $nameLength = \strlen($option->getName()) + 2; if ($option->getShortcut()) { $nameLength += \strlen($option->getShortcut()) + 3; } $max = \max($max,...
php
{ "resource": "" }
q26463
Command.getTable
train
protected function getTable(OutputInterface $output) { if (!\class_exists('Symfony\Component\Console\Helper\Table')) { return $this->getTableHelper(); } $style = new TableStyle(); $style ->setVerticalBorderChar(' ') ->setHorizontalBorderChar('') ...
php
{ "resource": "" }
q26464
Command.getTableHelper
train
protected function getTableHelper() { $table = $this->getApplication()->getHelperSet()->get('table'); return $table ->setRows([]) ->setLayout(TableHelper::LAYOUT_BORDERLESS) ->setHorizontalBorderChar('') ->setCrossingChar(''); }
php
{ "resource": "" }
q26465
FilterOptions.getOptions
train
public static function getOptions() { return [ new InputOption('grep', 'G', InputOption::VALUE_REQUIRED, 'Limit to items matching the given pattern (string or regex).'), new InputOption('insensitive', 'i', InputOption::VALUE_NONE, 'Case-insensitive search (requires --grep)...
php
{ "resource": "" }
q26466
FilterOptions.bind
train
public function bind(InputInterface $input) { $this->validateInput($input); if (!$pattern = $input->getOption('grep')) { $this->filter = false; return; } if (!$this->stringIsRegex($pattern)) { $pattern = '/' . \preg_quote($pattern, '/') . '/'; ...
php
{ "resource": "" }
q26467
FilterOptions.match
train
public function match($string, array &$matches = null) { return $this->filter === false || (\preg_match($this->pattern, $string, $matches) xor $this->invert); }
php
{ "resource": "" }
q26468
FilterOptions.validateInput
train
private function validateInput(InputInterface $input) { if (!$input->getOption('grep')) { foreach (['invert', 'insensitive'] as $option) { if ($input->getOption($option)) { throw new RuntimeException('--' . $option . ' does not make sense without --grep'); ...
php
{ "resource": "" }
q26469
ProcOutputPager.close
train
public function close() { if (isset($this->pipe)) { \fclose($this->pipe); } if (isset($this->proc)) { $exit = \proc_close($this->proc); if ($exit !== 0) { throw new \RuntimeException('Error closing output stream'); } } ...
php
{ "resource": "" }
q26470
ProcOutputPager.getPipe
train
private function getPipe() { if (!isset($this->pipe) || !isset($this->proc)) { $desc = [['pipe', 'r'], $this->stream, \fopen('php://stderr', 'w')]; $this->proc = \proc_open($this->cmd, $desc, $pipes); if (!\is_resource($this->proc)) { throw new \RuntimeEx...
php
{ "resource": "" }
q26471
ImplicitReturnPass.isNonExpressionStmt
train
private static function isNonExpressionStmt(Node $node) { return $node instanceof Stmt && !$node instanceof Expression && !$node instanceof Return_ && !$node instanceof Namespace_; }
php
{ "resource": "" }
q26472
MethodEnumerator.getMethods
train
protected function getMethods($showAll, \Reflector $reflector, $noInherit = false) { $className = $reflector->getName(); $methods = []; foreach ($reflector->getMethods() as $name => $method) { if ($noInherit && $method->getDeclaringClass()->getName() !== $className) { ...
php
{ "resource": "" }
q26473
MethodEnumerator.prepareMethods
train
protected function prepareMethods(array $methods) { // My kingdom for a generator. $ret = []; foreach ($methods as $name => $method) { if ($this->showItem($name)) { $ret[$name] = [ 'name' => $name, 'style' => $this->getVis...
php
{ "resource": "" }
q26474
MethodEnumerator.getVisibilityStyle
train
private function getVisibilityStyle(\ReflectionMethod $method) { if ($method->isPublic()) { return self::IS_PUBLIC; } elseif ($method->isProtected()) { return self::IS_PROTECTED; } else { return self::IS_PRIVATE; } }
php
{ "resource": "" }
q26475
ExecutionClosure.setClosure
train
protected function setClosure(Shell $shell, \Closure $closure) { if (self::shouldBindClosure()) { $that = $shell->getBoundObject(); if (\is_object($that)) { $closure = $closure->bindTo($that, \get_class($that)); } else { $closure = $closure...
php
{ "resource": "" }
q26476
CallTimePassByReferencePass.enterNode
train
public function enterNode(Node $node) { if (!$node instanceof FuncCall && !$node instanceof MethodCall && !$node instanceof StaticCall) { return; } foreach ($node->args as $arg) { if ($arg->byRef) { throw new FatalErrorException(self::EXCEPTION_MESSAG...
php
{ "resource": "" }
q26477
WhereamiCommand.trace
train
protected function trace() { foreach (\array_reverse($this->backtrace) as $stackFrame) { if ($this->isDebugCall($stackFrame)) { return $stackFrame; } } return \end($this->backtrace); }
php
{ "resource": "" }
q26478
WhereamiCommand.fileInfo
train
protected function fileInfo() { $stackFrame = $this->trace(); if (\preg_match('/eval\(/', $stackFrame['file'])) { \preg_match_all('/([^\(]+)\((\d+)/', $stackFrame['file'], $matches); $file = $matches[1][0]; $line = (int) $matches[2][0]; } else { ...
php
{ "resource": "" }
q26479
PropertyEnumerator.getProperties
train
protected function getProperties($showAll, \Reflector $reflector, $noInherit = false) { $className = $reflector->getName(); $properties = []; foreach ($reflector->getProperties() as $property) { if ($noInherit && $property->getDeclaringClass()->getName() !== $className) { ...
php
{ "resource": "" }
q26480
PropertyEnumerator.prepareProperties
train
protected function prepareProperties(array $properties, $target = null) { // My kingdom for a generator. $ret = []; foreach ($properties as $name => $property) { if ($this->showItem($name)) { $fname = '$' . $name; $ret[$fname] = [ ...
php
{ "resource": "" }
q26481
PropertyEnumerator.getVisibilityStyle
train
private function getVisibilityStyle(\ReflectionProperty $property) { if ($property->isPublic()) { return self::IS_PUBLIC; } elseif ($property->isProtected()) { return self::IS_PROTECTED; } else { return self::IS_PRIVATE; } }
php
{ "resource": "" }
q26482
FunctionEnumerator.getFunctions
train
protected function getFunctions($type = null) { $funcs = \get_defined_functions(); if ($type) { return $funcs[$type]; } else { return \array_merge($funcs['internal'], $funcs['user']); } }
php
{ "resource": "" }
q26483
FunctionEnumerator.prepareFunctions
train
protected function prepareFunctions(array $functions) { \natcasesort($functions); // My kingdom for a generator. $ret = []; foreach ($functions as $name) { if ($this->showItem($name)) { $ret[$name] = [ 'name' => $name, ...
php
{ "resource": "" }
q26484
ShellInput.tokenize
train
private function tokenize($input) { $tokens = []; $length = \strlen($input); $cursor = 0; while ($cursor < $length) { if (\preg_match('/\s+/A', $input, $match, null, $cursor)) { } elseif (\preg_match('/([^="\'\s]+?)(=?)(' . StringInput::REGEX_QUOTED_STRING . '...
php
{ "resource": "" }
q26485
ShellInput.parse
train
protected function parse() { $parseOptions = true; $this->parsed = $this->tokenPairs; while (null !== $tokenPair = \array_shift($this->parsed)) { // token is what you'd expect. rest is the remainder of the input // string, including token, and will be used if this is ...
php
{ "resource": "" }
q26486
ShellInput.parseShellArgument
train
private function parseShellArgument($token, $rest) { $c = \count($this->arguments); // if input is expecting another argument, add it if ($this->definition->hasArgument($c)) { $arg = $this->definition->getArgument($c); if ($arg instanceof CodeArgument) { ...
php
{ "resource": "" }
q26487
InstanceOfPass.enterNode
train
public function enterNode(Node $node) { if (!$node instanceof Instanceof_) { return; } if (($node->expr instanceof Scalar && !$node->expr instanceof Encapsed) || $node->expr instanceof ConstFetch) { throw new FatalErrorException(self::EXCEPTION_MSG, 0, E_ERROR, null,...
php
{ "resource": "" }
q26488
TimeitCommand.markEnd
train
public static function markEnd($ret = null) { self::$times[] = \microtime(true) - self::$start; self::$start = null; return $ret; }
php
{ "resource": "" }
q26489
TimeitCommand.instrumentCode
train
private function instrumentCode($code) { return $this->printer->prettyPrint($this->traverser->traverse($this->parse($code))); }
php
{ "resource": "" }
q26490
AbstractMatcher.getInput
train
protected function getInput(array $tokens) { $var = ''; $firstToken = \array_pop($tokens); if (self::tokenIs($firstToken, self::T_STRING)) { $var = $firstToken[1]; } return $var; }
php
{ "resource": "" }
q26491
ReflectionLanguageConstruct.getParameters
train
public function getParameters() { $params = []; foreach (self::$languageConstructs[$this->keyword] as $parameter => $opts) { \array_push($params, new ReflectionLanguageConstructParameter($this->keyword, $parameter, $opts)); } return $params; }
php
{ "resource": "" }
q26492
Presenter.present
train
public function present($value, $depth = null, $options = 0) { $data = $this->cloner->cloneVar($value, !($options & self::VERBOSE) ? Caster::EXCLUDE_VERBOSE : 0); if (null !== $depth) { $data = $data->withMaxDepth($depth); } // Work around https://github.com/symfony/sym...
php
{ "resource": "" }
q26493
ClassEnumerator.filterClasses
train
protected function filterClasses($key, $classes, $internal, $user) { $ret = []; if ($internal) { $ret['Internal ' . $key] = \array_filter($classes, function ($class) { $refl = new \ReflectionClass($class); return $refl->isInternal(); }); ...
php
{ "resource": "" }
q26494
ClassEnumerator.prepareClasses
train
protected function prepareClasses(array $classes) { \natcasesort($classes); // My kingdom for a generator. $ret = []; foreach ($classes as $name) { if ($this->showItem($name)) { $ret[$name] = [ 'name' => $name, 's...
php
{ "resource": "" }
q26495
AutoCompleter.processCallback
train
public function processCallback($input, $index, $info = []) { // Some (Windows?) systems provide incomplete `readline_info`, so let's // try to work around it. $line = $info['line_buffer']; if (isset($info['end'])) { $line = \substr($line, 0, $info['end']); } ...
php
{ "resource": "" }
q26496
PassableByReferencePass.validateArrayMultisort
train
private function validateArrayMultisort(Node $node) { $nonPassable = 2; // start with 2 because the first one has to be passable by reference foreach ($node->args as $arg) { if ($this->isPassableByReference($arg)) { $nonPassable = 0; } elseif (++$nonPassable >...
php
{ "resource": "" }
q26497
ShellOutput.page
train
public function page($messages, $type = 0) { if (\is_string($messages)) { $messages = (array) $messages; } if (!\is_array($messages) && !\is_callable($messages)) { throw new \InvalidArgumentException('Paged output requires a string, array or callback'); } ...
php
{ "resource": "" }
q26498
ShellOutput.initFormatters
train
private function initFormatters() { $formatter = $this->getFormatter(); $formatter->setStyle('warning', new OutputFormatterStyle('black', 'yellow')); $formatter->setStyle('error', new OutputFormatterStyle('black', 'red', ['bold'])); $formatter->setStyle('aside', new OutputFormat...
php
{ "resource": "" }
q26499
CodeCleaner.getDefaultPasses
train
private function getDefaultPasses() { $useStatementPass = new UseStatementPass(); $namespacePass = new NamespacePass($this); // Try to add implicit `use` statements and an implicit namespace, // based on the file in which the `debug` call was made. $this->addImplicitDebug...
php
{ "resource": "" }