_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
33
8k
language
stringclasses
1 value
meta_information
dict
q260500
Reflexion.get
test
public static function get($object, $property) { $property = self::getReflectionProperty($object, $property); if (is_string($object) || $property->isStatic()) { if (($declaringClass = $property->getDeclaringClass()->getName()) !== self::toClassName($object)) {
php
{ "resource": "" }
q260501
Reflexion.invoke
test
public static function invoke($object, $method, ...$params) { $method = self::getReflectionMethod($object, $method); if (is_string($object) || $method->isStatic()) { if (($declaringClass = $method->getDeclaringClass()->getName()) !== self::toClassName($object)) {
php
{ "resource": "" }
q260502
CacheStrategy.save
test
public function save($keyName = null, $content = null, $lifetime = null, $stopBuffer =
php
{ "resource": "" }
q260503
CacheStrategy.exists
test
public function exists($keyName = null, $lifetime = null)
php
{ "resource": "" }
q260504
CurrencyMiddleware.getUserCurrency
test
protected function getUserCurrency(Request $request) { // Check request for currency $currency = $request->get('currency'); if ($currency && currency()->isActive($currency) === TRUE) { return $currency; } //
php
{ "resource": "" }
q260505
Coordinates.isEqual
test
public function isEqual(CoordinatesInterface $coordinate) { return bccomp($this->latitude, $coordinate->getLatitude(), $this->getPrecision())
php
{ "resource": "" }
q260506
EloquentBlock.render
test
public function render($name = null) { $args = func_get_args(); $args[] = config('app.locale'); return $this->executeCallback(static::class, __FUNCTION__, $args, function () use ($name) { $block = $this->prepareQuery($this->createModel())
php
{ "resource": "" }
q260507
EventEmitter.bindEvent
test
public function bindEvent($event, $callback, $priority = 0) { $this->emitterEvents[$event][$priority][] = $callback;
php
{ "resource": "" }
q260508
EventEmitter.emitterEventSortEvents
test
protected function emitterEventSortEvents($eventName) { $this->emitterEventSorted[$eventName] = []; if (isset($this->emitterEvents[$eventName])) { krsort($this->emitterEvents[$eventName]);
php
{ "resource": "" }
q260509
EventEmitter.unbindEvent
test
public function unbindEvent($event = null) { // Multiple events if (is_array($event)) { foreach ($event as $_event) { $this->unbindEvent($_event); } return; } if ($event === null) { unset($this->emitterSingleEvents); ...
php
{ "resource": "" }
q260510
EventEmitter.fireEvent
test
public function fireEvent($event, $params = [], $halt = FALSE) { if (!is_array($params)) $params = [$params]; $result = []; // Single events if (isset($this->emitterSingleEvents[$event])) { foreach ($this->emitterSingleEvents[$event] as $callback) { $resp...
php
{ "resource": "" }
q260511
InjectionAwareTrait.getDI
test
public function getDI() { if (!isset($this->_di)) {
php
{ "resource": "" }
q260512
Header.has
test
public function has($name) { return isset($this->headers[$name])
php
{ "resource": "" }
q260513
Header.setHeaders
test
public function setHeaders(array $fields, $merge = false) { if ($merge) { $this->headers =
php
{ "resource": "" }
q260514
Header.build
test
public function build() { $headers = []; foreach ($this->headers as $name => $value) { $headers[]
php
{ "resource": "" }
q260515
Ellipsoid.checkCoordinatesEllipsoid
test
public static function checkCoordinatesEllipsoid(CoordinatesInterface $a, CoordinatesInterface $b) { if ($a->getEllipsoid() != $b->getEllipsoid()) {
php
{ "resource": "" }
q260516
ErrorHandler.getDetailedMessage
test
public static function getDetailedMessage($exception) { $message = $exception->getMessage(); if (!($exception instanceof ApplicationException) && Config::get('app.debug', FALSE)) { $message = sprintf('"%s" on line %s of %s',
php
{ "resource": "" }
q260517
ServerTask.mainAction
test
public function mainAction() { try { $host = $this->getHost(); $port = $this->getPort($host);
php
{ "resource": "" }
q260518
Session.registering
test
public function registering() { $di = $this->getDI(); $di->set(Services::SESSION_BAG, Bag::class); $di->setShared(Services::SESSION, function () { /** @var \Phalcon\DiInterface $this */ $sessionConfig = $this->getShared(Services::CONFIG)->session; if (...
php
{ "resource": "" }
q260519
WorkingTime.toDateTime
test
public function toDateTime(DateTime $date = null): DateTime { if (!$date) { $date = new DateTime('1970-01-01 00:00:00');
php
{ "resource": "" }
q260520
Preloader.prepareOutput
test
public function prepareOutput($file, $strict = false) { if ($strict && PHP_VERSION_ID < 70000) { throw new RuntimeException('Strict mode requires PHP 7 or greater.'); } $dir = dirname($file); if (!is_dir($dir) && !mkdir($dir, 0777, true)) {
php
{ "resource": "" }
q260521
Preloader.getCode
test
public function getCode($file) { $stmts = $this->parse($file);
php
{ "resource": "" }
q260522
Preloader.parse
test
public function parse($file) { if (!is_string($file) || empty($file)) { throw new RuntimeException('Invalid filename provided.'); } if (!is_readable($file)) { throw new RuntimeException("Cannot open
php
{ "resource": "" }
q260523
Database.registering
test
public function registering() { $di = $this->getDI(); $database = (array)$di->getShared(Services::CONFIG)->database; $connections = (array)$database['connections']; if (count($connections) > 1) { $di->setShared(Services::DB, DatabaseStrategy::class); foreac...
php
{ "resource": "" }
q260524
Builder.getNodeData
test
public function getNodeData($id, $required = FALSE) { $query = $this->toBase(); $query->where($this->model->getKeyName(), '=', $id);
php
{ "resource": "" }
q260525
Builder.whereAncestorOf
test
public function whereAncestorOf($id, $andSelf = FALSE, $boolean = 'and') { $keyName = $this->model->getKeyName(); if (NestedSet::isNode($id)) { $value = '?'; $this->query->addBinding($id->getRgt()); $id = $id->getKey(); } else { $val...
php
{ "resource": "" }
q260526
Builder.whereNodeBetween
test
public function whereNodeBetween($values, $boolean = 'and', $not = FALSE) {
php
{ "resource": "" }
q260527
Builder.whereDescendantOf
test
public function whereDescendantOf($id, $boolean = 'and', $not = FALSE, $andSelf = FALSE ) { if (NestedSet::isNode($id)) { $data = $id->getBounds(); } else {
php
{ "resource": "" }
q260528
Builder.descendantsOf
test
public function descendantsOf($id, array $columns = ['*'], $andSelf = FALSE) { try { return $this->whereDescendantOf($id, 'and', FALSE, $andSelf)->get($columns);
php
{ "resource": "" }
q260529
Builder.withDepth
test
public function withDepth($as = 'depth') { if ($this->query->columns === null) $this->query->columns = ['*']; $table = $this->wrappedTable(); list($lft, $rgt) = $this->wrappedColumns(); $alias = '_d'; $wrappedAlias = $this->query->getGrammar()->wrapTable($alias);
php
{ "resource": "" }
q260530
Builder.wrappedColumns
test
protected function wrappedColumns() { $grammar = $this->query->getGrammar(); return [ $grammar->wrap($this->model->getLftName()),
php
{ "resource": "" }
q260531
Builder.hasChildren
test
public function hasChildren() { list($lft, $rgt) = $this->wrappedColumns();
php
{ "resource": "" }
q260532
Builder.defaultOrder
test
public function defaultOrder($dir = 'asc') { $this->query->orders = null;
php
{ "resource": "" }
q260533
Builder.moveNode
test
public function moveNode($key, $position) { list($lft, $rgt) = $this->model->newNestedSetQuery() ->getPlainNodeData($key, TRUE); if ($lft < $position && $position <= $rgt) { throw new LogicException('Cannot move node into itself.'); } ...
php
{ "resource": "" }
q260534
Builder.makeGap
test
public function makeGap($cut, $height) { $params = compact('cut', 'height'); $query = $this->toBase()->whereNested(function (Query $inner) use ($cut) { $inner->where($this->model->getLftName(), '>=', $cut);
php
{ "resource": "" }
q260535
Builder.patch
test
protected function patch(array $params) { $grammar = $this->query->getGrammar(); $columns = []; foreach ([$this->model->getLftName(),
php
{ "resource": "" }
q260536
Builder.columnPatch
test
protected function columnPatch($col, array $params) { extract($params); /** @var int $height */ if ($height > 0) $height = '+'.$height; if (isset($cut)) { return new Expression("case when {$col} >= {$cut} then {$col}{$height} else {$col} end"); } /** @v...
php
{ "resource": "" }
q260537
Builder.countErrors
test
public function countErrors() { $checks = []; // Check if lft and rgt values are ok $checks['oddness'] = $this->getOdnessQuery(); // Check if lft and rgt values are unique $checks['duplicates'] = $this->getDuplicatesQuery(); // Check if parent_id is set correctly ...
php
{ "resource": "" }
q260538
Builder.fixTree
test
public function fixTree() { $columns = [ $this->model->getKeyName(), $this->model->getParentIdName(), $this->model->getLftName(), $this->model->getRgtName(), ]; $dictionary = $this->model->newNestedSetQuery() ...
php
{ "resource": "" }
q260539
Builder.rebuildTree
test
public function rebuildTree(array $data, $delete = FALSE) { if ($this->model->usesSoftDelete()) { $this->withTrashed(); } $existing = $this->get()->getDictionary(); $dictionary = []; $this->buildRebuildDictionary($dictionary, $data, $existing); if (!emp...
php
{ "resource": "" }
q260540
Purgeable.bootPurgeable
test
public static function bootPurgeable() { if (!property_exists(get_called_class(), 'purgeable')) throw new Exception(sprintf( 'You must define a $purgeable property in %s to use the Purgeable trait.', get_called_class() )); /* * Remove
php
{ "resource": "" }
q260541
Purgeable.addPurgeable
test
public function addPurgeable($attributes = null) { $attributes = is_array($attributes) ?
php
{ "resource": "" }
q260542
Purgeable.purgeAttributes
test
public function purgeAttributes($attributesToPurge = null) { if ($attributesToPurge !== null) { $purgeable = is_array($attributesToPurge) ? $attributesToPurge : [$attributesToPurge]; } else { $purgeable = $this->getPurgeableAttributes(); } $attributes...
php
{ "resource": "" }
q260543
Purgeable.getOriginalPurgeValue
test
public function getOriginalPurgeValue($attribute) { return isset($this->originalPurgeableValues[$attribute])
php
{ "resource": "" }
q260544
SettingStore.get
test
public function get($key, $default = null) { $this->load();
php
{ "resource": "" }
q260545
SettingStore.set
test
public function set($key, $value = null) { $this->load(); $this->unsaved = TRUE; if (is_array($key)) { foreach ($key as $k => $v) { Arr::set($this->items, $k, $v);
php
{ "resource": "" }
q260546
SettingStore.forget
test
public function forget($key) { $this->unsaved = TRUE; if ($this->has($key)) {
php
{ "resource": "" }
q260547
SettingStore.save
test
public function save() { if (!$this->unsaved) { // either nothing has been changed, or data has not
php
{ "resource": "" }
q260548
SettingStore.load
test
public function load($force = FALSE) { if (!$this->loaded ||
php
{ "resource": "" }
q260549
StrExtension.compileFunction
test
public function compileFunction($name, $arguments, $funcArguments) { if (!Str::startsWith($name, 'str_') || function_exists($name)) { return null; } $name = substr($name, 4);
php
{ "resource": "" }
q260550
OptimizeTask.mainAction
test
public function mainAction() { if (APP_DEBUG && !$this->hasOption('f', 'force')) { $this->info('Application is in debug mode.'); $this->info('For optimize in debug please use the --force, -f option.'); return; } $this->optimizer = $this->getDI()->get(Com...
php
{ "resource": "" }
q260551
Throttle.after
test
public function after(Event $event, $source, $data = null) {
php
{ "resource": "" }
q260552
Throttle.addHeader
test
protected function addHeader($signature, $tooManyAttempts = false) { /** @var \Phalcon\Http\Response $response */ $response = $this->getDI()->getShared(Services::RESPONSE); $limiter = $this->getLimiter(); $response->setHeader('X-RateLimit-Limit', $this->max); if ($tooManyAt...
php
{ "resource": "" }
q260553
Throttle.getLimiter
test
protected function getLimiter() { if (!isset($this->limiter)) {
php
{ "resource": "" }
q260554
Message.update
test
public function update($attributes = []) { $attributes = array_filter($attributes); foreach ($attributes as $key => $attribute) {
php
{ "resource": "" }
q260555
DatabaseMigrationRepository.log
test
public function log($file, $batch) { $record = ['migration'
php
{ "resource": "" }
q260556
DatabaseMigrationRepository.createRepository
test
public function createRepository() { $schema = $this->getConnection()->getSchemaBuilder(); $method = (!$schema->hasTable($this->table)) ? 'create' : 'table'; $schema->$method($this->table, function (Blueprint $table) use ($method) { // Drop old columns from CI_Migra...
php
{ "resource": "" }
q260557
DatabaseMigrationRepository.table
test
protected function table() { return $this->getConnection() ->table($this->table)
php
{ "resource": "" }
q260558
NetteDatabaseHandler.getDatabaseName
test
public function getDatabaseName() { $dsn = $this->result->connection->getDsn(); $matches = [];
php
{ "resource": "" }
q260559
HtmlElementAbstract.setAttribute
test
public function setAttribute($key, $value = null) { if (is_null($value)) { $this->getAttributeMap()->remove($key); } else {
php
{ "resource": "" }
q260560
HtmlElementAbstract.appendAttribute
test
public function appendAttribute($key, $value = null, $seperater = null) { if (!is_null($value)) { if ($this->getAttributeMap()->hasKey($key)) { if (strlen($seperater) > 0) { $values = array(); $values[] = $this->getAttributeMap()->get($key)...
php
{ "resource": "" }
q260561
HtmlElementAbstract.setContent
test
public function setContent($content) { if (!is_null($content)) { if ($content instanceof HtmlElementInterface) { $htmlElementObject = $content; } else { $htmlElementObject = new HtmlElementContent($content);
php
{ "resource": "" }
q260562
HtmlElementAbstract.addContent
test
public function addContent($content = null) { if (!is_null($content)) { $htmlElementObject =
php
{ "resource": "" }
q260563
ScaffoldServiceProvider.registerCommands
test
protected function registerCommands(array $commands) { foreach ($commands as $class =>
php
{ "resource": "" }
q260564
RouteCacheTask.mainAction
test
public function mainAction() { $this->output->write(Decorate::notice(str_pad('Generating http-routes cache', 40, ' ')), false); try { $router = $this->loadHttpRouter(); $str = $this->compile($router); file_put_contents(BASE_PATH . '/bootstrap/compile/http-route...
php
{ "resource": "" }
q260565
Db.getQueries
test
public static function getQueries(\Closure $callback, $pretend = false) { $db = Di::getDefault()->get(Services::DB); if (is_null($em = $db->getEventsManager())) { $db->setEventsManager($em = new Manager()); } $queries = []; $listener = function (Event $event,
php
{ "resource": "" }
q260566
RateLimiter.tooManyAttempts
test
public function tooManyAttempts($key, $maxAttempts, $decaySeconds = 1) { /** @var \Neutrino\Cache\CacheStrategy $cache */ $cache = $this->{Services::CACHE}; if ($cache->exists($this->name . $key . $this->klock, $decaySeconds)) { return true; } if ($this->attempts...
php
{ "resource": "" }
q260567
RateLimiter.hit
test
public function hit($key, $decaySeconds = 1) { $key = $this->name . $key; /** @var \Neutrino\Cache\CacheStrategy $cache */ $cache = $this->{Services::CACHE}; if (!$cache->exists($key, $decaySeconds)) { $cache->save($key, 0, $decaySeconds);
php
{ "resource": "" }
q260568
RateLimiter.attempts
test
public function attempts($key, $decaySeconds = 1) { $value = $this->{Services::CACHE}->get($this->name . $key,
php
{ "resource": "" }
q260569
RateLimiter.clear
test
public function clear($key) { $this->resetAttempts($key);
php
{ "resource": "" }
q260570
RateLimiter.availableIn
test
public function availableIn($key, $decaySeconds) { $time = $this->{Services::CACHE}->get($this->name
php
{ "resource": "" }
q260571
DotconstCacheTask.mainAction
test
public function mainAction() { $this->output->write(Decorate::notice(str_pad('Generating dotconst cache', 40, ' ')), false); try { self::generateCache(); $this->info("Success");
php
{ "resource": "" }
q260572
FilesystemServiceProvider.registerNativeFilesystem
test
protected function registerNativeFilesystem() { $this->app->singleton('files', function () { $config = $this->app['config']; $files = new Filesystem; $files->filePermissions = $config->get('system.filePermissions', null); $files->folderPermissions = $config->g...
php
{ "resource": "" }
q260573
Facade.swap
test
public static function swap($instance) { self::$resolvedInstance[static::getFacadeAccessor()] = $instance;
php
{ "resource": "" }
q260574
Facade.shouldReceive
test
public static function shouldReceive(...$params) { $name = static::getFacadeAccessor(); if (static::isMock()) { $mock = self::$resolvedInstance[$name]; } else {
php
{ "resource": "" }
q260575
Facade.createFreshMockInstance
test
protected static function createFreshMockInstance() { $name = static::getFacadeAccessor(); self::$resolvedInstance[$name] = $mock = static::createMockInstance(); $mock->shouldAllowMockingProtectedMethods();
php
{ "resource": "" }
q260576
Facade.isMock
test
protected static function isMock() { $name = static::getFacadeAccessor();
php
{ "resource": "" }
q260577
Facade.resolveFacadeInstance
test
protected static function resolveFacadeInstance($name) { if (is_object($name)) { return $name; } if (isset(self::$resolvedInstance[$name])) {
php
{ "resource": "" }
q260578
Processor.processSelect
test
public function processSelect(Finder $finder, $result) { if ($result === null) { return null; }
php
{ "resource": "" }
q260579
Processor.processSelectAll
test
public function processSelectAll(Finder $finder, $results) { if (!count($results)) { return []; } $items = []; foreach ($results as $result) { $fileName = array_get($result, 'fileName');
php
{ "resource": "" }
q260580
Processor.parseTemplateContent
test
protected function parseTemplateContent($result, $fileName) { $content = array_get($result, 'content'); $processed = FileParser::parse($content); $content = [ 'fileName' => $fileName,
php
{ "resource": "" }
q260581
Processor.processUpdate
test
public function processUpdate(Finder $finder, $data) { $existingData = $finder->getModel()->attributesToArray();
php
{ "resource": "" }
q260582
Listener.attach
test
public function attach() { $em = $this->getEventsManager(); if (!empty($this->space)) { foreach ($this->space as $space) { $em->attach($space, $this); } } if (!empty($this->listen)) { foreach ($this->listen as $event => $callback)...
php
{ "resource": "" }
q260583
Listener.detach
test
public function detach() { $em = $this->getEventsManager(); if (!empty($this->space)) { foreach ($this->space as $space) { $em->detach($space, $this); }
php
{ "resource": "" }
q260584
NominatimProvider.geocodeQuery
test
public function geocodeQuery(GeoQueryInterface $query): Collection { $url = sprintf( array_get($this->config, 'endpoints.geocode'), urlencode($query->getText()), $query->getLimit() ); $result = []; try { $result = $this->cacheCallback(...
php
{ "resource": "" }
q260585
NominatimProvider.reverseQuery
test
public function reverseQuery(GeoQueryInterface $query): Collection { $coordinates = $query->getCoordinates(); $url = sprintf( array_get($this->config, 'endpoints.reverse'), $coordinates->getLatitude(), $coordinates->getLongitude(), $query->getData('zo...
php
{ "resource": "" }
q260586
StatusTask.getStatusFor
test
protected function getStatusFor(array $ran) { return array_map(function ($migration) use ($ran) { $migrationName = $this->migrator->getMigrationName($migration); return [ 'Ran?' => in_array($migrationName, $ran) ? Decorate::info('Y') ...
php
{ "resource": "" }
q260587
RouteListTask.mainAction
test
public function mainAction() { $infos = $this->getHttpRoutesInfos(); $datas = []; foreach ($infos['routes'] as $route) { /** @var \Phalcon\Mvc\Router\Route $route */ $paths = $route->getPaths(); if (!$this->hasOption('no-substitution')) { ...
php
{ "resource": "" }
q260588
RouteListTask.getHttpRoutesInfos
test
protected function getHttpRoutesInfos() { Router::clearResolvedInstances(); $cliRouter = $this->router; $cliDispatcher = $this->dispatcher; $this->di->remove(Services::ROUTER); $this->di->remove(Services::DISPATCHER); $httpRouterProvider = new \Neutrino\Providers\H...
php
{ "resource": "" }
q260589
Curl.curlOptions
test
protected function curlOptions($ch) { $method = $this->method; if ($method === Method::HEAD) { curl_setopt($ch, CURLOPT_NOBODY, true); } // Default Options curl_setopt_array($ch, [ CURLOPT_URL => $this->uri->build(), ...
php
{ "resource": "" }
q260590
Curl.curlInfos
test
protected function curlInfos($ch) { $this->response->setCode(curl_getinfo($ch, CURLINFO_HTTP_CODE)); if (($errno = curl_errno($ch)) !== 0) { $this->response->setErrorCode(curl_errno($ch));
php
{ "resource": "" }
q260591
Compile.compile
test
public static function compile($basePath, $compilePath) { $extensions = Dotconst::getExtensions(); $raw = Loader::loadRaw($basePath); $config = Loader::fromFiles($basePath); $r = fopen($compilePath . '/consts.php', 'w'); if ($r === false) { throw new InvalidFi...
php
{ "resource": "" }
q260592
Process.start
test
public function start() { $this->spec = [ // 0 => ['pipe', 'w+'], 1 => fopen('php://temp/maxmemory:' . (1024 * 1024), 'w+'), 2 => fopen('php://temp/maxmemory:' . (1024 * 1024), 'w+'), ]; if ('\\' === DIRECTORY_SEPARATOR) { $this->options = array_m...
php
{ "resource": "" }
q260593
Process.wait
test
public function wait($timeout = null, $step = 1000) { $withTimeout = false === is_null($timeout); if ($withTimeout) { $start = microtime(true); if ($timeout < $step)
php
{ "resource": "" }
q260594
Process.stop
test
public function stop($timeout = 1000) { $timeout = microtime(true) + ($timeout * 1000); if ($this->isRunning()) { proc_terminate($this->proc);
php
{ "resource": "" }
q260595
Process.close
test
public function close() { $this->stop(0); if (is_resource($this->proc)) { proc_close($this->proc);
php
{ "resource": "" }
q260596
Process.exec
test
public function exec($timeout = null) { try { $this->start(); $this->wait($timeout, 500);
php
{ "resource": "" }
q260597
Composer.optimizeMemory
test
public function optimizeMemory() { $this->composer->dumpautoload(false); $files = $this->autoload->getFiles(); $namespaces = $this->autoload->getNamespaces(); $psr = $this->autoload->getPsr4(); $classes = $this->autoload->getClassmap(); $_namespaces =...
php
{ "resource": "" }
q260598
Composer.generateOutput
test
protected function generateOutput($files = null, $namespaces = null, $directories = null, $classmap = null) { $res = fopen($this->loaderFilePath, 'w'); if ($res == false) { return false; } fwrite($res, '<?php' . "\n"); if (isset($this->basePath)) { ...
php
{ "resource": "" }
q260599
Obj.fill
test
public static function fill(&$target, $key, $value) {
php
{ "resource": "" }