_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
33
8k
language
stringclasses
1 value
meta_information
dict
q254400
ImageMagickHandler._crop
test
public function _crop() { $source = ! empty($this->resource) ? $this->resource : $this->image->getPathname(); $destination = $this->getResourcePath(); $action = ' -crop ' . $this->width . 'x' . $this->height . '+' . $this->xAxis
php
{ "resource": "" }
q254401
ImageMagickHandler.getVersion
test
public function getVersion(): string { $result = $this->process('-version'); // The first line
php
{ "resource": "" }
q254402
ImageMagickHandler.getResourcePath
test
protected function getResourcePath() { if (! is_null($this->resource)) { return $this->resource; } $this->resource = WRITEPATH
php
{ "resource": "" }
q254403
Forge.addForeignKey
test
public function addForeignKey(string $fieldName = '', string $tableName = '', string $tableField = '', string $onUpdate = '', string $onDelete = '') { if (! isset($this->fields[$fieldName])) { throw new DatabaseException(lang('Database.fieldNotExists', [$fieldName])); } $this->foreignKeys[$fieldName] =
php
{ "resource": "" }
q254404
Forge.dropForeignKey
test
public function dropForeignKey(string $table, string $foreign_name) { $sql = sprintf($this->dropConstraintStr, $this->db->escapeIdentifiers($this->db->DBPrefix . $table), $this->db->escapeIdentifiers($this->db->DBPrefix . $foreign_name)); if ($sql === false) { if ($this->db->DBDebug)
php
{ "resource": "" }
q254405
Forge._attributeUnsigned
test
protected function _attributeUnsigned(array &$attributes, array &$field) { if (empty($attributes['UNSIGNED']) || $attributes['UNSIGNED'] !== true) { return; } // Reset the attribute in order to avoid issues if we do type conversion $attributes['UNSIGNED'] = false; if (is_array($this->unsigned)) { ...
php
{ "resource": "" }
q254406
Forge._attributeDefault
test
protected function _attributeDefault(array &$attributes, array &$field) { if ($this->default === false) { return; } if (array_key_exists('DEFAULT', $attributes)) { if ($attributes['DEFAULT'] === null) { $field['default'] = empty($this->null)
php
{ "resource": "" }
q254407
Forge._processPrimaryKeys
test
protected function _processPrimaryKeys(string $table): string { $sql = ''; for ($i = 0, $c = count($this->primaryKeys); $i < $c; $i++) { if (! isset($this->fields[$this->primaryKeys[$i]]))
php
{ "resource": "" }
q254408
Forge._processForeignKeys
test
protected function _processForeignKeys(string $table): string { $sql = ''; $allowActions = [ 'CASCADE', 'SET NULL', 'NO ACTION', 'RESTRICT', 'SET DEFAULT', ]; if (count($this->foreignKeys) > 0) { foreach ($this->foreignKeys as $field => $fkey) { $name_index = $table . '_' . $field ...
php
{ "resource": "" }
q254409
Language.setLocale
test
public function setLocale(string $locale = null) { if (! is_null($locale)) {
php
{ "resource": "" }
q254410
Language.getLine
test
public function getLine(string $line, array $args = []) { // ignore requests with no file specified if (! strpos($line, '.')) { return $line; } // Parse out the file name and the actual alias. // Will load the language file and strings. [ $file, $parsedLine, ] = $this->parseLine($line, $this-...
php
{ "resource": "" }
q254411
Language.formatMessage
test
protected function formatMessage($message, array $args = []) { if (! $this->intlSupport || ! $args) { return $message; } if (is_array($message)) { foreach ($message as $index => $value) {
php
{ "resource": "" }
q254412
Language.requireFile
test
protected function requireFile(string $path): array { $files = Services::locator()->search($path); $strings = []; foreach ($files as $file) { // On some OS's we were seeing failures // on this command returning boolean instead // of array during testing, so we've removed // the require_once for ...
php
{ "resource": "" }
q254413
ContentSecurityPolicy.addBaseURI
test
public function addBaseURI($uri, ?bool $explicitReporting = null) { $this->addOption($uri,
php
{ "resource": "" }
q254414
ContentSecurityPolicy.addImageSrc
test
public function addImageSrc($uri, ?bool $explicitReporting = null) { $this->addOption($uri,
php
{ "resource": "" }
q254415
ContentSecurityPolicy.addMediaSrc
test
public function addMediaSrc($uri, ?bool $explicitReporting = null) { $this->addOption($uri,
php
{ "resource": "" }
q254416
ContentSecurityPolicy.addManifestSrc
test
public function addManifestSrc($uri, ?bool $explicitReporting = null) {
php
{ "resource": "" }
q254417
ContentSecurityPolicy.addObjectSrc
test
public function addObjectSrc($uri, ?bool $explicitReporting = null) { $this->addOption($uri,
php
{ "resource": "" }
q254418
ContentSecurityPolicy.addPluginType
test
public function addPluginType($mime, ?bool $explicitReporting = null) { $this->addOption($mime,
php
{ "resource": "" }
q254419
ContentSecurityPolicy.addSandbox
test
public function addSandbox($flags, ?bool $explicitReporting = null) {
php
{ "resource": "" }
q254420
ContentSecurityPolicy.addScriptSrc
test
public function addScriptSrc($uri, ?bool $explicitReporting = null) { $this->addOption($uri,
php
{ "resource": "" }
q254421
ContentSecurityPolicy.addStyleSrc
test
public function addStyleSrc($uri, ?bool $explicitReporting = null) { $this->addOption($uri,
php
{ "resource": "" }
q254422
ContentSecurityPolicy.addOption
test
protected function addOption($options, string $target, ?bool $explicitReporting = null) { // Ensure we have an array to work with... if (is_string($this->{$target})) { $this->{$target} = [$this->{$target}]; } if (is_array($options)) { foreach ($options
php
{ "resource": "" }
q254423
ContentSecurityPolicy.generateNonces
test
protected function generateNonces(ResponseInterface &$response) { $body = $response->getBody(); if (empty($body)) { return; } if (! is_array($this->styleSrc)) { $this->styleSrc = [$this->styleSrc]; } if (! is_array($this->scriptSrc)) { $this->scriptSrc = [$this->scriptSrc]; } // Repla...
php
{ "resource": "" }
q254424
ContentSecurityPolicy.buildHeaders
test
protected function buildHeaders(ResponseInterface &$response) { // Ensure both headers are available and arrays... $response->setHeader('Content-Security-Policy', []); $response->setHeader('Content-Security-Policy-Report-Only', []); $directives = [ 'base-uri' => 'baseURI', 'child-src' => 'c...
php
{ "resource": "" }
q254425
BaseCollector.getTitle
test
public function getTitle(bool $safe = false): string { if ($safe) { return str_replace(' ',
php
{ "resource": "" }
q254426
Logs.collectLogs
test
protected function collectLogs() { if (! is_null($this->data))
php
{ "resource": "" }
q254427
Cell.prepareParams
test
public function prepareParams($params) { if (empty($params) || ( ! is_string($params) && ! is_array($params))) { return []; } if (is_string($params)) { $new_params = []; $separator = ' '; if (strpos($params, ',') !== false) { $separator = ',';
php
{ "resource": "" }
q254428
Cell.determineClass
test
protected function determineClass(string $library): array { // We don't want to actually call static methods // by default, so convert any double colons. $library = str_replace('::', ':', $library); list($class, $method) = explode(':', $library); if (empty($class)) { throw ViewException::forNoCellClas...
php
{ "resource": "" }
q254429
BaseResult.getResult
test
public function getResult(string $type = 'object'): array { if ($type === 'array') { return $this->getResultArray();
php
{ "resource": "" }
q254430
BaseResult.getCustomResultObject
test
public function getCustomResultObject(string $className) { if (isset($this->customResultObject[$className])) { return $this->customResultObject[$className]; } if (is_bool($this->resultID) || ! $this->resultID || $this->numRows === 0) { return []; } // Don't fetch the result set again if we alread...
php
{ "resource": "" }
q254431
BaseResult.getResultArray
test
public function getResultArray(): array { if (! empty($this->resultArray)) { return $this->resultArray; } // In the event that query caching is on, the result_id variable // will not be a valid resource so we'll simply return an empty // array. if (is_bool($this->resultID) || ! $this->resultID || $th...
php
{ "resource": "" }
q254432
BaseResult.getResultObject
test
public function getResultObject(): array { if (! empty($this->resultObject)) { return $this->resultObject; } // In the event that query caching is on, the result_id variable // will not be a valid resource so we'll simply return an empty // array. if (is_bool($this->resultID) || ! $this->resultID || ...
php
{ "resource": "" }
q254433
BaseResult.getRow
test
public function getRow($n = 0, string $type = 'object') { if (! is_numeric($n)) { // We cache the row data for subsequent uses is_array($this->rowData) || $this->rowData = $this->getRowArray(0); // array_key_exists() instead of isset() to allow for NULL values if (empty($this->rowData) || ! array_key_...
php
{ "resource": "" }
q254434
BaseResult.getCustomRowObject
test
public function getCustomRowObject(int $n, string $className) { isset($this->customResultObject[$className]) || $this->getCustomResultObject($className); if (empty($this->customResultObject[$className])) { return null; } if ($n !== $this->currentRow
php
{ "resource": "" }
q254435
BaseResult.getRowArray
test
public function getRowArray(int $n = 0) { $result = $this->getResultArray(); if (empty($result)) { return null; } if ($n !== $this->currentRow &&
php
{ "resource": "" }
q254436
BaseResult.getRowObject
test
public function getRowObject(int $n = 0) { $result = $this->getResultObject(); if (empty($result)) {
php
{ "resource": "" }
q254437
BaseResult.setRow
test
public function setRow($key, $value = null) { // We cache the row data for subsequent uses if (! is_array($this->rowData)) { $this->rowData = $this->getRowArray(0); } if (is_array($key)) { foreach ($key
php
{ "resource": "" }
q254438
BaseResult.getFirstRow
test
public function getFirstRow(string $type = 'object') { $result = $this->getResult($type);
php
{ "resource": "" }
q254439
BaseResult.getLastRow
test
public function getLastRow(string $type = 'object') { $result = $this->getResult($type);
php
{ "resource": "" }
q254440
BaseResult.getNextRow
test
public function getNextRow(string $type = 'object') { $result = $this->getResult($type); if (empty($result)) { return null; }
php
{ "resource": "" }
q254441
BaseResult.getUnbufferedRow
test
public function getUnbufferedRow(string $type = 'object') { if ($type === 'array') { return $this->fetchAssoc();
php
{ "resource": "" }
q254442
Negotiate.match
test
protected function match(array $acceptable, string $supported, bool $enforceTypes = false): bool { $supported = $this->parseHeader($supported); if (is_array($supported) && count($supported) === 1) { $supported = $supported[0]; } // Is it an exact match? if ($acceptable['value'] === $supported['value'])...
php
{ "resource": "" }
q254443
Negotiate.matchParameters
test
protected function matchParameters(array $acceptable, array $supported): bool { if (count($acceptable['params']) !== count($supported['params'])) { return false; } foreach ($supported['params'] as $label => $value)
php
{ "resource": "" }
q254444
Console.run
test
public function run(bool $useSafeOutput = false) { $path = CLI::getURI() ?: 'list'; // Set the path for the application to route to.
php
{ "resource": "" }
q254445
Console.showHeader
test
public function showHeader() { CLI::newLine(1); CLI::write(CLI::color('CodeIgniter CLI Tool',
php
{ "resource": "" }
q254446
Pager.links
test
public function links(string $group = 'default', string $template = 'default_full'): string {
php
{ "resource": "" }
q254447
Pager.makeLinks
test
public function makeLinks(int $page, int $perPage, int $total, string $template = 'default_full', int $segment =
php
{ "resource": "" }
q254448
Pager.store
test
public function store(string $group, int $page, int $perPage, int $total, int $segment = 0) { $this->segment[$group] = $segment; $this->ensureGroup($group);
php
{ "resource": "" }
q254449
Pager.setPath
test
public function setPath(string $path, string $group = 'default') { $this->ensureGroup($group);
php
{ "resource": "" }
q254450
Pager.getPageCount
test
public function getPageCount(string $group = 'default'): int { $this->ensureGroup($group);
php
{ "resource": "" }
q254451
Pager.getCurrentPage
test
public function getCurrentPage(string $group = 'default'): int { $this->ensureGroup($group);
php
{ "resource": "" }
q254452
Pager.hasMore
test
public function hasMore(string $group = 'default'): bool { $this->ensureGroup($group); return
php
{ "resource": "" }
q254453
Pager.getLastPage
test
public function getLastPage(string $group = 'default') { $this->ensureGroup($group); if (! is_numeric($this->groups[$group]['total']) || ! is_numeric($this->groups[$group]['perPage'])) {
php
{ "resource": "" }
q254454
Pager.getPageURI
test
public function getPageURI(int $page = null, string $group = 'default', bool $returnObject = false) { $this->ensureGroup($group); /** * @var \CodeIgniter\HTTP\URI $uri */ $uri = $this->groups[$group]['uri']; $segment = $this->segment[$group] ?? 0; if ($segment) { $uri->setSegment($segment, $pag...
php
{ "resource": "" }
q254455
Pager.getNextPageURI
test
public function getNextPageURI(string $group = 'default', bool $returnObject = false) { $this->ensureGroup($group); $last = $this->getLastPage($group); $curr = $this->getCurrentPage($group); $page = null; if (! empty($last) && ! empty($curr) && $last
php
{ "resource": "" }
q254456
Pager.getPreviousPageURI
test
public function getPreviousPageURI(string $group = 'default', bool $returnObject = false) { $this->ensureGroup($group); $first = $this->getFirstPage($group); $curr = $this->getCurrentPage($group); $page = null; if (! empty($first) && ! empty($curr)
php
{ "resource": "" }
q254457
Pager.getPerPage
test
public function getPerPage(string $group = 'default'): int
php
{ "resource": "" }
q254458
Pager.getDetails
test
public function getDetails(string $group = 'default'): array { if (! array_key_exists($group, $this->groups)) { throw PagerException::forInvalidPaginationGroup($group); } $newGroup = $this->groups[$group]; $newGroup['next'] =
php
{ "resource": "" }
q254459
Pager.ensureGroup
test
protected function ensureGroup(string $group) { if (array_key_exists($group, $this->groups)) { return; } $this->groups[$group] = [ 'uri' => clone Services::request()->uri, 'hasMore' => false, 'total' => null, 'perPage' => $this->config->perPage, 'pageCount' => 1, ]; if (ar...
php
{ "resource": "" }
q254460
TimeDifference.getYears
test
public function getYears(bool $raw = false) { if ($raw) { return $this->difference / YEAR; } $time
php
{ "resource": "" }
q254461
TimeDifference.getMonths
test
public function getMonths(bool $raw = false) { if ($raw) { return $this->difference / MONTH; } $time
php
{ "resource": "" }
q254462
TimeDifference.getWeeks
test
public function getWeeks(bool $raw = false) { if ($raw) { return $this->difference / WEEK; } $time = clone($this->currentTime);
php
{ "resource": "" }
q254463
TimeDifference.getDays
test
public function getDays(bool $raw = false) { if ($raw) { return $this->difference / DAY; } $time
php
{ "resource": "" }
q254464
TimeDifference.getHours
test
public function getHours(bool $raw = false) { if ($raw) { return $this->difference / HOUR; } $time
php
{ "resource": "" }
q254465
TimeDifference.getMinutes
test
public function getMinutes(bool $raw = false) { if ($raw) { return $this->difference / MINUTE; } $time
php
{ "resource": "" }
q254466
TimeDifference.getSeconds
test
public function getSeconds(bool $raw = false) { if ($raw) { return $this->difference; } $time = clone($this->currentTime);
php
{ "resource": "" }
q254467
TimeDifference.humanize
test
public function humanize(string $locale = null): string { $current = clone($this->currentTime); $years = $current->fieldDifference($this->testTime, IntlCalendar::FIELD_YEAR); $months = $current->fieldDifference($this->testTime, IntlCalendar::FIELD_MONTH); $days = $current->fieldDifference($this->testTim...
php
{ "resource": "" }
q254468
Database.load
test
public function load(array $params = [], string $alias) { // No DB specified? Beat them senseless... if (empty($params['DBDriver'])) { throw new \InvalidArgumentException('You have not selected a database type to connect to.'); } $className = strpos($params['DBDriver'], '\\') === false ? '\CodeIgniter...
php
{ "resource": "" }
q254469
Database.loadForge
test
public function loadForge(ConnectionInterface $db) { $className = strpos($db->DBDriver, '\\') === false ? '\CodeIgniter\Database\\' . $db->DBDriver . '\\Forge' : $db->DBDriver . '\\Forge'; // Make sure a connection exists
php
{ "resource": "" }
q254470
Entity.hasPropertyChanged
test
protected function hasPropertyChanged(string $key, $value = null): bool { return ! (($this->_original[$key] === null &&
php
{ "resource": "" }
q254471
Entity.mapProperty
test
protected function mapProperty(string $key) { if (empty($this->_options['datamap'])) { return $key; }
php
{ "resource": "" }
q254472
Entity.mutateDate
test
protected function mutateDate($value) { if ($value instanceof Time) { return $value; } if ($value instanceof \DateTime) { return Time::instance($value); } if (is_numeric($value)) {
php
{ "resource": "" }
q254473
Entity.castAsJson
test
private function castAsJson($value, bool $asArray = false) { $tmp = ! is_null($value) ? ($asArray ? [] : new \stdClass) : null; if (function_exists('json_decode')) { if ((is_string($value) && (strpos($value, '[') === 0
php
{ "resource": "" }
q254474
Modules.shouldDiscover
test
public function shouldDiscover(string $alias) { if (! $this->enabled)
php
{ "resource": "" }
q254475
Model.findAll
test
public function findAll(int $limit = 0, int $offset = 0) { $builder = $this->builder(); if ($this->tempUseSoftDeletes === true) { $builder->where($this->table . '.' . $this->deletedField, 0); } $row = $builder->limit($limit, $offset) ->get(); $row = $row->getResult($this->tempReturnType); $row...
php
{ "resource": "" }
q254476
Model.first
test
public function first() { $builder = $this->builder(); if ($this->tempUseSoftDeletes === true) { $builder->where($this->table . '.' . $this->deletedField, 0); } // Some databases, like PostgreSQL, need order // information to consistently return correct results.
php
{ "resource": "" }
q254477
Model.save
test
public function save($data): bool { if (empty($data)) { return true; } if (is_object($data) && isset($data->{$this->primaryKey})) { $response = $this->update($data->{$this->primaryKey}, $data); } elseif (is_array($data) && ! empty($data[$this->primaryKey])) { $response = $this->update($data[$...
php
{ "resource": "" }
q254478
Model.classToArray
test
public static function classToArray($data, $primaryKey = null, string $dateFormat = 'datetime', bool $onlyChanged = true): array { if (method_exists($data, 'toRawArray')) { $properties = $data->toRawArray($onlyChanged); // Always grab the primary key otherwise updates will fail. if (! empty($properties) ...
php
{ "resource": "" }
q254479
Model.insert
test
public function insert($data = null, bool $returnID = true) { $escape = null; $this->insertID = 0; if (empty($data)) { $data = $this->tempData['data'] ?? null; $escape = $this->tempData['escape'] ?? null; $this->tempData = []; } if (empty($data)) { throw DataException::fo...
php
{ "resource": "" }
q254480
Model.insertBatch
test
public function insertBatch(array $set = null, bool $escape = null, int $batchSize = 100, bool $testing = false) { if (is_array($set) && $this->skipValidation === false)
php
{ "resource": "" }
q254481
Model.builder
test
protected function builder(string $table = null) { if ($this->builder instanceof BaseBuilder) { return $this->builder; } // We're going to force a primary key to exist // so we don't have overly convoluted code, // and future features are likely to require them. if (empty($this->primaryKey)) { t...
php
{ "resource": "" }
q254482
Model.doProtectFields
test
protected function doProtectFields(array $data): array { if ($this->protectFields === false) { return $data; } if (empty($this->allowedFields)) { throw DataException::forInvalidAllowedFields(get_class($this)); } if (is_array($data) && count($data)) { foreach ($data
php
{ "resource": "" }
q254483
Model.cleanValidationRules
test
protected function cleanValidationRules(array $rules, array $data = null): array { if (empty($data)) { return []; } foreach ($rules as $field => $rule)
php
{ "resource": "" }
q254484
Model.getValidationRules
test
public function getValidationRules(array $options = []): array { $rules = $this->validationRules; if (isset($options['except'])) { $rules = array_diff_key($rules, array_flip($options['except']));
php
{ "resource": "" }
q254485
Model.countAllResults
test
public function countAllResults(bool $reset = true, bool $test = false) { if ($this->tempUseSoftDeletes
php
{ "resource": "" }
q254486
CURLRequest.setAuth
test
public function setAuth(string $username, string $password, string $type = 'basic') { $this->config['auth'] = [
php
{ "resource": "" }
q254487
CURLRequest.setForm
test
public function setForm(array $params, bool $multipart = false) { if ($multipart) { $this->config['multipart'] = $params; } else {
php
{ "resource": "" }
q254488
CURLRequest.parseOptions
test
protected function parseOptions(array $options) { if (array_key_exists('baseURI', $options)) { $this->baseURI = $this->baseURI->setURI($options['baseURI']); unset($options['baseURI']); } if (array_key_exists('headers', $options) && is_array($options['headers'])) { foreach ($options['headers'] as $n...
php
{ "resource": "" }
q254489
CURLRequest.getMethod
test
public function getMethod(bool $upper = false): string
php
{ "resource": "" }
q254490
CURLRequest.send
test
public function send(string $method, string $url) { // Reset our curl options so we're on a fresh slate. $curl_options = []; if (! empty($this->config['query']) && is_array($this->config['query'])) { // This is likely too naive a solution. // Should look into handling when $url already // has query v...
php
{ "resource": "" }
q254491
CURLRequest.applyRequestHeaders
test
protected function applyRequestHeaders(array $curl_options = []): array { $headers = $this->getHeaders(); if (empty($headers)) { return $curl_options;
php
{ "resource": "" }
q254492
CURLRequest.setResponseHeaders
test
protected function setResponseHeaders(array $headers = []) { foreach ($headers as $header) { if (($pos = strpos($header, ':')) !== false) { $title = substr($header, 0, $pos); $value = substr($header, $pos + 1); $this->response->setHeader($title, $value); } else if (strpos($header, 'HTTP') ...
php
{ "resource": "" }
q254493
CURLRequest.sendRequest
test
protected function sendRequest(array $curl_options = []): string { $ch = curl_init(); curl_setopt_array($ch, $curl_options); // Send the request and wait for a response. $output = curl_exec($ch); if ($output ===
php
{ "resource": "" }
q254494
MigrationRunner.version
test
public function version(string $targetVersion, string $namespace = null, string $group = null) { if (! $this->enabled) { throw ConfigException::forDisabledMigrations(); } $this->ensureTable(); // Set Namespace if not null if (! is_null($namespace)) { $this->setNamespace($namespace); } // Set...
php
{ "resource": "" }
q254495
MigrationRunner.findMigrations
test
public function findMigrations(): array { $migrations = []; // If $this->path contains a valid directory use it. if (! empty($this->path)) { helper('filesystem'); $dir = rtrim($this->path, DIRECTORY_SEPARATOR) . '/'; $files = get_filenames($dir, true); } // Otherwise use FileLocator to search f...
php
{ "resource": "" }
q254496
MigrationRunner.checkMigrations
test
protected function checkMigrations(array $migrations, string $method, string $targetVersion): bool { // Check if no migrations found if (empty($migrations)) { if ($this->silent) { return false; } throw new \RuntimeException(lang('Migrations.empty')); } // Check if $targetVersion file is foun...
php
{ "resource": "" }
q254497
MigrationRunner.getHistory
test
public function getHistory(string $group = 'default'): array { $this->ensureTable(); $query = $this->db->table($this->table)
php
{ "resource": "" }
q254498
MigrationRunner.getMigrationName
test
protected function getMigrationName(string $migration): string {
php
{ "resource": "" }
q254499
MigrationRunner.getVersion
test
protected function getVersion(): string { $this->ensureTable(); $row = $this->db->table($this->table) ->select('version') ->where('group', $this->group) ->where('namespace', $this->namespace)
php
{ "resource": "" }