_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
33
8k
language
stringclasses
1 value
meta_information
dict
q17400
TextWrapper.getStatus
train
public function getStatus($env = null) { $command = ['status']; if ($env ?: $this->hasOption('environment')) { $command += ['-e' => $env ?: $this->getOption('environment')]; } if ($this->hasOption('configuration')) { $command += ['-c' =>
php
{ "resource": "" }
q17401
TextWrapper.getMigrate
train
public function getMigrate($env = null, $target = null) { $command = ['migrate']; if ($env ?: $this->hasOption('environment')) { $command += ['-e' => $env ?: $this->getOption('environment')]; } if ($this->hasOption('configuration')) { $command += ['-c' => $thi...
php
{ "resource": "" }
q17402
TextWrapper.getRollback
train
public function getRollback($env = null, $target = null) { $command = ['rollback']; if ($env ?: $this->hasOption('environment')) { $command += ['-e' => $env ?: $this->getOption('environment')]; } if ($this->hasOption('configuration')) { $command += ['-c' => $t...
php
{ "resource": "" }
q17403
TextWrapper.getOption
train
protected function getOption($key) { if (!isset($this->options[$key])) { return null;
php
{ "resource": "" }
q17404
TextWrapper.executeRun
train
protected function executeRun(array $command) { // Output will be written to a temporary stream, so that it can be // collected after running the command. $stream = fopen('php://temp', 'w+'); // Execute the command, capturing the output in the temporary stream // and storing...
php
{ "resource": "" }
q17405
Column.setPrecisionAndScale
train
public function setPrecisionAndScale($precision, $scale) {
php
{ "resource": "" }
q17406
Column.setValues
train
public function setValues($values) { if (!is_array($values)) { $values = preg_split('/,\s*/', $values);
php
{ "resource": "" }
q17407
Column.setCollation
train
public function setCollation($collation) { $allowedTypes = [ AdapterInterface::PHINX_TYPE_CHAR, AdapterInterface::PHINX_TYPE_STRING, AdapterInterface::PHINX_TYPE_TEXT,
php
{ "resource": "" }
q17408
Column.setEncoding
train
public function setEncoding($encoding) { $allowedTypes = [ AdapterInterface::PHINX_TYPE_CHAR, AdapterInterface::PHINX_TYPE_STRING, AdapterInterface::PHINX_TYPE_TEXT,
php
{ "resource": "" }
q17409
Column.setOptions
train
public function setOptions($options) { $validOptions = $this->getValidOptions(); $aliasOptions = $this->getAliasedOptions(); foreach ($options as $option => $value) { if (isset($aliasOptions[$option])) { // proxy alias -> option $option = $aliasOp...
php
{ "resource": "" }
q17410
Config.fromYaml
train
public static function fromYaml($configFilePath) { $configFile = file_get_contents($configFilePath); $configArray = Yaml::parse($configFile); if (!is_array($configArray)) { throw new \RuntimeException(sprintf( 'File
php
{ "resource": "" }
q17411
Config.fromJson
train
public static function fromJson($configFilePath) { $configArray = json_decode(file_get_contents($configFilePath), true); if (!is_array($configArray)) { throw new \RuntimeException(sprintf( 'File \'%s\' must be
php
{ "resource": "" }
q17412
Config.fromPhp
train
public static function fromPhp($configFilePath) { ob_start(); /** @noinspection PhpIncludeInspection */ $configArray = include($configFilePath); // Hide console output ob_end_clean(); if (!is_array($configArray)) { throw new \RuntimeException(sprintf(
php
{ "resource": "" }
q17413
Config.replaceTokens
train
protected function replaceTokens(array $arr) { // Get environment variables // $_ENV is empty because variables_order does not include it normally $tokens = []; foreach ($_SERVER as $varname => $varvalue) { if (0 === strpos($varname, 'PHINX_')) { $tokens['...
php
{ "resource": "" }
q17414
Config.recurseArrayForTokens
train
protected function recurseArrayForTokens($arr, $tokens) { $out = []; foreach ($arr as $name => $value) { if (is_array($value)) { $out[$name] = $this->recurseArrayForTokens($value, $tokens); continue; } if (is_string($value)) { ...
php
{ "resource": "" }
q17415
Migrate.execute
train
protected function execute(InputInterface $input, OutputInterface $output) { $this->bootstrap($input, $output); $version = $input->getOption('target'); $environment = $input->getOption('environment'); $date = $input->getOption('date'); $fake = (bool)$input->getOption('fake')...
php
{ "resource": "" }
q17416
PdoAdapter.verboseLog
train
protected function verboseLog($message) { if (!$this->isDryRunEnabled() && $this->getOutput()->getVerbosity()
php
{ "resource": "" }
q17417
PdoAdapter.quoteValue
train
private function quoteValue($value) { if (is_numeric($value)) { return $value; } if ($value === null) { return
php
{ "resource": "" }
q17418
PdoAdapter.executeAlterSteps
train
protected function executeAlterSteps($tableName, AlterInstructions $instructions) {
php
{ "resource": "" }
q17419
Intent.merge
train
public function merge(Intent $another) {
php
{ "resource": "" }
q17420
Table.changePrimaryKey
train
public function changePrimaryKey($columns) { $this->actions->addAction(new
php
{ "resource": "" }
q17421
Table.changeComment
train
public function changeComment($comment) { $this->actions->addAction(new
php
{ "resource": "" }
q17422
Table.getColumn
train
public function getColumn($name) { $columns = array_filter( $this->getColumns(), function ($column) use ($name) {
php
{ "resource": "" }
q17423
Table.removeColumn
train
public function removeColumn($columnName) { $action = RemoveColumn::build($this->table, $columnName);
php
{ "resource": "" }
q17424
Table.removeIndex
train
public function removeIndex($columns) { $action = DropIndex::build($this->table, is_string($columns) ? [$columns] : $columns);
php
{ "resource": "" }
q17425
Table.removeIndexByName
train
public function removeIndexByName($name) { $action = DropIndex::buildFromName($this->table, $name);
php
{ "resource": "" }
q17426
Table.addForeignKeyWithName
train
public function addForeignKeyWithName($name, $columns, $referencedTable, $referencedColumns = ['id'], $options = []) { $action = AddForeignKey::build( $this->table, $columns,
php
{ "resource": "" }
q17427
Table.hasForeignKey
train
public function hasForeignKey($columns, $constraint = null) { return
php
{ "resource": "" }
q17428
Table.executeActions
train
protected function executeActions($exists) { // Renaming a table is tricky, specially when running a reversible migration // down. We will just assume the table already exists if the user commands a // table rename. $renamed = collection($this->actions->getActions()) ->fi...
php
{ "resource": "" }
q17429
DropForeignKey.build
train
public static function build(Table $table, $columns, $constraint = null) { if (is_string($columns)) { $columns = [$columns]; } $foreignKey = new ForeignKey(); $foreignKey->setColumns($columns); if ($constraint) {
php
{ "resource": "" }
q17430
ConfigFileBuilder.add
train
public function add($key, $value) { $array = array_get($this->configs, $key); if (is_array($array)) { $array[] = $value;
php
{ "resource": "" }
q17431
ConfigFileBuilder.useForge
train
public function useForge($phpVersion = self::DEFAULT_PHP_VERSION) { $this->reloadFpm($phpVersion); $this->setHost('deploy_path',
php
{ "resource": "" }
q17432
ConfigFile.store
train
public function store($path = 'config' . DIRECTORY_SEPARATOR . 'deploy.php') { $path = base_path($path); if (! is_dir(dirname($path))) {
php
{ "resource": "" }
q17433
PHPGangsta_GoogleAuthenticator._base32Decode
train
protected function _base32Decode($secret) { if (empty($secret)) { return ''; } $base32chars = $this->_getBase32LookupTable(); $base32charsFlipped = array_flip($base32chars); $paddingCharCount = substr_count($secret, $base32chars[32]); $allowedValues = ar...
php
{ "resource": "" }
q17434
PostgresBuilder.getAllTables
train
public function getAllTables() { return $this->connection->select(
php
{ "resource": "" }
q17435
BuildsQueries.eachById
train
public function eachById(callable $callback, $count = 1000, $column = null, $alias = null) { return $this->chunkById($count, function ($results) use ($callback) { foreach ($results as $key => $value) {
php
{ "resource": "" }
q17436
HasOneOrMany.createMany
train
public function createMany(iterable $records) { $instances = $this->related->newCollection(); foreach ($records as $record) {
php
{ "resource": "" }
q17437
Builder.fromSub
train
public function fromSub($query, $as) { [$query, $bindings] = $this->createSub($query);
php
{ "resource": "" }
q17438
Builder.joinSub
train
public function joinSub($query, $as, $first, $operator = null, $second = null, $type = 'inner', $where = false) { [$query, $bindings] = $this->createSub($query); $expression = '('.$query.') as '.$this->grammar->wrap($as);
php
{ "resource": "" }
q17439
AbstractGenerator.setOptions
train
public function setOptions(array $options) { foreach ($options as $name => $value) {
php
{ "resource": "" }
q17440
AbstractGenerator.getCommand
train
public function getCommand($input, $output, array $options = []) { $options = $this->mergeOptions($options);
php
{ "resource": "" }
q17441
AbstractGenerator.mergeOptions
train
protected function mergeOptions(array $options) { $mergedOptions = $this->options; foreach ($options as $name => $value) { if (!array_key_exists($name, $mergedOptions)) {
php
{ "resource": "" }
q17442
AbstractGenerator.checkOutput
train
protected function checkOutput($output, $command) { // the output file must exist if (!$this->fileExists($output)) { throw new \RuntimeException(sprintf( 'The file \'%s\' was not created (command: %s).', $output, $command )); } ...
php
{ "resource": "" }
q17443
AbstractGenerator.buildCommand
train
protected function buildCommand($binary, $input, $output, array $options = []) { $command = $binary; $escapedBinary = escapeshellarg($binary); if (is_executable($escapedBinary)) { $command = $escapedBinary; } foreach ($options as $key => $option) { if...
php
{ "resource": "" }
q17444
AbstractGenerator.executeCommand
train
protected function executeCommand($command) { if (method_exists(Process::class, 'fromShellCommandline')) { $process = Process::fromShellCommandline($command, null, $this->env); } else { $process = new Process($command, null, $this->env); } if (false !== $this...
php
{ "resource": "" }
q17445
AbstractGenerator.prepareOutput
train
protected function prepareOutput($filename, $overwrite) { $directory = dirname($filename); if ($this->fileExists($filename)) { if (!$this->isFile($filename)) { throw new \InvalidArgumentException(sprintf( 'The output file \'%s\' already exists and it ...
php
{ "resource": "" }
q17446
Pdf.handleOptions
train
protected function handleOptions(array $options = []) { foreach ($options as $option => $value) { if (null === $value) { unset($options[$option]); continue; } if (!empty($value) && array_key_exists($option, $this->optionsWithContentCheck))...
php
{ "resource": "" }
q17447
MountManager.listWith
train
public function listWith(array $keys = [], $directory = '', $recursive = false) { list($prefix, $directory) = $this->getPrefixAndPath($directory);
php
{ "resource": "" }
q17448
MountManager.invokePluginOnFilesystem
train
public function invokePluginOnFilesystem($method, $arguments, $prefix) { $filesystem = $this->getFilesystem($prefix); try { return $this->invokePlugin($method, $arguments, $filesystem);
php
{ "resource": "" }
q17449
Config.get
train
public function get($key, $default = null) { if ( ! array_key_exists($key, $this->settings))
php
{ "resource": "" }
q17450
Config.has
train
public function has($key) { if (array_key_exists($key, $this->settings)) { return true; }
php
{ "resource": "" }
q17451
ContentListingFormatter.residesInDirectory
train
private function residesInDirectory(array $entry) { if ($this->directory === '') { return true; } return $this->caseSensitive
php
{ "resource": "" }
q17452
ContentListingFormatter.isDirectChild
train
private function isDirectChild(array $entry) { return $this->caseSensitive ? $entry['dirname'] === $this->directory
php
{ "resource": "" }
q17453
Util.pathinfo
train
public static function pathinfo($path) { $pathinfo = compact('path'); if ('' !== $dirname = dirname($path)) { $pathinfo['dirname'] = static::normalizeDirname($dirname); }
php
{ "resource": "" }
q17454
Util.map
train
public static function map(array $object, array $map) { $result = []; foreach ($map as $from => $to) { if ( ! isset($object[$from])) { continue;
php
{ "resource": "" }
q17455
Util.ensureConfig
train
public static function ensureConfig($config) { if ($config === null) { return new Config(); } if ($config instanceof Config) { return $config; } if (is_array($config)) {
php
{ "resource": "" }
q17456
Util.basename
train
private static function basename($path) { $separators = DIRECTORY_SEPARATOR === '/' ? '/' : '\/'; $path = rtrim($path, $separators); $basename = preg_replace('#.*?([^' . preg_quote($separators, '#') . ']+$)#', '$1', $path); if (DIRECTORY_SEPARATOR === '/') { return $ba...
php
{ "resource": "" }
q17457
Ftp.setUtf8Mode
train
protected function setUtf8Mode() { if ($this->utf8) { $response = ftp_raw($this->connection, "OPTS UTF8 ON"); if (substr($response[0], 0, 3) !== '200') { throw new RuntimeException(
php
{ "resource": "" }
q17458
Ftp.ftpRawlist
train
protected function ftpRawlist($options, $path) { $connection = $this->getConnection(); if ($this->isPureFtpd) { $path
php
{ "resource": "" }
q17459
ConfigAwareTrait.prepareConfig
train
protected function prepareConfig(array $config) { $config = new Config($config);
php
{ "resource": "" }
q17460
PluggableTrait.findPlugin
train
protected function findPlugin($method) { if ( ! isset($this->plugins[$method])) {
php
{ "resource": "" }
q17461
PluggableTrait.invokePlugin
train
protected function invokePlugin($method, array $arguments, FilesystemInterface $filesystem) { $plugin = $this->findPlugin($method); $plugin->setFilesystem($filesystem); $callback
php
{ "resource": "" }
q17462
StreamedWritingTrait.writeStream
train
public function writeStream($path, $resource, Config $config) {
php
{ "resource": "" }
q17463
JWTManager.addUserIdentityToPayload
train
protected function addUserIdentityToPayload(UserInterface $user, array &$payload) { $accessor
php
{ "resource": "" }
q17464
LoadedJWS.checkExpiration
train
private function checkExpiration() { if (!$this->hasLifetime) { return; } if (!isset($this->payload['exp']) || !is_numeric($this->payload['exp'])) { return $this->state = self::INVALID; } if
php
{ "resource": "" }
q17465
LoadedJWS.checkIssuedAt
train
private function checkIssuedAt() { if (isset($this->payload['iat']) && (int) $this->payload['iat'] - $this->clockSkew > time()) {
php
{ "resource": "" }
q17466
JWTFactory.createEntryPoint
train
protected function createEntryPoint(ContainerBuilder $container, $id, $defaultEntryPoint) { $entryPointId = 'lexik_jwt_authentication.security.authentication.entry_point.'.$id; $container->setDefinition($entryPointId,
php
{ "resource": "" }
q17467
ChainTokenExtractor.removeExtractor
train
public function removeExtractor(\Closure $filter) { $filtered = array_filter($this->map, $filter); if (!$extractorToUnmap = current($filtered)) { return false; } $key
php
{ "resource": "" }
q17468
JWTTokenAuthenticator.getCredentials
train
public function getCredentials(Request $request) { $tokenExtractor = $this->getTokenExtractor(); if (!$tokenExtractor instanceof TokenExtractorInterface) { throw new \RuntimeException(sprintf('Method "%s::getTokenExtractor()" must return an instance of "%s".', __CLASS__, TokenExtractorI...
php
{ "resource": "" }
q17469
JWTTokenAuthenticator.getUser
train
public function getUser($preAuthToken, UserProviderInterface $userProvider) { if (!$preAuthToken instanceof PreAuthenticationJWTUserToken) { throw new \InvalidArgumentException( sprintf('The first argument of the "%s()" method must be an instance of "%s".', __METHOD__, PreAuthent...
php
{ "resource": "" }
q17470
JWTTokenAuthenticator.loadUser
train
protected function loadUser(UserProviderInterface $userProvider, array $payload, $identity) { if ($userProvider instanceof PayloadAwareUserProviderInterface)
php
{ "resource": "" }
q17471
JWTProvider.getUserFromPayload
train
protected function getUserFromPayload(array $payload) { if (!isset($payload[$this->userIdClaim])) {
php
{ "resource": "" }
q17472
MarkdownDifferAndFormatter.removeTrailingWhitespaces
train
private function removeTrailingWhitespaces(string $diff): string {
php
{ "resource": "" }
q17473
Configuration.resolveFromInput
train
public function resolveFromInput(InputInterface $input): void { $this->isDryRun = (bool) $input->getOption(Option::OPTION_DRY_RUN); $this->source = (array) $input->getArgument(Option::SOURCE);
php
{ "resource": "" }
q17474
RectorNodeTraverser.configureEnabledRectorsOnly
train
private function configureEnabledRectorsOnly(): void { $this->visitors = []; $enabledRectors = $this->enabledRectorsProvider->getEnabledRectors(); foreach ($enabledRectors as $enabledRector => $configuration) { foreach ($this->allPhpRectors as $phpRector) { if (!...
php
{ "resource": "" }
q17475
PhpSpecMocksToPHPUnitMocksRector.createCreateMockCall
train
private function createCreateMockCall(Param $param, Name $name): ?Expression { /** @var Class_ $classNode */ $classNode = $param->getAttribute(AttributeKey::CLASS_NODE); $classMocks = $this->phpSpecMockCollector->resolveClassMocksFromParam($classNode); $variable = $this->getName($p...
php
{ "resource": "" }
q17476
PhpDocInfoFactory.setPositionOfLastToken
train
private function setPositionOfLastToken( AttributeAwarePhpDocNode $attributeAwarePhpDocNode ): AttributeAwarePhpDocNode { if ($attributeAwarePhpDocNode->children === []) { return $attributeAwarePhpDocNode; } /** @var AttributeAwareNodeInterface $lastChildNode */
php
{ "resource": "" }
q17477
ShowCommand.resolveConfiguration
train
private function resolveConfiguration(RectorInterface $rector): array { $rectorReflection = new ReflectionClass($rector); $constructorReflection = $rectorReflection->getConstructor(); if ($constructorReflection === null) { return []; } $configuration = []; ...
php
{ "resource": "" }
q17478
ComplexNodeTypeResolver.resolvePropertyTypeInfo
train
public function resolvePropertyTypeInfo(Property $property): ?VarTypeInfo { $types = []; $propertyDefault = $property->props[0]->default; if ($propertyDefault !== null) { $types[] = $this->nodeToStringTypeResolver->resolver($propertyDefault); } $classNode = $pro...
php
{ "resource": "" }
q17479
DocBlockManipulator.getParamTypeInfos
train
public function getParamTypeInfos(Node $node): array { if ($node->getDocComment() === null) { return []; } $phpDocInfo = $this->createPhpDocInfoFromNode($node); $types = $phpDocInfo->getParamTagValues(); if ($types === []) { return []; } ...
php
{ "resource": "" }
q17480
BetterStandardPrinter.pScalar_String
train
protected function pScalar_String(String_ $node): string { $kind = $node->getAttribute('kind', String_::KIND_SINGLE_QUOTED); if ($kind === String_::KIND_DOUBLE_QUOTED && $node->getAttribute('is_regular_pattern')) {
php
{ "resource": "" }
q17481
BetterStandardPrinter.pStmt_Class
train
protected function pStmt_Class(Class_ $class): string { $shouldReindex = false; foreach ($class->stmts as $key => $stmt) { if ($stmt instanceof TraitUse) { // remove empty ones if (count($stmt->traits) === 0) { unset($class->stmts[$key...
php
{ "resource": "" }
q17482
ParseFileRector.refactor
train
public function refactor(Node $node): ?Node { if (! $this->isName($node, 'parse')) { return null; } if (! $this->isType($node->class, 'Symfony\Component\Yaml\Yaml')) {
php
{ "resource": "" }
q17483
AssertCompareToSpecificMethodRector.moveFunctionArgumentsUp
train
private function moveFunctionArgumentsUp(Node $node): void { /** @var FuncCall $secondArgument */
php
{ "resource": "" }
q17484
TemplateAnnotationRector.resolveArgumentsFromMethodCall
train
private function resolveArgumentsFromMethodCall(Return_ $returnNode): array { $arguments = []; if ($returnNode->expr instanceof MethodCall) { foreach ($returnNode->expr->args as $arg) { if ($arg->value
php
{ "resource": "" }
q17485
PhpDocInfoPrinter.printFormatPreserving
train
public function printFormatPreserving(PhpDocInfo $phpDocInfo): string { $this->attributeAwarePhpDocNode = $phpDocInfo->getPhpDocNode(); $this->tokens = $phpDocInfo->getTokens();
php
{ "resource": "" }
q17486
FunctionLikeManipulator.resolveStaticReturnTypeInfo
train
public function resolveStaticReturnTypeInfo(FunctionLike $functionLike): ?ReturnTypeInfo { if ($this->shouldSkip($functionLike)) { return null; } /** @var Return_[] $returnNodes */ $returnNodes = $this->betterNodeFinder->findInstanceOf((array) $functionLike->stmts, Retur...
php
{ "resource": "" }
q17487
PhpSpecClassToPHPUnitClassRector.removeSelfTypeMethod
train
private function removeSelfTypeMethod(Class_ $node): Class_ { foreach ((array) $node->stmts as $key => $stmt) { if (! $stmt instanceof ClassMethod) { continue; } if (count((array) $stmt->stmts) !== 1) { continue; } ...
php
{ "resource": "" }
q17488
SimplifyConditionsRector.shouldSkip
train
private function shouldSkip(BinaryOp $binaryOp): bool { if ($binaryOp instanceof BooleanOr) { return true; } if ($binaryOp->left instanceof BinaryOp) {
php
{ "resource": "" }
q17489
AbstractTypeInfo.isTypehintAble
train
public function isTypehintAble(): bool { if ($this->hasRemovedTypes()) { return false; } $typeCount = count($this->types);
php
{ "resource": "" }
q17490
RenameNamespaceRector.isClassFullyQualifiedName
train
private function isClassFullyQualifiedName(Node $node): bool { $parentNode = $node->getAttribute(AttributeKey::PARENT_NODE); if ($parentNode === null) { return false; } if (! $parentNode instanceof New_) { return false; }
php
{ "resource": "" }
q17491
VisibilityManipulator.removeOriginalVisibilityFromFlags
train
private function removeOriginalVisibilityFromFlags(Node $node): void { $this->ensureIsClassMethodOrProperty($node, __METHOD__); // no modifier if ($node->flags === 0) { return;
php
{ "resource": "" }
q17492
Loggers.getLogger
train
public static function getLogger(string $channel): Logger { if (empty(static::$loggers[$channel])) {
php
{ "resource": "" }
q17493
Translatable.scopeOrderByTranslation
train
public function scopeOrderByTranslation(Builder $query, $key, $sortmethod = 'asc') { $translationTable = $this->getTranslationsTable(); $localeKey = $this->getLocaleKey(); $table = $this->getTable(); $keyName = $this->getKeyName(); return $query ->join($translati...
php
{ "resource": "" }
q17494
Agent.getDetectionRulesExtended
train
public static function getDetectionRulesExtended() { static $rules; if (!$rules) { $rules = static::mergeRules( static::$desktopDevices, // NEW static::$phoneDevices,
php
{ "resource": "" }
q17495
Agent.languages
train
public function languages($acceptLanguage = null) { if ($acceptLanguage === null) { $acceptLanguage = $this->getHttpHeader('HTTP_ACCEPT_LANGUAGE'); } if (!$acceptLanguage) { return []; } $languages = []; // Parse accept language string.
php
{ "resource": "" }
q17496
Agent.findDetectionRulesAgainstUA
train
protected function findDetectionRulesAgainstUA(array $rules, $userAgent = null) { // Loop given rules foreach ($rules as $key => $regex) { if (empty($regex)) {
php
{ "resource": "" }
q17497
Agent.isDesktop
train
public function isDesktop($userAgent = null, $httpHeaders = null) { return
php
{ "resource": "" }
q17498
Agent.isPhone
train
public function isPhone($userAgent = null, $httpHeaders = null) {
php
{ "resource": "" }
q17499
DefaultFormFactory.getFormFields
train
protected function getFormFields(RequestHandler $controller = null, $name, $context = []) { // Fall back to standard "getCMSFields" which itself uses the FormScaffolder as a fallback // @todo Deprecate or formalise support for
php
{ "resource": "" }