_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q268200
RequestTrait.validateMethod
test
protected function validateMethod(string $method): void { if (! RequestMethod::isValid($method)) { throw new InvalidMethod( sprintf( 'Unsupported HTTP method "%s" provided', $method ) ); } }
php
{ "resource": "" }
q268201
Locator.locate
test
public function locate($command) { $paths = $this->locateAll($command); return empty($paths) ? null : $paths[0]; }
php
{ "resource": "" }
q268202
Locator.locateAll
test
public function locateAll($command) { return array_values(array_filter($this->_pathBuilder->getPermutations($command), $this->_executableTester)); }
php
{ "resource": "" }
q268203
PEAR_Downloader_Package.&
test
function &download() { if (isset($this->_packagefile)) { return $this->_packagefile; } if (isset($this->_downloadURL['url'])) { $this->_isvalid = false; $info = $this->getParsedPackage(); foreach ($info as $i => $p) { $info[$i]...
php
{ "resource": "" }
q268204
PEAR_Downloader_Package.removeInstalled
test
function removeInstalled(&$params) { if (!isset($params[0])) { return; } $options = $params[0]->_downloader->getOptions(); if (!isset($options['downloadonly'])) { foreach ($params as $i => $param) { $package = $param->getPackage(); ...
php
{ "resource": "" }
q268205
PEAR_Downloader_Package.detectStupidDuplicates
test
function detectStupidDuplicates($params, &$errorparams) { $existing = array(); foreach ($params as $i => $param) { $package = $param->getPackage(); $channel = $param->getChannel(); $group = $param->getGroup(); if (!isset($existing[$channel . '/' . $p...
php
{ "resource": "" }
q268206
PEAR_Downloader_Package._fromFile
test
function _fromFile(&$param) { $saveparam = $param; if (is_string($param)) { if (!@file_exists($param)) { $test = explode('#', $param); $group = array_pop($test); if (@file_exists(implode('#', $test))) { $this->setGroup($...
php
{ "resource": "" }
q268207
JsonParametersExtractor.getParameters
test
public function getParameters() { $bodyParams = json_decode($this->body, true); if (!$bodyParams) { return array(); } $parameters = array(); foreach ($bodyParams as $paramName => $paramValue) { $parameters[$paramName] = $paramValue; } ...
php
{ "resource": "" }
q268208
Debug.enable
test
public static function enable(int $errorReportingLevel = E_ALL, bool $displayErrors = false): void { // If debug is already enabled if (static::$enabled) { // Don't do things twice return; } // Debug is enabled static::$enabled = true; // The...
php
{ "resource": "" }
q268209
Budget.getAmountDifference
test
public function getAmountDifference() { $amount = ($this->hasChildren() ? $this->getGlobalAmount() : $this->getAmount()); return ($amount - $this->getTransactionsAmount()); }
php
{ "resource": "" }
q268210
Budget.addMonthToBitmask
test
public function addMonthToBitmask($month) { $month = (int) $month; if ($month < 1 || $month > 12) { throw new \RangeException('Month is invalid!'); } $bit = pow(2, $month - 1); $bitmask = $this->getMonthBitmask() | $bit; $this->setMonthBitmask($bitma...
php
{ "resource": "" }
q268211
Budget.hasMonth
test
public function hasMonth($month) { $bitmask = $this->getMonthBitmask(); $month = (int) $month; $bit = pow(2, $month - 1); return ($bit === ($bit & $bitmask)); }
php
{ "resource": "" }
q268212
HTTP_Request2_MultipartBody.getLength
test
public function getLength() { $boundaryLength = strlen($this->getBoundary()); $headerParamLength = strlen($this->_headerParam) - 4 + $boundaryLength; $headerUploadLength = strlen($this->_headerUpload) - 8 + $boundaryLength; $length = $boundaryLength + 6; ...
php
{ "resource": "" }
q268213
HTTP_Request2_MultipartBody.getBoundary
test
public function getBoundary() { if (empty($this->_boundary)) { $this->_boundary = '--' . md5('PEAR-HTTP_Request2-' . microtime()); } return $this->_boundary; }
php
{ "resource": "" }
q268214
DbalUserProvider.loadUserByUsername
test
public function loadUserByUsername($username) { $qb = $this->_conn->createQueryBuilder(); $qb->select('su.username, su.password') ->from('security_users', 'su') ->where( $qb->expr()->orX( $qb->expr()->eq('su.username', ':username'), ...
php
{ "resource": "" }
q268215
User.create
test
public function create($sendWelcome = true) { if ($this->getIsNewRecord() == false) { throw new \RuntimeException('Calling "' . __CLASS__ . '::' . __METHOD__ . '" on existing user'); } $this->confirmed_at = time(); $this->password = $this->password == null ? Password::genera...
php
{ "resource": "" }
q268216
Socket.setIpAddress
test
public function setIpAddress($ip, $port = 80) { if (false !== strpos($ip, ':')) { list($ip, $port) = explode(':', $ip); } if (empty($ip)) { $ip = '127.0.0.1'; } $this->ip = $ip; $this->port = intval($port); return $this; }
php
{ "resource": "" }
q268217
Mail.renderView
test
protected function renderView($view, array $parameters = array()) { if ($this->_oContainer->has('templating')) { return $this->_oContainer->get('templating')->render($view, $parameters); } if (!$this->_oContainer->has('twig')) { throw new \LogicException('You can not...
php
{ "resource": "" }
q268218
EventStoreRepository.publishStream
test
protected function publishStream(StreamInterface $stream): EventStoreRepository { foreach ($stream as $domainEventMessage) { $this ->getEventPublisher() ->publish($domainEventMessage); } return $this; }
php
{ "resource": "" }
q268219
LinkedResourceFetcher.onResourceMaterialize
test
public function onResourceMaterialize(ResourceMaterializeEvent $e) { /** @var $resource MaterializedResource */ $resource = $e->getResource(); // Only scan resources with .css extension. if (preg_match('/\.css$/i', $resource->getPath())) { $this->scanner->scan($resource,...
php
{ "resource": "" }
q268220
Message.params
test
public function params( /*...*/ ) { $args = func_get_args(); if ( isset( $args[0] ) && is_array( $args[0] ) ) { $args = $args[0]; } $values = array_values( $args ); $this->params = array_merge( $this->params, $values ); return $this; }
php
{ "resource": "" }
q268221
Message.fetchMessage
test
protected function fetchMessage() { if ( $this->message === null ) { $this->message = $this->ctx->getMessageCache()->get( $this->key, array( $this->ctx->getCurrentLanguage(), $this->ctx->getDefaultLanguage(), ) ); } return $this->message; }
php
{ "resource": "" }
q268222
SodiumCrypt.encrypt
test
public function encrypt(string $message, string $key = null): string { $key = $key ?? $this->getKey(); $nonce = random_bytes( SODIUM_CRYPTO_SECRETBOX_NONCEBYTES ); $cipher = base64_encode( $nonce . sodium_crypto_secretbox( $messag...
php
{ "resource": "" }
q268223
SodiumCrypt.decrypt
test
public function decrypt(string $encrypted, string $key = null): string { $key = $key ?? $this->getKey(); $decoded = base64_decode($encrypted, true); if ($decoded === false) { throw new CryptException('The encoding failed'); } if (mb_strlen($decoded, '8bit') ...
php
{ "resource": "" }
q268224
SodiumCrypt.decryptArray
test
public function decryptArray(string $encrypted, string $key = null): array { return \json_decode($this->decrypt($encrypted, $key), true); }
php
{ "resource": "" }
q268225
SodiumCrypt.encryptObject
test
public function encryptObject(object $object, string $key = null): string { return $this->encrypt(\json_encode($object), $key); }
php
{ "resource": "" }
q268226
SodiumCrypt.decryptObject
test
public function decryptObject(string $encrypted, string $key = null): object { return \json_decode($this->decrypt($encrypted, $key), true); }
php
{ "resource": "" }
q268227
Zend_Cache_Backend_Static.getOption
test
public function getOption($name) { $name = strtolower($name); if ($name == 'tag_cache') { return $this->getInnerCache(); } return parent::getOption($name); }
php
{ "resource": "" }
q268228
AbstractPackageDependent.init
test
protected function init() { $clsname = get_called_class(); if (property_exists($clsname, 'defaults')) { foreach($clsname::$defaults as $name=>$value) { $this->{$name} = $value; } } return $this; }
php
{ "resource": "" }
q268229
AbstractComponent.replaceMagicFields
test
public function replaceMagicFields($html) { $html = str_replace('%id%', $this->getId(), $html); $html = str_replace('%class%', implode(' ', $this->classes), $html); $html = str_replace('%style%', $this->getStyle(), $html); $html = str_replace('%name%', $this->getName(), $html); $html = str_r...
php
{ "resource": "" }
q268230
PsiToOrmQueryBuilderConverter.convert
test
public function convert(Query $query): QueryBuilder { $queryBuilder = $this->entityManager ->getRepository($query->getClassFqn()) ->createQueryBuilder(self::FROM_ALIAS); $this->buildSelects($queryBuilder, $query); $this->buildJoins($queryBuilder, $query); if...
php
{ "resource": "" }
q268231
RichText.asText
test
public static function asText($richText) { $result = ''; foreach ($richText as $block) { if (isset($block->text)) { $result .= $block->text . "\n"; } } return $result; }
php
{ "resource": "" }
q268232
RichText.asHtml
test
public static function asHtml(array $richText, LinkResolver $linkResolver = null) { $groups = []; if(is_array($richText) && key_exists('dimensions', $richText)) { return self::asImageBlock($richText); } foreach ($richText as $block) { $block = (object) $bloc...
php
{ "resource": "" }
q268233
RichText.asHtmlBlock
test
private static function asHtmlBlock(\stdClass $block, $linkResolver = null, $htmlSerializer = null) { $content = ''; if ($block->type === 'heading1' || $block->type === 'heading2' || $block->type === 'heading3' || $block->type === 'heading4' || $block-...
php
{ "resource": "" }
q268234
NativeResponse.withoutCookie
test
public function withoutCookie(Cookie $cookie) { $cookie->setValue(); $cookie->setExpire(); return $this->withAddedHeader( Header::SET_COOKIE, (string) $cookie ); }
php
{ "resource": "" }
q268235
NativeResponse.send
test
public function send(): Response { $http_line = sprintf( 'HTTP/%s %s %s', $this->getProtocolVersion(), $this->getStatusCode(), $this->getReasonPhrase() ); header($http_line, true, $this->getStatusCode()); foreach ($this->getHeaders() ...
php
{ "resource": "" }
q268236
NativeResponse.validateStatusCode
test
protected function validateStatusCode(int $code): int { if (StatusCode::MIN > $code || $code > StatusCode::MAX) { throw new InvalidStatusCode( sprintf( 'Invalid status code "%d"; must adhere to values set in the %s enum class.', $code, ...
php
{ "resource": "" }