_id stringlengths 2 7 | title stringlengths 3 151 | partition stringclasses 3
values | text stringlengths 83 13k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q14100 | MethodAnalyzer.checkStatic | train | public static function checkStatic(
$method_id,
$self_call,
$is_context_dynamic,
Codebase $codebase,
CodeLocation $code_location,
array $suppressed_issues,
&$is_dynamic_this_method = false
) {
$codebase_methods = $codebase->methods;
if ($method_id === 'Closure::fromcallable') {
return true;
}
$original_method_id = $method_id;
$method_id = $codebase_methods->getDeclaringMethodId($method_id);
if (!$method_id) {
throw new \LogicException('Declaring method for ' . $original_method_id . ' should not be null');
}
$storage = $codebase_methods->getStorage($method_id);
if (!$storage->is_static) {
if ($self_call) {
if (!$is_context_dynamic) {
if (IssueBuffer::accepts(
new NonStaticSelfCall(
'Method ' . $codebase_methods->getCasedMethodId($method_id) .
' is not static, but is called ' .
'using self::',
$code_location
),
$suppressed_issues
)) {
return false;
}
} else {
$is_dynamic_this_method = true;
}
} else {
if (IssueBuffer::accepts(
new InvalidStaticInvocation(
'Method ' . $codebase_methods->getCasedMethodId($method_id) .
' is not static, but is called ' .
'statically',
$code_location
),
$suppressed_issues
)) {
return false;
}
}
}
return true;
} | php | {
"resource": ""
} |
q14101 | Algebra.simplifyCNF | train | public static function simplifyCNF(array $clauses)
{
$cloned_clauses = [];
// avoid strict duplicates
foreach ($clauses as $clause) {
$unique_clause = clone $clause;
foreach ($unique_clause->possibilities as $var_id => $possibilities) {
if (count($possibilities)) {
$unique_clause->possibilities[$var_id] = array_unique($possibilities);
}
}
$cloned_clauses[$clause->getHash()] = $unique_clause;
}
// remove impossible types
foreach ($cloned_clauses as $clause_a) {
if (count($clause_a->possibilities) !== 1 || count(array_values($clause_a->possibilities)[0]) !== 1) {
continue;
}
if (!$clause_a->reconcilable || $clause_a->wedge) {
continue;
}
$clause_var = array_keys($clause_a->possibilities)[0];
$only_type = array_pop(array_values($clause_a->possibilities)[0]);
$negated_clause_type = self::negateType($only_type);
foreach ($cloned_clauses as $clause_b) {
if ($clause_a === $clause_b || !$clause_b->reconcilable || $clause_b->wedge) {
continue;
}
if (isset($clause_b->possibilities[$clause_var]) &&
in_array($negated_clause_type, $clause_b->possibilities[$clause_var], true)
) {
$clause_b->possibilities[$clause_var] = array_filter(
$clause_b->possibilities[$clause_var],
/**
* @param string $possible_type
*
* @return bool
*/
function ($possible_type) use ($negated_clause_type) {
return $possible_type !== $negated_clause_type;
}
);
if (count($clause_b->possibilities[$clause_var]) === 0) {
unset($clause_b->possibilities[$clause_var]);
$clause_b->impossibilities = null;
}
}
}
}
$deduped_clauses = [];
// avoid strict duplicates
foreach ($cloned_clauses as $clause) {
$deduped_clauses[$clause->getHash()] = clone $clause;
}
$deduped_clauses = array_filter(
$deduped_clauses,
/**
* @return bool
*/
function (Clause $clause) {
return count($clause->possibilities) || $clause->wedge;
}
);
$simplified_clauses = [];
foreach ($deduped_clauses as $clause_a) {
$is_redundant = false;
foreach ($deduped_clauses as $clause_b) {
if ($clause_a === $clause_b
|| !$clause_b->reconcilable
|| $clause_b->wedge
|| $clause_a->wedge
) {
continue;
}
if ($clause_a->contains($clause_b)) {
$is_redundant = true;
break;
}
}
if (!$is_redundant) {
$simplified_clauses[] = $clause_a;
}
}
return $simplified_clauses;
} | php | {
"resource": ""
} |
q14102 | Algebra.getTruthsFromFormula | train | public static function getTruthsFromFormula(
array $clauses,
array &$cond_referenced_var_ids = []
) {
$truths = [];
if (empty($clauses)) {
return [];
}
foreach ($clauses as $clause) {
if (!$clause->reconcilable) {
continue;
}
foreach ($clause->possibilities as $var => $possible_types) {
// if there's only one possible type, return it
if (count($clause->possibilities) === 1 && count($possible_types) === 1) {
if (isset($truths[$var])) {
$truths[$var][] = [array_pop($possible_types)];
} else {
$truths[$var] = [[array_pop($possible_types)]];
}
} elseif (count($clause->possibilities) === 1) {
// if there's only one active clause, return all the non-negation clause members ORed together
$things_that_can_be_said = array_filter(
$possible_types,
/**
* @param string $possible_type
*
* @return bool
*
* @psalm-suppress MixedOperand
*/
function ($possible_type) {
return $possible_type[0] !== '!';
}
);
if ($things_that_can_be_said && count($things_that_can_be_said) === count($possible_types)) {
$things_that_can_be_said = array_unique($things_that_can_be_said);
if ($clause->generated && count($possible_types) > 1) {
unset($cond_referenced_var_ids[$var]);
}
/** @var array<int, string> $things_that_can_be_said */
$truths[$var] = [$things_that_can_be_said];
}
}
}
}
return $truths;
} | php | {
"resource": ""
} |
q14103 | TextDocument.publishDiagnostics | train | public function publishDiagnostics(string $uri, array $diagnostics): Promise
{
return $this->handler->notify('textDocument/publishDiagnostics', [
'uri' => $uri,
'diagnostics' => $diagnostics
]);
} | php | {
"resource": ""
} |
q14104 | TextDocument.xcontent | train | public function xcontent(TextDocumentIdentifier $textDocument): Promise
{
return call(
/**
* @return \Generator<int, mixed, mixed, TextDocumentItem>
*/
function () use ($textDocument) {
$result = yield $this->handler->request(
'textDocument/xcontent',
['textDocument' => $textDocument]
);
/** @var TextDocumentItem */
return $this->mapper->map($result, new TextDocumentItem);
}
);
} | php | {
"resource": ""
} |
q14105 | StatementsAnalyzer.getFirstAppearance | train | public function getFirstAppearance($var_id)
{
return isset($this->all_vars[$var_id]) ? $this->all_vars[$var_id] : null;
} | php | {
"resource": ""
} |
q14106 | Properties.propertyExists | train | public function propertyExists(
string $property_id,
bool $read_mode,
StatementsSource $source = null,
Context $context = null,
CodeLocation $code_location = null
) {
// remove trailing backslash if it exists
$property_id = preg_replace('/^\\\\/', '', $property_id);
list($fq_class_name, $property_name) = explode('::$', $property_id);
if ($this->property_existence_provider->has($fq_class_name)) {
$property_exists = $this->property_existence_provider->doesPropertyExist(
$fq_class_name,
$property_name,
$read_mode,
$source,
$context,
$code_location
);
if ($property_exists !== null) {
return $property_exists;
}
}
$class_storage = $this->classlike_storage_provider->get($fq_class_name);
if (isset($class_storage->declaring_property_ids[$property_name])) {
$declaring_property_class = $class_storage->declaring_property_ids[$property_name];
if ($context && $context->calling_method_id) {
$this->file_reference_provider->addMethodReferenceToClassMember(
$context->calling_method_id,
strtolower($declaring_property_class) . '::$' . $property_name
);
} elseif ($source) {
$this->file_reference_provider->addFileReferenceToClassMember(
$source->getFilePath(),
strtolower($declaring_property_class) . '::$' . $property_name
);
}
if ($this->collect_locations && $code_location) {
$this->file_reference_provider->addCallingLocationForClassProperty(
$code_location,
strtolower($declaring_property_class) . '::$' . $property_name
);
}
return true;
}
if ($context && $context->calling_method_id) {
$this->file_reference_provider->addMethodReferenceToMissingClassMember(
$context->calling_method_id,
strtolower($fq_class_name) . '::$' . $property_name
);
} elseif ($source) {
$this->file_reference_provider->addFileReferenceToMissingClassMember(
$source->getFilePath(),
strtolower($fq_class_name) . '::$' . $property_name
);
}
return false;
} | php | {
"resource": ""
} |
q14107 | Context.update | train | public function update(
Context $start_context,
Context $end_context,
$has_leaving_statements,
array $vars_to_update,
array &$updated_vars
) {
foreach ($start_context->vars_in_scope as $var_id => $old_type) {
// this is only true if there was some sort of type negation
if (in_array($var_id, $vars_to_update, true)) {
// if we're leaving, we're effectively deleting the possibility of the if types
$new_type = !$has_leaving_statements && $end_context->hasVariable($var_id)
? $end_context->vars_in_scope[$var_id]
: null;
$existing_type = isset($this->vars_in_scope[$var_id]) ? $this->vars_in_scope[$var_id] : null;
if (!$existing_type) {
if ($new_type) {
$this->vars_in_scope[$var_id] = clone $new_type;
$updated_vars[$var_id] = true;
}
continue;
}
// if the type changed within the block of statements, process the replacement
// also never allow ourselves to remove all types from a union
if ((!$new_type || !$old_type->equals($new_type))
&& ($new_type || count($existing_type->getTypes()) > 1)
) {
$existing_type->substitute($old_type, $new_type);
if ($new_type && $new_type->from_docblock) {
$existing_type->setFromDocblock();
}
$updated_vars[$var_id] = true;
}
}
}
} | php | {
"resource": ""
} |
q14108 | Config.getConfigForPath | train | public static function getConfigForPath($path, $base_dir, $output_format)
{
$config_path = self::locateConfigFile($path);
if (!$config_path) {
if ($output_format === ProjectAnalyzer::TYPE_CONSOLE) {
exit(
'Could not locate a config XML file in path ' . $path . '. Have you run \'psalm --init\' ?' .
PHP_EOL
);
}
throw new ConfigException('Config not found for path ' . $path);
}
return self::loadFromXMLFile($config_path, $base_dir);
} | php | {
"resource": ""
} |
q14109 | Config.locateConfigFile | train | public static function locateConfigFile(string $path)
{
$dir_path = realpath($path);
if ($dir_path === false) {
throw new ConfigException('Config not found for path ' . $path);
}
if (!is_dir($dir_path)) {
$dir_path = dirname($dir_path);
}
do {
$maybe_path = $dir_path . DIRECTORY_SEPARATOR . Config::DEFAULT_FILE_NAME;
if (file_exists($maybe_path) || file_exists($maybe_path .= '.dist')) {
return $maybe_path;
}
$dir_path = dirname($dir_path);
} while (dirname($dir_path) !== $dir_path);
return null;
} | php | {
"resource": ""
} |
q14110 | Config.loadFromXMLFile | train | public static function loadFromXMLFile($file_path, $base_dir)
{
$file_contents = file_get_contents($file_path);
if ($file_contents === false) {
throw new \InvalidArgumentException('Cannot open ' . $file_path);
}
try {
$config = self::loadFromXML($base_dir, $file_contents);
$config->hash = sha1($file_contents);
} catch (ConfigException $e) {
throw new ConfigException(
'Problem parsing ' . $file_path . ":\n" . ' ' . $e->getMessage()
);
}
return $config;
} | php | {
"resource": ""
} |
q14111 | FileDiffer.coalesceReplacements | train | private static function coalesceReplacements(array $diff)
{
$newDiff = [];
$c = \count($diff);
for ($i = 0; $i < $c; $i++) {
$diffType = $diff[$i]->type;
if ($diffType !== DiffElem::TYPE_REMOVE) {
$newDiff[] = $diff[$i];
continue;
}
$j = $i;
while ($j < $c && $diff[$j]->type === DiffElem::TYPE_REMOVE) {
$j++;
}
$k = $j;
while ($k < $c && $diff[$k]->type === DiffElem::TYPE_ADD) {
$k++;
}
if ($j - $i === $k - $j) {
$len = $j - $i;
for ($n = 0; $n < $len; $n++) {
$newDiff[] = new DiffElem(
DiffElem::TYPE_REPLACE,
$diff[$i + $n]->old,
$diff[$j + $n]->new
);
}
} else {
for (; $i < $k; $i++) {
$newDiff[] = $diff[$i];
}
}
/** @psalm-suppress LoopInvalidation */
$i = $k - 1;
}
return $newDiff;
} | php | {
"resource": ""
} |
q14112 | Codebase.scanFiles | train | public function scanFiles(int $threads = 1)
{
$has_changes = $this->scanner->scanFiles($this->classlikes, $threads);
if ($has_changes) {
$this->populator->populateCodebase($this);
}
} | php | {
"resource": ""
} |
q14113 | Codebase.isTypeContainedByType | train | public function isTypeContainedByType(
Type\Union $input_type,
Type\Union $container_type
): bool {
return TypeAnalyzer::isContainedBy($this, $input_type, $container_type);
} | php | {
"resource": ""
} |
q14114 | Codebase.canTypeBeContainedByType | train | public function canTypeBeContainedByType(
Type\Union $input_type,
Type\Union $container_type
): bool {
return TypeAnalyzer::canBeContainedBy($this, $input_type, $container_type);
} | php | {
"resource": ""
} |
q14115 | FunctionDocblockManipulator.setReturnType | train | public function setReturnType($php_type, $new_type, $phpdoc_type, $is_php_compatible, $description)
{
$new_type = str_replace(['<mixed, mixed>', '<array-key, mixed>', '<empty, empty>'], '', $new_type);
$this->new_php_return_type = $php_type;
$this->new_phpdoc_return_type = $phpdoc_type;
$this->new_psalm_return_type = $new_type;
$this->return_type_is_php_compatible = $is_php_compatible;
$this->return_type_description = $description;
} | php | {
"resource": ""
} |
q14116 | FunctionDocblockManipulator.setParamType | train | public function setParamType($param_name, $php_type, $new_type, $phpdoc_type, $is_php_compatible)
{
$new_type = str_replace(['<mixed, mixed>', '<array-key, mixed>', '<empty, empty>'], '', $new_type);
if ($php_type) {
$this->new_php_param_types[$param_name] = $php_type;
}
$this->new_phpdoc_param_types[$param_name] = $phpdoc_type;
$this->new_psalm_param_types[$param_name] = $new_type;
$this->param_type_is_php_compatible[$param_name] = $is_php_compatible;
} | php | {
"resource": ""
} |
q14117 | LanguageServer.pathToUri | train | public static function pathToUri(string $filepath): string
{
$filepath = trim(str_replace('\\', '/', $filepath), '/');
$parts = explode('/', $filepath);
// Don't %-encode the colon after a Windows drive letter
$first = array_shift($parts);
if (substr($first, -1) !== ':') {
$first = rawurlencode($first);
}
$parts = array_map('rawurlencode', $parts);
array_unshift($parts, $first);
$filepath = implode('/', $parts);
return 'file:///' . $filepath;
} | php | {
"resource": ""
} |
q14118 | LanguageServer.uriToPath | train | public static function uriToPath(string $uri)
{
$fragments = parse_url($uri);
if ($fragments === false || !isset($fragments['scheme']) || $fragments['scheme'] !== 'file') {
throw new \InvalidArgumentException("Not a valid file URI: $uri");
}
$filepath = urldecode((string) $fragments['path']);
if (strpos($filepath, ':') !== false) {
if ($filepath[0] === '/') {
$filepath = substr($filepath, 1);
}
$filepath = str_replace('/', '\\', $filepath);
}
return $filepath;
} | php | {
"resource": ""
} |
q14119 | FunctionLikeAnalyzer.addReturnTypes | train | public function addReturnTypes(Context $context)
{
if ($this->return_vars_in_scope !== null) {
$this->return_vars_in_scope = TypeAnalyzer::combineKeyedTypes(
$context->vars_in_scope,
$this->return_vars_in_scope
);
} else {
$this->return_vars_in_scope = $context->vars_in_scope;
}
if ($this->return_vars_possibly_in_scope !== null) {
$this->return_vars_possibly_in_scope = array_merge(
$context->vars_possibly_in_scope,
$this->return_vars_possibly_in_scope
);
} else {
$this->return_vars_possibly_in_scope = $context->vars_possibly_in_scope;
}
} | php | {
"resource": ""
} |
q14120 | ClientHandler.notify | train | public function notify(string $method, $params): Promise
{
return $this->protocolWriter->write(
new Message(
new AdvancedJsonRpc\Notification($method, (object)$params)
)
);
} | php | {
"resource": ""
} |
q14121 | WebDriverActions.moveByOffset | train | public function moveByOffset($x_offset, $y_offset)
{
$this->action->addAction(
new WebDriverMoveToOffsetAction($this->mouse, null, $x_offset, $y_offset)
);
return $this;
} | php | {
"resource": ""
} |
q14122 | Cookie.setDomain | train | public function setDomain($domain)
{
if (mb_strpos($domain, ':') !== false) {
throw new InvalidArgumentException(sprintf('Cookie domain "%s" should not contain a port', $domain));
}
$this->cookie['domain'] = $domain;
} | php | {
"resource": ""
} |
q14123 | RemoteKeyboard.sendKeys | train | public function sendKeys($keys)
{
$this->executor->execute(DriverCommand::SEND_KEYS_TO_ACTIVE_ELEMENT, [
'value' => WebDriverKeys::encode($keys),
]);
return $this;
} | php | {
"resource": ""
} |
q14124 | RemoteKeyboard.pressKey | train | public function pressKey($key)
{
$this->executor->execute(DriverCommand::SEND_KEYS_TO_ACTIVE_ELEMENT, [
'value' => [(string) $key],
]);
return $this;
} | php | {
"resource": ""
} |
q14125 | RemoteKeyboard.releaseKey | train | public function releaseKey($key)
{
$this->executor->execute(DriverCommand::SEND_KEYS_TO_ACTIVE_ELEMENT, [
'value' => [(string) $key],
]);
return $this;
} | php | {
"resource": ""
} |
q14126 | WebDriverExpectedCondition.titleContains | train | public static function titleContains($title)
{
return new static(
function (WebDriver $driver) use ($title) {
return mb_strpos($driver->getTitle(), $title) !== false;
}
);
} | php | {
"resource": ""
} |
q14127 | WebDriverExpectedCondition.titleMatches | train | public static function titleMatches($titleRegexp)
{
return new static(
function (WebDriver $driver) use ($titleRegexp) {
return (bool) preg_match($titleRegexp, $driver->getTitle());
}
);
} | php | {
"resource": ""
} |
q14128 | WebDriverExpectedCondition.urlContains | train | public static function urlContains($url)
{
return new static(
function (WebDriver $driver) use ($url) {
return mb_strpos($driver->getCurrentURL(), $url) !== false;
}
);
} | php | {
"resource": ""
} |
q14129 | WebDriverExpectedCondition.urlMatches | train | public static function urlMatches($urlRegexp)
{
return new static(
function (WebDriver $driver) use ($urlRegexp) {
return (bool) preg_match($urlRegexp, $driver->getCurrentURL());
}
);
} | php | {
"resource": ""
} |
q14130 | WebDriverExpectedCondition.presenceOfAllElementsLocatedBy | train | public static function presenceOfAllElementsLocatedBy(WebDriverBy $by)
{
return new static(
function (WebDriver $driver) use ($by) {
$elements = $driver->findElements($by);
return count($elements) > 0 ? $elements : null;
}
);
} | php | {
"resource": ""
} |
q14131 | WebDriverExpectedCondition.visibilityOfElementLocated | train | public static function visibilityOfElementLocated(WebDriverBy $by)
{
return new static(
function (WebDriver $driver) use ($by) {
try {
$element = $driver->findElement($by);
return $element->isDisplayed() ? $element : null;
} catch (StaleElementReferenceException $e) {
return null;
}
}
);
} | php | {
"resource": ""
} |
q14132 | WebDriverExpectedCondition.visibilityOfAnyElementLocated | train | public static function visibilityOfAnyElementLocated(WebDriverBy $by)
{
return new static(
function (WebDriver $driver) use ($by) {
$elements = $driver->findElements($by);
$visibleElements = [];
foreach ($elements as $element) {
try {
if ($element->isDisplayed()) {
$visibleElements[] = $element;
}
} catch (StaleElementReferenceException $e) {
}
}
return count($visibleElements) > 0 ? $visibleElements : null;
}
);
} | php | {
"resource": ""
} |
q14133 | WebDriverExpectedCondition.elementTextMatches | train | public static function elementTextMatches(WebDriverBy $by, $regexp)
{
return new static(
function (WebDriver $driver) use ($by, $regexp) {
try {
return (bool) preg_match($regexp, $driver->findElement($by)->getText());
} catch (StaleElementReferenceException $e) {
return null;
}
}
);
} | php | {
"resource": ""
} |
q14134 | WebDriverExpectedCondition.elementValueContains | train | public static function elementValueContains(WebDriverBy $by, $text)
{
return new static(
function (WebDriver $driver) use ($by, $text) {
try {
$element_text = $driver->findElement($by)->getAttribute('value');
return mb_strpos($element_text, $text) !== false;
} catch (StaleElementReferenceException $e) {
return null;
}
}
);
} | php | {
"resource": ""
} |
q14135 | WebDriverExpectedCondition.frameToBeAvailableAndSwitchToIt | train | public static function frameToBeAvailableAndSwitchToIt($frame_locator)
{
return new static(
function (WebDriver $driver) use ($frame_locator) {
try {
return $driver->switchTo()->frame($frame_locator);
} catch (NoSuchFrameException $e) {
return false;
}
}
);
} | php | {
"resource": ""
} |
q14136 | WebDriverExpectedCondition.invisibilityOfElementLocated | train | public static function invisibilityOfElementLocated(WebDriverBy $by)
{
return new static(
function (WebDriver $driver) use ($by) {
try {
return !$driver->findElement($by)->isDisplayed();
} catch (NoSuchElementException $e) {
return true;
} catch (StaleElementReferenceException $e) {
return true;
}
}
);
} | php | {
"resource": ""
} |
q14137 | WebDriverExpectedCondition.invisibilityOfElementWithText | train | public static function invisibilityOfElementWithText(WebDriverBy $by, $text)
{
return new static(
function (WebDriver $driver) use ($by, $text) {
try {
return !($driver->findElement($by)->getText() === $text);
} catch (NoSuchElementException $e) {
return true;
} catch (StaleElementReferenceException $e) {
return true;
}
}
);
} | php | {
"resource": ""
} |
q14138 | WebDriverExpectedCondition.elementToBeClickable | train | public static function elementToBeClickable(WebDriverBy $by)
{
$visibility_of_element_located =
self::visibilityOfElementLocated($by);
return new static(
function (WebDriver $driver) use ($visibility_of_element_located) {
$element = call_user_func(
$visibility_of_element_located->getApply(),
$driver
);
try {
if ($element !== null && $element->isEnabled()) {
return $element;
}
return null;
} catch (StaleElementReferenceException $e) {
return null;
}
}
);
} | php | {
"resource": ""
} |
q14139 | WebDriverExpectedCondition.stalenessOf | train | public static function stalenessOf(WebDriverElement $element)
{
return new static(
function () use ($element) {
try {
$element->isEnabled();
return false;
} catch (StaleElementReferenceException $e) {
return true;
}
}
);
} | php | {
"resource": ""
} |
q14140 | WebDriverExpectedCondition.refreshed | train | public static function refreshed(self $condition)
{
return new static(
function (WebDriver $driver) use ($condition) {
try {
return call_user_func($condition->getApply(), $driver);
} catch (StaleElementReferenceException $e) {
return null;
}
}
);
} | php | {
"resource": ""
} |
q14141 | WebDriverExpectedCondition.elementSelectionStateToBe | train | public static function elementSelectionStateToBe($element_or_by, $selected)
{
if ($element_or_by instanceof WebDriverElement) {
return new static(
function () use ($element_or_by, $selected) {
return $element_or_by->isSelected() === $selected;
}
);
} else {
if ($element_or_by instanceof WebDriverBy) {
return new static(
function (WebDriver $driver) use ($element_or_by, $selected) {
try {
$element = $driver->findElement($element_or_by);
return $element->isSelected() === $selected;
} catch (StaleElementReferenceException $e) {
return null;
}
}
);
}
}
} | php | {
"resource": ""
} |
q14142 | WebDriverExpectedCondition.not | train | public static function not(self $condition)
{
return new static(
function (WebDriver $driver) use ($condition) {
$result = call_user_func($condition->getApply(), $driver);
return !$result;
}
);
} | php | {
"resource": ""
} |
q14143 | AbstractWebDriverCheckboxOrRadio.byIndex | train | protected function byIndex($index, $select = true)
{
$elements = $this->getRelatedElements();
if (!isset($elements[$index])) {
throw new NoSuchElementException(sprintf('Cannot locate %s with index: %d', $this->type, $index));
}
$select ? $this->selectOption($elements[$index]) : $this->deselectOption($elements[$index]);
} | php | {
"resource": ""
} |
q14144 | RemoteTargetLocator.defaultContent | train | public function defaultContent()
{
$params = ['id' => null];
$this->executor->execute(DriverCommand::SWITCH_TO_FRAME, $params);
return $this->driver;
} | php | {
"resource": ""
} |
q14145 | RemoteTargetLocator.frame | train | public function frame($frame)
{
if ($frame instanceof WebDriverElement) {
$id = ['ELEMENT' => $frame->getID()];
} else {
$id = (string) $frame;
}
$params = ['id' => $id];
$this->executor->execute(DriverCommand::SWITCH_TO_FRAME, $params);
return $this->driver;
} | php | {
"resource": ""
} |
q14146 | RemoteTargetLocator.window | train | public function window($handle)
{
$params = ['name' => (string) $handle];
$this->executor->execute(DriverCommand::SWITCH_TO_WINDOW, $params);
return $this->driver;
} | php | {
"resource": ""
} |
q14147 | RemoteTargetLocator.activeElement | train | public function activeElement()
{
$response = $this->driver->execute(DriverCommand::GET_ACTIVE_ELEMENT, []);
$method = new RemoteExecuteMethod($this->driver);
return new RemoteWebElement($method, $response['ELEMENT']);
} | php | {
"resource": ""
} |
q14148 | RemoteWebElement.findElement | train | public function findElement(WebDriverBy $by)
{
$params = [
'using' => $by->getMechanism(),
'value' => $by->getValue(),
':id' => $this->id,
];
$raw_element = $this->executor->execute(
DriverCommand::FIND_CHILD_ELEMENT,
$params
);
return $this->newElement($raw_element['ELEMENT']);
} | php | {
"resource": ""
} |
q14149 | RemoteWebElement.findElements | train | public function findElements(WebDriverBy $by)
{
$params = [
'using' => $by->getMechanism(),
'value' => $by->getValue(),
':id' => $this->id,
];
$raw_elements = $this->executor->execute(
DriverCommand::FIND_CHILD_ELEMENTS,
$params
);
$elements = [];
foreach ($raw_elements as $raw_element) {
$elements[] = $this->newElement($raw_element['ELEMENT']);
}
return $elements;
} | php | {
"resource": ""
} |
q14150 | RemoteWebElement.getAttribute | train | public function getAttribute($attribute_name)
{
$params = [
':name' => $attribute_name,
':id' => $this->id,
];
return $this->executor->execute(
DriverCommand::GET_ELEMENT_ATTRIBUTE,
$params
);
} | php | {
"resource": ""
} |
q14151 | RemoteWebElement.getCSSValue | train | public function getCSSValue($css_property_name)
{
$params = [
':propertyName' => $css_property_name,
':id' => $this->id,
];
return $this->executor->execute(
DriverCommand::GET_ELEMENT_VALUE_OF_CSS_PROPERTY,
$params
);
} | php | {
"resource": ""
} |
q14152 | RemoteWebElement.getLocation | train | public function getLocation()
{
$location = $this->executor->execute(
DriverCommand::GET_ELEMENT_LOCATION,
[':id' => $this->id]
);
return new WebDriverPoint($location['x'], $location['y']);
} | php | {
"resource": ""
} |
q14153 | RemoteWebElement.getLocationOnScreenOnceScrolledIntoView | train | public function getLocationOnScreenOnceScrolledIntoView()
{
$location = $this->executor->execute(
DriverCommand::GET_ELEMENT_LOCATION_ONCE_SCROLLED_INTO_VIEW,
[':id' => $this->id]
);
return new WebDriverPoint($location['x'], $location['y']);
} | php | {
"resource": ""
} |
q14154 | RemoteWebElement.getSize | train | public function getSize()
{
$size = $this->executor->execute(
DriverCommand::GET_ELEMENT_SIZE,
[':id' => $this->id]
);
return new WebDriverDimension($size['width'], $size['height']);
} | php | {
"resource": ""
} |
q14155 | RemoteWebElement.sendKeys | train | public function sendKeys($value)
{
$local_file = $this->fileDetector->getLocalFile($value);
if ($local_file === null) {
$params = [
'value' => WebDriverKeys::encode($value),
':id' => $this->id,
];
$this->executor->execute(DriverCommand::SEND_KEYS_TO_ELEMENT, $params);
} else {
$remote_path = $this->upload($local_file);
$params = [
'value' => WebDriverKeys::encode($remote_path),
':id' => $this->id,
];
$this->executor->execute(DriverCommand::SEND_KEYS_TO_ELEMENT, $params);
}
return $this;
} | php | {
"resource": ""
} |
q14156 | RemoteWebElement.upload | train | protected function upload($local_file)
{
if (!is_file($local_file)) {
throw new WebDriverException('You may only upload files: ' . $local_file);
}
// Create a temporary file in the system temp directory.
$temp_zip = tempnam(sys_get_temp_dir(), 'WebDriverZip');
$zip = new ZipArchive();
if ($zip->open($temp_zip, ZipArchive::CREATE) !== true) {
return false;
}
$info = pathinfo($local_file);
$file_name = $info['basename'];
$zip->addFile($local_file, $file_name);
$zip->close();
$params = [
'file' => base64_encode(file_get_contents($temp_zip)),
];
$remote_path = $this->executor->execute(
DriverCommand::UPLOAD_FILE,
$params
);
unlink($temp_zip);
return $remote_path;
} | php | {
"resource": ""
} |
q14157 | WebDriverWindow.getPosition | train | public function getPosition()
{
$position = $this->executor->execute(
DriverCommand::GET_WINDOW_POSITION,
[':windowHandle' => 'current']
);
return new WebDriverPoint(
$position['x'],
$position['y']
);
} | php | {
"resource": ""
} |
q14158 | WebDriverWindow.getSize | train | public function getSize()
{
$size = $this->executor->execute(
DriverCommand::GET_WINDOW_SIZE,
[':windowHandle' => 'current']
);
return new WebDriverDimension(
$size['width'],
$size['height']
);
} | php | {
"resource": ""
} |
q14159 | WebDriverWindow.setSize | train | public function setSize(WebDriverDimension $size)
{
$params = [
'width' => $size->getWidth(),
'height' => $size->getHeight(),
':windowHandle' => 'current',
];
$this->executor->execute(DriverCommand::SET_WINDOW_SIZE, $params);
return $this;
} | php | {
"resource": ""
} |
q14160 | WebDriverWindow.setPosition | train | public function setPosition(WebDriverPoint $position)
{
$params = [
'x' => $position->getX(),
'y' => $position->getY(),
':windowHandle' => 'current',
];
$this->executor->execute(DriverCommand::SET_WINDOW_POSITION, $params);
return $this;
} | php | {
"resource": ""
} |
q14161 | WebDriverWindow.setScreenOrientation | train | public function setScreenOrientation($orientation)
{
$orientation = mb_strtoupper($orientation);
if (!in_array($orientation, ['PORTRAIT', 'LANDSCAPE'])) {
throw new IndexOutOfBoundsException(
'Orientation must be either PORTRAIT, or LANDSCAPE'
);
}
$this->executor->execute(
DriverCommand::SET_SCREEN_ORIENTATION,
['orientation' => $orientation]
);
return $this;
} | php | {
"resource": ""
} |
q14162 | DesiredCapabilities.setJavascriptEnabled | train | public function setJavascriptEnabled($enabled)
{
$browser = $this->getBrowserName();
if ($browser && $browser !== WebDriverBrowserType::HTMLUNIT) {
throw new Exception(
'isJavascriptEnabled() is a htmlunit-only option. ' .
'See https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities#read-write-capabilities.'
);
}
$this->set(WebDriverCapabilityType::JAVASCRIPT_ENABLED, $enabled);
return $this;
} | php | {
"resource": ""
} |
q14163 | RemoteWebDriver.create | train | public static function create(
$selenium_server_url = 'http://localhost:4444/wd/hub',
$desired_capabilities = null,
$connection_timeout_in_ms = null,
$request_timeout_in_ms = null,
$http_proxy = null,
$http_proxy_port = null,
DesiredCapabilities $required_capabilities = null
) {
$selenium_server_url = preg_replace('#/+$#', '', $selenium_server_url);
$desired_capabilities = self::castToDesiredCapabilitiesObject($desired_capabilities);
$executor = new HttpCommandExecutor($selenium_server_url, $http_proxy, $http_proxy_port);
if ($connection_timeout_in_ms !== null) {
$executor->setConnectionTimeout($connection_timeout_in_ms);
}
if ($request_timeout_in_ms !== null) {
$executor->setRequestTimeout($request_timeout_in_ms);
}
if ($required_capabilities !== null) {
// TODO: Selenium (as of v3.0.1) does accept requiredCapabilities only as a property of desiredCapabilities.
// This will probably change in future with the W3C WebDriver spec, but is the only way how to pass these
// values now.
$desired_capabilities->setCapability('requiredCapabilities', $required_capabilities->toArray());
}
$command = new WebDriverCommand(
null,
DriverCommand::NEW_SESSION,
['desiredCapabilities' => $desired_capabilities->toArray()]
);
$response = $executor->execute($command);
$returnedCapabilities = new DesiredCapabilities($response->getValue());
$driver = new static($executor, $response->getSessionID(), $returnedCapabilities);
return $driver;
} | php | {
"resource": ""
} |
q14164 | RemoteWebDriver.findElement | train | public function findElement(WebDriverBy $by)
{
$params = ['using' => $by->getMechanism(), 'value' => $by->getValue()];
$raw_element = $this->execute(
DriverCommand::FIND_ELEMENT,
$params
);
return $this->newElement($raw_element['ELEMENT']);
} | php | {
"resource": ""
} |
q14165 | RemoteWebDriver.findElements | train | public function findElements(WebDriverBy $by)
{
$params = ['using' => $by->getMechanism(), 'value' => $by->getValue()];
$raw_elements = $this->execute(
DriverCommand::FIND_ELEMENTS,
$params
);
$elements = [];
foreach ($raw_elements as $raw_element) {
$elements[] = $this->newElement($raw_element['ELEMENT']);
}
return $elements;
} | php | {
"resource": ""
} |
q14166 | RemoteWebDriver.get | train | public function get($url)
{
$params = ['url' => (string) $url];
$this->execute(DriverCommand::GET, $params);
return $this;
} | php | {
"resource": ""
} |
q14167 | RemoteWebDriver.executeScript | train | public function executeScript($script, array $arguments = [])
{
$params = [
'script' => $script,
'args' => $this->prepareScriptArguments($arguments),
];
return $this->execute(DriverCommand::EXECUTE_SCRIPT, $params);
} | php | {
"resource": ""
} |
q14168 | RemoteWebDriver.executeAsyncScript | train | public function executeAsyncScript($script, array $arguments = [])
{
$params = [
'script' => $script,
'args' => $this->prepareScriptArguments($arguments),
];
return $this->execute(
DriverCommand::EXECUTE_ASYNC_SCRIPT,
$params
);
} | php | {
"resource": ""
} |
q14169 | RemoteWebDriver.takeScreenshot | train | public function takeScreenshot($save_as = null)
{
$screenshot = base64_decode(
$this->execute(DriverCommand::SCREENSHOT)
);
if ($save_as) {
file_put_contents($save_as, $screenshot);
}
return $screenshot;
} | php | {
"resource": ""
} |
q14170 | RemoteWebDriver.getAllSessions | train | public static function getAllSessions($selenium_server_url = 'http://localhost:4444/wd/hub', $timeout_in_ms = 30000)
{
$executor = new HttpCommandExecutor($selenium_server_url);
$executor->setConnectionTimeout($timeout_in_ms);
$command = new WebDriverCommand(
null,
DriverCommand::GET_ALL_SESSIONS,
[]
);
return $executor->execute($command)->getValue();
} | php | {
"resource": ""
} |
q14171 | RemoteWebDriver.prepareScriptArguments | train | protected function prepareScriptArguments(array $arguments)
{
$args = [];
foreach ($arguments as $key => $value) {
if ($value instanceof WebDriverElement) {
$args[$key] = ['ELEMENT' => $value->getID()];
} else {
if (is_array($value)) {
$value = $this->prepareScriptArguments($value);
}
$args[$key] = $value;
}
}
return $args;
} | php | {
"resource": ""
} |
q14172 | WebDriverPoint.move | train | public function move($new_x, $new_y)
{
$this->x = $new_x;
$this->y = $new_y;
return $this;
} | php | {
"resource": ""
} |
q14173 | WebDriverPoint.moveBy | train | public function moveBy($x_offset, $y_offset)
{
$this->x += $x_offset;
$this->y += $y_offset;
return $this;
} | php | {
"resource": ""
} |
q14174 | WebDriverPoint.equals | train | public function equals(self $point)
{
return $this->x === $point->getX() &&
$this->y === $point->getY();
} | php | {
"resource": ""
} |
q14175 | WebDriverDimension.equals | train | public function equals(self $dimension)
{
return $this->height === $dimension->getHeight() && $this->width === $dimension->getWidth();
} | php | {
"resource": ""
} |
q14176 | WebDriverOptions.addCookie | train | public function addCookie($cookie)
{
if (is_array($cookie)) {
$cookie = Cookie::createFromArray($cookie);
}
if (!$cookie instanceof Cookie) {
throw new InvalidArgumentException('Cookie must be set from instance of Cookie class or from array.');
}
$this->executor->execute(
DriverCommand::ADD_COOKIE,
['cookie' => $cookie->toArray()]
);
return $this;
} | php | {
"resource": ""
} |
q14177 | WebDriverOptions.getCookieNamed | train | public function getCookieNamed($name)
{
$cookies = $this->getCookies();
foreach ($cookies as $cookie) {
if ($cookie['name'] === $name) {
return $cookie;
}
}
return null;
} | php | {
"resource": ""
} |
q14178 | WebDriverOptions.getCookies | train | public function getCookies()
{
$cookieArrays = $this->executor->execute(DriverCommand::GET_ALL_COOKIES);
$cookies = [];
foreach ($cookieArrays as $cookieArray) {
$cookies[] = Cookie::createFromArray($cookieArray);
}
return $cookies;
} | php | {
"resource": ""
} |
q14179 | WebDriverException.throwException | train | public static function throwException($status_code, $message, $results)
{
switch ($status_code) {
case 1:
throw new IndexOutOfBoundsException($message, $results);
case 2:
throw new NoCollectionException($message, $results);
case 3:
throw new NoStringException($message, $results);
case 4:
throw new NoStringLengthException($message, $results);
case 5:
throw new NoStringWrapperException($message, $results);
case 6:
throw new NoSuchDriverException($message, $results);
case 7:
throw new NoSuchElementException($message, $results);
case 8:
throw new NoSuchFrameException($message, $results);
case 9:
throw new UnknownCommandException($message, $results);
case 10:
throw new StaleElementReferenceException($message, $results);
case 11:
throw new ElementNotVisibleException($message, $results);
case 12:
throw new InvalidElementStateException($message, $results);
case 13:
throw new UnknownServerException($message, $results);
case 14:
throw new ExpectedException($message, $results);
case 15:
throw new ElementNotSelectableException($message, $results);
case 16:
throw new NoSuchDocumentException($message, $results);
case 17:
throw new UnexpectedJavascriptException($message, $results);
case 18:
throw new NoScriptResultException($message, $results);
case 19:
throw new XPathLookupException($message, $results);
case 20:
throw new NoSuchCollectionException($message, $results);
case 21:
throw new TimeOutException($message, $results);
case 22:
throw new NullPointerException($message, $results);
case 23:
throw new NoSuchWindowException($message, $results);
case 24:
throw new InvalidCookieDomainException($message, $results);
case 25:
throw new UnableToSetCookieException($message, $results);
case 26:
throw new UnexpectedAlertOpenException($message, $results);
case 27:
throw new NoAlertOpenException($message, $results);
case 28:
throw new ScriptTimeoutException($message, $results);
case 29:
throw new InvalidCoordinatesException($message, $results);
case 30:
throw new IMENotAvailableException($message, $results);
case 31:
throw new IMEEngineActivationFailedException($message, $results);
case 32:
throw new InvalidSelectorException($message, $results);
case 33:
throw new SessionNotCreatedException($message, $results);
case 34:
throw new MoveTargetOutOfBoundsException($message, $results);
default:
throw new UnrecognizedExceptionException($message, $results);
}
} | php | {
"resource": ""
} |
q14180 | WebDriverNavigation.to | train | public function to($url)
{
$params = ['url' => (string) $url];
$this->executor->execute(DriverCommand::GET, $params);
return $this;
} | php | {
"resource": ""
} |
q14181 | HtmlBuilder.nestedListing | train | protected function nestedListing($key, $type, $value)
{
if (is_int($key)) {
return $this->listing($type, $value);
} else {
return '<li>' . $key . $this->listing($type, $value) . '</li>';
}
} | php | {
"resource": ""
} |
q14182 | FormBuilder.tel | train | public function tel($name, $value = null, $options = [])
{
return $this->input('tel', $name, $value, $options);
} | php | {
"resource": ""
} |
q14183 | FormBuilder.month | train | public function month($name, $value = null, $options = [])
{
if ($value instanceof DateTime) {
$value = $value->format('Y-m');
}
return $this->input('month', $name, $value, $options);
} | php | {
"resource": ""
} |
q14184 | PolicyCommands.rsyncValidate | train | public function rsyncValidate(CommandData $commandData) {
if (preg_match("/^@prod/", $commandData->input()->getArgument('target'))) {
throw new \Exception(dt('Per !file, you may never rsync to the production site.', ['!file' => __FILE__]));
}
} | php | {
"resource": ""
} |
q14185 | PSR7Client.configureServer | train | protected function configureServer(array $ctx): array
{
$server = $this->originalServer;
$server['REQUEST_TIME'] = time();
$server['REQUEST_TIME_FLOAT'] = microtime(true);
$server['REMOTE_ADDR'] = $ctx['attributes']['ipAddress'] ?? $ctx['remoteAddr'] ?? '127.0.0.1';
$server['HTTP_USER_AGENT'] = '';
foreach ($ctx['headers'] as $key => $value) {
$key = strtoupper(str_replace('-', '_', $key));
if (\in_array($key, ['CONTENT_TYPE', 'CONTENT_LENGTH'])) {
$server[$key] = implode(', ', $value);
} else {
$server['HTTP_' . $key] = implode(', ', $value);
}
}
return $server;
} | php | {
"resource": ""
} |
q14186 | PSR7Client.wrapUploads | train | private function wrapUploads($files): array
{
if (empty($files)) {
return [];
}
$result = [];
foreach ($files as $index => $f) {
if (!isset($f['name'])) {
$result[$index] = $this->wrapUploads($f);
continue;
}
if (UPLOAD_ERR_OK === $f['error']) {
$stream = $this->streamFactory->createStreamFromFile($f['tmpName']);
} else {
$stream = $this->streamFactory->createStream();
}
$result[$index] = $this->uploadsFactory->createUploadedFile(
$stream,
$f['size'],
$f['error'],
$f['name'],
$f['mime']
);
}
return $result;
} | php | {
"resource": ""
} |
q14187 | PSR7Client.fetchProtocolVersion | train | private static function fetchProtocolVersion(string $version): string
{
$v = substr($version, 5);
if ($v === '2.0') {
return '2';
}
// Fallback for values outside of valid protocol versions
if (!in_array($v, static::$allowedVersions, true)) {
return '1.1';
}
return $v;
} | php | {
"resource": ""
} |
q14188 | Worker.receive | train | public function receive(&$header)
{
$body = $this->relay->receiveSync($flags);
if ($flags & Relay::PAYLOAD_CONTROL) {
if ($this->handleControl($body, $header, $flags)) {
// wait for the next command
return $this->receive($header);
}
// no context for the termination.
$header = null;
// Expect process termination
return null;
}
if ($flags & Relay::PAYLOAD_ERROR) {
return new \Error($body);
}
return $body;
} | php | {
"resource": ""
} |
q14189 | Worker.send | train | public function send(string $payload = null, string $header = null)
{
if (is_null($header)) {
$this->relay->send($header, Relay::PAYLOAD_CONTROL | Relay::PAYLOAD_NONE);
} else {
$this->relay->send($header, Relay::PAYLOAD_CONTROL | Relay::PAYLOAD_RAW);
}
$this->relay->send($payload, Relay::PAYLOAD_RAW);
} | php | {
"resource": ""
} |
q14190 | Worker.error | train | public function error(string $message)
{
$this->relay->send(
$message,
Relay::PAYLOAD_CONTROL | Relay::PAYLOAD_RAW | Relay::PAYLOAD_ERROR
);
} | php | {
"resource": ""
} |
q14191 | Worker.handleControl | train | private function handleControl(string $body = null, &$header = null, int $flags = 0): bool
{
$header = $body;
if (is_null($body) || $flags & Relay::PAYLOAD_RAW) {
// empty or raw prefix
return true;
}
$p = json_decode($body, true);
if ($p === false) {
throw new RoadRunnerException("invalid task context, JSON payload is expected");
}
// PID negotiation (socket connections only)
if (!empty($p['pid'])) {
$this->relay->send(
sprintf('{"pid":%s}', getmypid()), Relay::PAYLOAD_CONTROL
);
}
// termination request
if (!empty($p['stop'])) {
return false;
}
// parsed header
$header = $p;
return true;
} | php | {
"resource": ""
} |
q14192 | SelectFields.validateField | train | protected static function validateField($fieldObject)
{
$selectable = true;
// If not a selectable field
if(isset($fieldObject->config['selectable']) && $fieldObject->config['selectable'] === false)
{
$selectable = false;
}
if(isset($fieldObject->config['privacy']))
{
$privacyClass = $fieldObject->config['privacy'];
// If privacy given as a closure
if(is_callable($privacyClass) && call_user_func($privacyClass, self::$args) === false)
{
$selectable = null;
}
// If Privacy class given
elseif(is_string($privacyClass))
{
if(array_has(self::$privacyValidations, $privacyClass))
{
$validated = self::$privacyValidations[$privacyClass];
}
else
{
$validated = call_user_func([app($privacyClass), 'fire'], self::$args);
self::$privacyValidations[$privacyClass] = $validated;
}
if( ! $validated)
{
$selectable = null;
}
}
}
return $selectable;
} | php | {
"resource": ""
} |
q14193 | SelectFields.addAlwaysFields | train | protected static function addAlwaysFields($fieldObject, array &$select, $parentTable, $forRelation = false)
{
if(isset($fieldObject->config['always']))
{
$always = $fieldObject->config['always'];
if(is_string($always))
{
$always = explode(',', $always);
}
// Get as 'field' => true
foreach($always as $field)
{
self::addFieldToSelect($field, $select, $parentTable, $forRelation);
}
}
} | php | {
"resource": ""
} |
q14194 | GraphQLUploadMiddleware.processRequest | train | public function processRequest(Request $request)
{
$contentType = $request->header('content-type') ?: '';
if (mb_stripos($contentType, 'multipart/form-data') !== false) {
$this->validateParsedBody($request);
$request = $this->parseUploadedFiles($request);
}
return $request;
} | php | {
"resource": ""
} |
q14195 | GraphQLUploadMiddleware.parseUploadedFiles | train | private function parseUploadedFiles(Request $request)
{
$bodyParams = $request->all();
if (!isset($bodyParams['map'])) {
throw new RequestError('The request must define a `map`');
}
$map = json_decode($bodyParams['map'], true);
$result = json_decode($bodyParams['operations'], true);
if (isset($result['operationName'])) {
$result['operation'] = $result['operationName'];
unset($result['operationName']);
}
foreach ($map as $fileKey => $locations) {
foreach ($locations as $location) {
$items = &$result;
foreach (explode('.', $location) as $key) {
if (!isset($items[$key]) || !is_array($items[$key])) {
$items[$key] = [];
}
$items = &$items[$key];
}
$items = $request->allFiles()[$fileKey];
}
}
$request->replace($result);
return $request;
} | php | {
"resource": ""
} |
q14196 | GraphQLUploadMiddleware.validateParsedBody | train | private function validateParsedBody(Request $request)
{
$bodyParams = $request->all();
if (null === $bodyParams) {
throw new InvariantViolation(
'Request is expected to provide parsed body for "multipart/form-data" requests but got null'
);
}
if (!is_array($bodyParams)) {
throw new RequestError(
'GraphQL Server expects JSON object or array, but got ' . Utils::printSafeJson($bodyParams)
);
}
if (empty($bodyParams)) {
throw new InvariantViolation(
'Request is expected to provide parsed body for "multipart/form-data" requests but got empty array'
);
}
} | php | {
"resource": ""
} |
q14197 | GraphQLServiceProvider.bootSchemas | train | protected function bootSchemas()
{
$configSchemas = config('graphql.schemas');
foreach ($configSchemas as $name => $schema) {
$this->app['graphql']->addSchema($name, $schema);
}
} | php | {
"resource": ""
} |
q14198 | GraphQLServiceProvider.applySecurityRules | train | protected function applySecurityRules()
{
$maxQueryComplexity = config('graphql.security.query_max_complexity');
if ($maxQueryComplexity !== null) {
/** @var QueryComplexity $queryComplexity */
$queryComplexity = DocumentValidator::getRule('QueryComplexity');
$queryComplexity->setMaxQueryComplexity($maxQueryComplexity);
}
$maxQueryDepth = config('graphql.security.query_max_depth');
if ($maxQueryDepth !== null) {
/** @var QueryDepth $queryDepth */
$queryDepth = DocumentValidator::getRule('QueryDepth');
$queryDepth->setMaxQueryDepth($maxQueryDepth);
}
$disableIntrospection = config('graphql.security.disable_introspection');
if ($disableIntrospection === true) {
/** @var DisableIntrospection $disableIntrospection */
$disableIntrospection = DocumentValidator::getRule('DisableIntrospection');
$disableIntrospection->setEnabled(DisableIntrospection::ENABLED);
}
} | php | {
"resource": ""
} |
q14199 | PostsController.store | train | public function store($id)
{
$data = [
'title' => request('title'),
'excerpt' => request('excerpt', ''),
'slug' => request('slug'),
'body' => request('body', ''),
'published' => request('published'),
'author_id' => request('author_id'),
'featured_image' => request('featured_image'),
'featured_image_caption' => request('featured_image_caption', ''),
'publish_date' => request('publish_date', ''),
'meta' => request('meta', (object) []),
];
validator($data, [
'publish_date' => 'required|date',
'author_id' => 'required',
'title' => 'required',
'slug' => 'required|'.Rule::unique(config('wink.database_connection').'.wink_posts', 'slug')->ignore(request('id')),
])->validate();
$entry = $id !== 'new' ? WinkPost::findOrFail($id) : new WinkPost(['id' => request('id')]);
$entry->fill($data);
$entry->save();
$entry->tags()->sync(
$this->collectTags(request('tags'))
);
return response()->json([
'entry' => $entry,
]);
} | php | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.