_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q264300
EntityModifierByCurrentAction.modifyByNewsletterController
test
protected function modifyByNewsletterController() { /** @var \OxidEsales\Eshop\Application\Controller\NewsletterController $currentController */ $currentController = Registry::getConfig()->getActiveView(); if ($currentController->getNewsletterStatus()) { $this->activePageEntity->setNewsletterMessage('Newsletter registriert'); } }
php
{ "resource": "" }
q264301
EntityModifierByCurrentAction.modifyWithUserRegistrationAction
test
protected function modifyWithUserRegistrationAction($user) { $errorCode = Registry::getRequest()->getRequestEscapedParameter('newslettererror'); $successCode = Registry::getRequest()->getRequestEscapedParameter('success'); if ($errorCode && $errorCode < 0) { $this->activePageEntity->setRegisteredUserId($user ? md5($user->getId()) : 'NULL'); $this->activePageEntity->setRegisteredUserResult(abs($errorCode)); } if ($successCode && $successCode > 0 && $user) { $this->activePageEntity->setRegisteredUserId(md5($user->getId())); $this->activePageEntity->setRegisteredUserResult(0); $this->activePageEntity->setLoginUserId($this->activeUserDataProvider->getActiveUserHashedId()); $this->activePageEntity->setLoginResult($this->activeUserDataProvider->isLoaded() ? 0 : 1); } }
php
{ "resource": "" }
q264302
EventsTrait.disableEventSubscriber
test
public function disableEventSubscriber($subscriberClass) { $subscriberClass = $this->getSubscriberClassName($subscriberClass); $eventManager = $this->getEventManager(); /* @var EventSubscriber[] $subscribers */ foreach ($this->getEventListeners() as $subscribers) { while ($subscriber = \array_shift($subscribers)) { if ($subscriber instanceof $subscriberClass) { $this->disabledSubscribers[] = $subscriber; $eventManager->removeEventSubscriber($subscriber); return; } } } }
php
{ "resource": "" }
q264303
EventsTrait.restoreEventSubscribers
test
public function restoreEventSubscribers() { $eventManager = $this->getEventManager(); foreach ($this->disabledSubscribers as $subscriber) { $eventManager->addEventSubscriber($subscriber); } $this->disabledSubscribers = []; }
php
{ "resource": "" }
q264304
EventsTrait.disableEventListeners
test
public function disableEventListeners(string $event) { $eventManager = $this->getEventManager(); if (!\array_key_exists($event, $this->disabledListeners)) { $this->disabledListeners[$event] = []; } foreach ($this->getEventListeners($event) as $listener) { $eventManager->removeEventListener($event, $listener); $this->disabledListeners[$event][] = $listener; } }
php
{ "resource": "" }
q264305
EventsTrait.disableEventListener
test
public function disableEventListener(string $event, $subscriberClass) { $subscriberClass = $this->getSubscriberClassName($subscriberClass); if (!\array_key_exists($event, $this->disabledListeners)) { $this->disabledListeners[$event] = []; } $eventManager = $this->getEventManager(); foreach ($this->getEventListeners($event) as $listener) { if ($listener instanceof $subscriberClass) { $this->disabledListeners[$event][] = $listener; $eventManager->removeEventListener($event, $listener); break; } } }
php
{ "resource": "" }
q264306
EventsTrait.restoreAllEventListeners
test
public function restoreAllEventListeners() { $eventManager = $this->getEventManager(); foreach ($this->disabledListeners as $event => $listeners) { /* @var EventSubscriber[] $listeners */ foreach ($listeners as $listener) { $eventManager->addEventListener($event, $listener); } $this->disabledListeners[$event] = []; } }
php
{ "resource": "" }
q264307
EventsTrait.restoreEventListeners
test
public function restoreEventListeners(string $event) { if (!\array_key_exists($event, $this->disabledListeners) || empty($this->disabledListeners[$event])) { return; } $eventManager = $this->getEventManager(); /* @var EventSubscriber[] $listeners */ $listeners = $this->disabledListeners[$event]; foreach ($listeners as $listener) { $eventManager->addEventListener($event, $listener); } $this->disabledListeners[$event] = []; }
php
{ "resource": "" }
q264308
EventsTrait.getSubscriberClassName
test
protected function getSubscriberClassName($subscriberClass): string { if ($this->isEventSubscriber($subscriberClass)) { return \is_object($subscriberClass) ? \get_class($subscriberClass) : $subscriberClass; } throw new \InvalidArgumentException('subscriberClass must be an EventSubscriber'); }
php
{ "resource": "" }
q264309
EventsTrait.isEventSubscriber
test
private function isEventSubscriber($subscriberClass): bool { return \is_object($subscriberClass) || (\is_string($subscriberClass) && \class_exists($subscriberClass)) ? \in_array(EventSubscriber::class, \class_implements($subscriberClass), true) : false; }
php
{ "resource": "" }
q264310
EventsTrait.getEventListeners
test
protected function getEventListeners($event = null): array { $eventManager = $this->getEventManager(); return $event !== null && !$eventManager->hasListeners($event) ? [] : $eventManager->getListeners($event); }
php
{ "resource": "" }
q264311
ActiveUserDataProvider.getActiveUserHashedId
test
public function getActiveUserHashedId() { $id = null; if ($this->isLoaded()) { $id = md5($this->user->oxuser__oxid->value); } return $id; }
php
{ "resource": "" }
q264312
ActiveUserDataProvider.getActiveUserHashedEmail
test
public function getActiveUserHashedEmail() { $email = null; if ($this->isLoaded()) { $email = md5($this->user->oxuser__oxusername->value); } return $email; }
php
{ "resource": "" }
q264313
CacheProvider.generateCacheKey
test
public static function generateCacheKey() { $args = func_get_args(); if (empty($args)) { throw new \InvalidArgumentException('At least one argument must be passed to generate cache key.'); } $const = $args[0] . '::VERSION'; $version = defined($const) ? self::$delimiter . constant($const) : ''; return self::$prefix . self::$delimiter . implode(self::$delimiter, $args) . $version; }
php
{ "resource": "" }
q264314
CacheProvider.generateCacheKeys
test
public static function generateCacheKeys() { $args = func_get_args(); if (empty($args)) { throw new \InvalidArgumentException('At least one argument must be passed to generate cache key.'); } $ids = array_pop($args); if (!is_array($ids)) { throw new \InvalidArgumentException('The last parameter must be an array.'); } $commonKey = call_user_func_array(['self', 'generateCacheKey'], $args); $result = []; foreach ($ids as $id) { $result[] = $commonKey . self::$delimiter . $id; } return $result; }
php
{ "resource": "" }
q264315
GetRequest.send
test
public function send() { $cc = curl_init($this->url); $this->logger->log("API connection established"); curl_setopt($cc, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $this->apiKey, 'Content-type: application/json')); curl_setopt($cc, CURLOPT_RETURNTRANSFER, true); curl_setopt($cc, CURLOPT_VERBOSE, 0); curl_setopt($cc, CURLOPT_HEADER, 1); // Execute the cURL, fetch the XML $result = curl_exec($cc); $this->result = $result; $this->headerSize = curl_getinfo($cc, CURLINFO_HEADER_SIZE); // Close connection curl_close($cc); }
php
{ "resource": "" }
q264316
DotKey.exists
test
public function exists($key) { $index = explode('.', $key); self::getValue($this->item, $index, false, $err); return !$err; }
php
{ "resource": "" }
q264317
DotKey.get
test
public function get($key) { $index = explode('.', $key); $ret = self::getValue($this->item, $index, true, $err); if ($err) { $invalidPath = join('.', array_slice($index, 0, -1 * $err->incomplete)); trigger_error("Unable to get '$key': '$invalidPath' is a {$err->var}", E_USER_WARNING); } // @codeCoverageIgnore return $ret; }
php
{ "resource": "" }
q264318
DotKey.getValue
test
protected static function getValue($item, $index, $ignore = false, &$err = null) { $err = null; if (empty($index)) return $item; $key = array_shift($index); if ((is_array($item) || $item instanceof \Traversable) && isset($item[$key])) { return static::getValue($item[$key], $index, $ignore, $err); } if (is_object($item) && isset($item->$key)) { return static::getValue($item->$key, $index, $ignore, $err); } if ((!is_object($item) && !is_array($item)) || !$ignore) { $err = (object)['var' => isset($item) ? gettype($item) : null, 'incomplete' => count($index) + 1]; } return null; }
php
{ "resource": "" }
q264319
DotKey.set
test
public function set($key, $value) { $index = explode('.', $key); self::setValue($this->item, $index, $value, false, $err); if ($err) { $invalidPath = join('.', array_slice($index, 0, -1 * $err->incomplete)); $reason = isset($err->var) ? "'$invalidPath' is a {$err->var}" : "'$invalidPath' doesn't exist"; trigger_error("Unable to set '$key': $reason", E_USER_WARNING); } // @codeCoverageIgnore return $this->item; }
php
{ "resource": "" }
q264320
DotKey.put
test
public function put($key, $value) { $index = explode('.', $key); $err = null; self::setValue($this->item, $index, $value, $this->assoc ? 'array' : 'object', $err); if ($err) { $invalidPath = join('.', array_slice($index, 0, -1 * $err->incomplete)); trigger_error("Unable to put '$key': '$invalidPath' is a {$err->var}", E_USER_WARNING); } // @codeCoverageIgnore return $this->item; }
php
{ "resource": "" }
q264321
DotKey.setValue
test
protected static function setValue(&$item, $index, $value, $create = false, &$err = null) { $err = null; $key = array_shift($index); if (is_array($item) || $item instanceof \Traversable) { if (empty($index)) { $item[$key] = $value; return; } if (!isset($item[$key]) && $create) { $item[$key] = $create === 'array' ? [] : (object)[]; } if (isset($item[$key])) { return static::setValue($item[$key], $index, $value, $create, $err); } } elseif (is_object($item)) { if (empty($index)) { $item->$key = $value; return; } if (!isset($item->$key) && $create) { $item->$key = $create === 'array' ? [] : (object)[]; } if (isset($item->$key)) { return static::setValue($item->$key, $index, $value, $create, $err); } } else { $err = (object)['var' => gettype($item), 'incomplete' => count($index) + 1]; return; } $err = (object)['var' => null, 'incomplete' => count($index)]; }
php
{ "resource": "" }
q264322
DotKey.remove
test
public function remove($key) { $index = explode('.', $key); self::removeValue($this->item, $index, $err); if ($err) { $invalidPath = join('.', array_slice($index, 0, -1 * $err->incomplete)); trigger_error("Unable to remove '$key': '$invalidPath' is a {$err->var}", E_USER_WARNING); } // @codeCoverageIgnore return $this->item; }
php
{ "resource": "" }
q264323
DotKey.removeValue
test
protected static function removeValue(&$item, $index, &$err = null) { $err = null; if (!is_object($item) && !is_array($item)) { $err = (object)['var' => gettype($item), 'incomplete' => count($index)]; return; } $key = array_shift($index); if (empty($index)) { if (is_object($item) && isset($item->$key)) unset($item->$key); if (is_array($item) && isset($item[$key])) unset($item[$key]); return; } if (is_object($item) && isset($item->$key)) return static::removeValue($item->$key, $index, $err); if (is_array($item) && isset($item[$key])) return static::removeValue($item[$key], $index, $err); }
php
{ "resource": "" }
q264324
Connector.setLogger
test
public function setLogger($loggerClass, $loggerFunc) { if(empty($loggerClass)) { $this->helper->setLogger($loggerFunc); } else { $this->helper->setLogger(array($loggerClass, $loggerFunc)); } }
php
{ "resource": "" }
q264325
SettingServiceProvider.boot
test
public function boot() { $this->registerTranslations(); $this->registerConfig(); $this->registerViews(); $this->registerFactories(); $this->setMailConfig(); }
php
{ "resource": "" }
q264326
SettingServiceProvider.setMailConfig
test
private function setMailConfig() { try { config([ 'mail.host' => setting()->get('mail.mail_host', ''), 'mail.port' => setting()->get('mail.mail_port', '2525'), 'mail.username' => setting()->get('mail.mail_user', ''), 'mail.password' => setting()->get('mail.mail_password', ''), 'mail.from.address' => setting()->get('mail.mail_from_address', ''), 'mail.from.name' => setting()->get('mail.mail_from_name', '') ]); } catch (\Exception $e) {} }
php
{ "resource": "" }
q264327
ParcelshopConfig.get
test
public function get($key) { if (!isset($this->setFields[$key])) return null; return $this->setFields[$key]; }
php
{ "resource": "" }
q264328
ArrayFixtureGenerator.convertValue
test
protected function convertValue($value) { if (!is_array($value)) { return $value; } $result = 'array('; $values = array(); foreach ($value as $key => $val) { $values[] .= sprintf("'%s' => %s", $key, $this->convertValue($val)); } $result .= implode(",", $values); $result .= ')'; return $result; }
php
{ "resource": "" }
q264329
ApiController.getPageSize
test
public function getPageSize(Request $request): int { $pageSize = $request->get('pageSize', 50); if ($pageSize > 5000) { return 5000; } return (int) $pageSize; }
php
{ "resource": "" }
q264330
CapsuleServiceProvider.register
test
public function register(Application $app) { $app['capsule.connection_defaults'] = array( 'driver' => 'mysql', 'host' => 'localhost', 'database' => null, 'username' => 'root', 'password' => null, 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => null, 'logging' => false, ); $app['capsule.global'] = true; $app['capsule.eloquent'] = true; $app['capsule.container'] = $app->share(function() { return new Container; }); $app['capsule.dispatcher'] = $app->share(function() use($app) { return new Dispatcher($app['capsule.container']); }); if (class_exists('Illuminate\Cache\CacheManager')) { $app['capsule.cache_manager'] = $app->share(function() use($app) { return new CacheManager($app['capsule.container']); }); } $app['capsule'] = $app->share(function($name) use ($app) { $capsule = new Capsule($app['capsule.container']); $capsule->setEventDispatcher($app['capsule.dispatcher']); if (isset($app['capsule.cache_manager']) && isset($app['capsule.cache'])) { $capsule->setCacheManager($app['capsule.cache_manager']); foreach ($app['capsule.cache'] as $key => $value) { $app['capsule.container']->offsetGet('config')->offsetSet('cache.' . $key, $value); } } if ($app['capsule.global']) { $capsule->setAsGlobal(); } if ($app['capsule.eloquent']) { $capsule->bootEloquent(); } if (! isset($app['capsule.connections'])) { $app['capsule.connections'] = array( 'default' => (isset($app['capsule.connection']) ? $app['capsule.connection'] : array()), ); } foreach ($app['capsule.connections'] as $connection => $options) { $options = array_replace($app['capsule.connection_defaults'], $options); $logging = $options['logging']; unset($options['logging']); $capsule->addConnection($options, $connection); if ($logging) { $capsule->connection($connection)->enableQueryLog(); } else { $capsule->connection($connection)->disableQueryLog(); } } return $capsule; }); }
php
{ "resource": "" }
q264331
Config.validate
test
public function validate() { $resultingData = array_merge($this->defaultFields, $this->setFields); return $this->_arrayKeysExists($this->requiredFields, $resultingData); }
php
{ "resource": "" }
q264332
WP_Notice.instance
test
public static function instance() { if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Notice ) ) { self::$instance = new WP_Notice; self::$instance->init(); } return self::$instance; }
php
{ "resource": "" }
q264333
WP_Notice.init
test
private function init() { add_action( 'admin_notices', array( self::$instance, 'display' ) ); add_action( 'admin_print_scripts', array( self::$instance, 'load_script' ) ); add_action( 'wp_ajax_tdp_dismiss_notice', array( self::$instance, 'dismiss_notice_ajax' ) ); }
php
{ "resource": "" }
q264334
WP_Notice.load_script
test
public function load_script() { wp_register_script( 'tdp', trailingslashit( plugin_dir_url( __FILE__ ) ) . 'assets/js/main.js', array( 'jquery' ), self::$instance->version, true ); wp_enqueue_script( 'tdp' ); }
php
{ "resource": "" }
q264335
WP_Notice.display
test
public function display() { if ( is_null( self::$instance->notices ) || empty( self::$instance->notices ) ) { return; } foreach ( self::$instance->notices as $id => $notice ) { $id = self::$instance->get_id( $id ); // Check if the notice was dismissed. if ( self::$instance->is_dismissed( $id ) ) { continue; } if ( ! empty( $notice['cap'] ) && ! current_user_can( $notice['cap'] ) ) { continue; } $class = array( 'notice', 'notice-' . $notice['type'], $notice['dismissible'] ? 'is-dismissible' : false, $notice['class'], ); printf( '<div id="%3$s" class="%1$s"><p>%2$s</p></div>', trim( implode( ' ', $class ) ), $notice['content'], "tdp-$id" ); } }
php
{ "resource": "" }
q264336
WP_Notice.register_notice
test
public function register_notice( $id, $type, $content, $args = array() ) { if ( is_null( self::$instance->notices ) ) { self::$instance->notices = array(); } $id = self::$instance->get_id( $id ); $type = in_array( $t = sanitize_text_field( $type ), self::$instance->get_types() ) ? $t : 'updated'; $content = wp_kses_post( $content ); $args = wp_parse_args( $args, self::$instance->default_args() ); $notice = array( 'type' => $type, 'content' => $content, ); $notice = array_merge( $notice, $args ); self::$instance->notices[ $id ] = $notice; return true; }
php
{ "resource": "" }
q264337
WP_Notice.dismiss_notice_ajax
test
public function dismiss_notice_ajax() { if ( ! isset( $_POST['id'] ) ) { echo 0; exit; } if ( empty( $_POST['id'] ) || false === strpos( $_POST['id'], 'tdp-' ) ) { echo 0; exit; } $id = self::$instance->get_id( str_replace( 'tdp-', '', $_POST['id'] ) ); echo self::$instance->dismiss_notice( $id ); exit; }
php
{ "resource": "" }
q264338
WP_Notice.dismiss_notice
test
public function dismiss_notice( $id ) { $notice = self::$instance->get_notice( self::$instance->get_id( $id ) ); if ( self::$instance->is_dismissed( $id ) ) { return false; } return 'user' === $notice['scope'] ? self::$instance->dismiss_user( $id ) : self::$instance->dismiss_global( $id ); }
php
{ "resource": "" }
q264339
WP_Notice.dismiss_user
test
private function dismiss_user( $id ) { $dismissed = self::$instance->dismissed_user(); if ( in_array( $id, $dismissed ) ) { return false; } array_push( $dismissed, $id ); return update_user_meta( get_current_user_id(), 'tdp_dismissed_notices', $dismissed ); }
php
{ "resource": "" }
q264340
WP_Notice.dismiss_global
test
private function dismiss_global( $id ) { $dismissed = self::$instance->dismissed_global(); if ( in_array( $id, $dismissed ) ) { return false; } array_push( $dismissed, $id ); return update_option( 'tdp_dismissed_notices', $dismissed ); }
php
{ "resource": "" }
q264341
WP_Notice.restore_notice
test
public function restore_notice( $id ) { $id = self::$instance->get_id( $id ); $notice = self::$instance->get_notice( $id ); if ( false === $notice ) { return false; } return 'user' === $notice['scope'] ? self::$instance->restore_user( $id ) : self::$instance->restore_global( $id ); }
php
{ "resource": "" }
q264342
WP_Notice.restore_user
test
private function restore_user( $id ) { $id = self::$instance->get_id( $id ); $notice = self::$instance->get_notice( $id ); if ( false === $notice ) { return false; } $dismissed = self::$instance->dismissed_user(); if ( ! in_array( $id, $dismissed ) ) { return false; } $flip = array_flip( $dismissed ); $key = $flip[ $id ]; unset( $dismissed[ $key ] ); return update_user_meta( get_current_user_id(), 'tdp_dismissed_notices', $dismissed ); }
php
{ "resource": "" }
q264343
WP_Notice.restore_global
test
private function restore_global( $id ) { $id = self::$instance->get_id( $id ); $notice = self::$instance->get_notice( $id ); if ( false === $notice ) { return false; } $dismissed = self::$instance->dismissed_global(); if ( ! in_array( $id, $dismissed ) ) { return false; } $flip = array_flip( $dismissed ); $key = $flip[ $id ]; unset( $dismissed[ $key ] ); return update_option( 'tdp_dismissed_notices', $dismissed ); }
php
{ "resource": "" }
q264344
WP_Notice.dismissed_notices
test
public function dismissed_notices() { $user = self::$instance->dismissed_user(); $global = self::$instance->dismissed_global(); return array_merge( $user, $global ); }
php
{ "resource": "" }
q264345
WP_Notice.is_dismissed
test
public function is_dismissed( $id ) { $dismissed = self::$instance->dismissed_notices(); if ( ! in_array( self::$instance->get_id( $id ), $dismissed ) ) { return false; } return true; }
php
{ "resource": "" }
q264346
WP_Notice.get_notice
test
public function get_notice( $id ) { $id = self::$instance->get_id( $id ); if ( ! is_array( self::$instance->notices ) || ! array_key_exists( $id, self::$instance->notices ) ) { return false; } return self::$instance->notices[ $id ]; }
php
{ "resource": "" }
q264347
Refinery.refineItem
test
public function refineItem($raw) { $refined = $this->setTemplate($raw); if ( ! empty($this->attachments)) { $refined = $this->merge($refined, $this->includeAttachments($raw)); } return $refined; }
php
{ "resource": "" }
q264348
Refinery.refineCollection
test
public function refineCollection($raw, $retainKey = false) { $refined = []; foreach ($raw as $key => $item) { if ($retainKey) { $this->key = $key; $refined[ $key ] = $this->refineItem($item); } else { $refined[] = $this->refineItem($item); } } return $refined; }
php
{ "resource": "" }
q264349
Refinery.includeAttachments
test
protected function includeAttachments($raw) { $attachments = []; foreach ($this->attachments as $attachment => $refinery) { if (isset($refinery['raw'])) { $attachments[$attachment] = $refinery['raw']($raw); } else { $class = $refinery['class']; $callback = $refinery['callback']; if ( ! $callback) { $items = $this->getItems($raw, $class, $attachment); } else { $items = $this->getItemsUsingCallback($raw, $class, $callback); } $attachments[$attachment] = ! is_null($items) ? $class->refine($items) : null; } } return $attachments; }
php
{ "resource": "" }
q264350
Refinery.getItems
test
protected function getItems($raw, $class, $attachment) { if ($class->hasFilter()) { $query = $class->getFilter(); return call_user_func_array($query, [$raw->$attachment()]); } else { return is_object($raw) ? $raw->$attachment : $raw[$attachment]; } }
php
{ "resource": "" }
q264351
Refinery.bring
test
public function bring($attachments) { if (is_string($attachments)) { $attachments = func_get_args(); } $this->attachments = $this->parseAttachments($attachments); return $this; }
php
{ "resource": "" }
q264352
Refinery.parseAttachments
test
protected function parseAttachments(array $relations) { $parsedRelations = []; foreach ($relations as $key => $relation) { if ( ! is_numeric($key)) { if (is_callable($relation)) { $parsedRelations[$key] = $this->attachItem($key); $parsedRelations[$key]['class']->with($this->attributes)->filter($relation); } else { $parsedRelations[$key] = $this->attachItem($key); $parsedRelations[$key]['class']->with($this->attributes)->bring($relation); } } else { $parsedRelations[$relation] = $this->attachItem($relation); if (isset($parsedRelations[$relation]['class'])) { $parsedRelations[$relation]['class']->with($this->attributes); } } } return $parsedRelations; }
php
{ "resource": "" }
q264353
Refinery.attachItem
test
protected function attachItem($attachment) { if ( ! method_exists($this, $attachment)) { throw new RefineryMethodNotFound( "No attachment set with the name '{$attachment}' on '" . get_class($this) . "'." ); } return $this->$attachment(); }
php
{ "resource": "" }
q264354
Refinery.attach
test
public function attach($className, callable $callback = null) { // If the user has passed through a callable item then we want // to attach the raw result of that call. if (is_callable($className)) { return ['raw' => $className]; } if ( ! class_exists($className)) { throw new AttachmentClassNotFound("No class found with the name '{$className}'."); } return ['class' => new $className, 'callback' => $callback]; }
php
{ "resource": "" }
q264355
Refinery.merge
test
protected function merge($original, $merge) { if (is_array($original) && is_array($merge)) { return array_merge($original, $merge); } if (is_array($original)) { foreach ($merge as $key => $value) { $original[$key] = $value; } } else { foreach ($merge as $key => $value) { $original->$key = $value; } } return $original; }
php
{ "resource": "" }
q264356
Request.getResponseHeaders
test
public function getResponseHeaders() { $headers = array(); $header_text = substr($this->result, 0, $this->headerSize); foreach (explode("\r\n", $header_text) as $i => $line) if (strlen($line) > 4 && substr($line, 0, 4) === "HTTP") { $headers['http_code'] = $line; } else { list ($key, $value) = array_pad(explode(': ', $line, 2), 2, null); $headers[$key] = $value; } return $headers; }
php
{ "resource": "" }
q264357
RestResponse.getCardReference
test
public function getCardReference() { if (isset($this->data['response']['token'])) { return $this->data['response']['token']; } if (isset($this->data['response']['card_token'])) { return $this->data['response']['card_token']; } }
php
{ "resource": "" }
q264358
RestResponse.getCustomerReference
test
public function getCustomerReference() { if (isset($this->data['response']['customer'])) { return $this->data['response']['customer']; } if (isset($this->data['response']['id'])) { return $this->data['response']['id']; } }
php
{ "resource": "" }
q264359
ClassUtils.getClassName
test
public static function getClassName($class) { if (!is_object($class) && !is_string($class)) { throw new InvalidArgumentException(sprintf('$object must be a string or an object, %s given', gettype($class))); } $className = is_string($class) ? $class : get_class($class); $pos = strrpos($className, '\\'); if ($pos !== false) { $className = substr($className, ($pos + 1)); } return $className; }
php
{ "resource": "" }
q264360
ClassUtils.getNamespace
test
public static function getNamespace($class) { if (!is_object($class) && !is_string($class)) { throw new InvalidArgumentException('$object must be a string or an object'); } $class = (is_string($class) ? $class : get_class($class)); $pos = strrpos($class, '\\'); return substr($class, 0, $pos); }
php
{ "resource": "" }
q264361
ClassFixtureGenerator.findAdderMethod
test
private function findAdderMethod($obj, $key) { if (method_exists($obj, $method = 'add'.$key)) { return $method; } foreach ((array) StringUtil::singularify($key) as $singularForm) { if (method_exists($obj, $method = 'add'.$singularForm)) { return $method; } } if (method_exists($obj, $method = 'add'.rtrim($key, 's'))) { return $method; } if (substr($key, -3) === 'ies' && method_exists($obj, $method = 'add'.substr($key, 0, -3).'y')) { return $method; } }
php
{ "resource": "" }
q264362
ClassMetadataProxy.initMappings
test
protected function initMappings() { if ($this->initialized) { return $this; } foreach ($this->classMetadata->fieldMappings as $key => $mapping) { if (isset($mapping['reference'])) { $this->associationMappings[$key] = $mapping; } else { $this->fieldMappings[$key] = $mapping; } } $this->initialized = true; return $this; }
php
{ "resource": "" }
q264363
Helper.setTranslationLang
test
public function setTranslationLang($lang) { global $translationData; $translationData = array(); $file = realpath(dirname(dirname(__FILE__)) . "/etc/lang/en-" . strtolower($lang) . ".csv"); if (file_exists($file)) { if (($handle = fopen($file, "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { if (count($data) == 2) { $translationData[$data[0]] = $data[1]; } } fclose($handle); } } }
php
{ "resource": "" }
q264364
AbstractGenerator.readProperty
test
protected function readProperty($object, $property) { foreach ($this->propertyReader as $reader) { /** @var PropertyReaderInterface $reader */ if ($reader->supports($object, $property)) { return $reader->getValue($object, $property); } } $camelProp = ucfirst($property); $getter = 'get'.$camelProp; $isser = 'is'.$camelProp; if (method_exists($object, $getter)) { return $object->$getter(); } elseif (method_exists($object, $isser)) { return $object->$isser(); } elseif (property_exists($object, $property)) { $reflectionProperty = new \ReflectionProperty($object, $property); $reflectionProperty->setAccessible(true); return $reflectionProperty->getValue($object); } throw new InvalidPropertyException(sprintf('Neither property "%s" nor method "%s()" nor method "%s()" exists in class "%s"', $property, $getter, $isser, get_class($object))); }
php
{ "resource": "" }
q264365
EntityManagerController.defaultAction
test
public function defaultAction($name = null, $selfedit = 'false', $installMode = null) { $this->selfedit = $selfedit; $this->installMode = $installMode; $name = $name ? $name : 'entityManager'; $this->instanceName = $name; if ($selfedit == 'true') { $this->moufManager = MoufManager::getMoufManager(); } else { $this->moufManager = MoufManager::getMoufManagerHiddenInstance(); } $classNameMapper = ClassNameMapper::createFromComposerFile(__DIR__.'/../../../../../../composer.json'); $managedNamespaces = $classNameMapper->getManagedNamespaces(); $this->autoloadDetected = true; if ($this->moufManager->instanceExists($name)) { $instance = $this->moufManager->getInstanceDescriptor($name); $this->entitiesNamespace = $instance->getSetterProperty('setEntitiesNamespace')->getValue(); $this->proxyNamespace = $instance->getSetterProperty('setProxyNamespace')->getValue(); $this->daoNamespace = $instance->getSetterProperty('setDaoNamespace')->getValue(); } else { if ($managedNamespaces) { $rootNamespace = $classNameMapper->getManagedNamespaces()[0]; $this->entitiesNamespace = $rootNamespace."Model\\Entities"; $this->proxyNamespace = $rootNamespace."Model\\Proxies"; $this->daoNamespace = $rootNamespace."Model\\DAOs"; } else { $this->autoloadDetected = false; $this->entitiesPath = 'src/path_to_entities'; $this->proxyDir = 'src/path_to_proxies'; $this->proxyNamespace = "YOUR_APP_NAMESPACE\\PATH\\TO\\PROXIES"; } } $this->contentBlock->addFile(__DIR__.'/../views/install.php', $this); $this->template->toHtml(); }
php
{ "resource": "" }
q264366
ModelHook.before
test
final public function before(string $action, Record $record, Record $previous = null): bool { $action = ucfirst($action); $method = "before{$action}"; $container = Container::instance(); if ($container->exists($this, $method)) { return $container->invoke($this, $method, ['record' => $record, 'previous' => $previous]); } return true; }
php
{ "resource": "" }
q264367
ModelHook.after
test
final public function after(string $action, Record $record, $extra = true) { $data = is_array($extra) ? $extra : []; $data = $this->afterDefault($action, $record, $data); $name = ucfirst($action); $method = "after{$name}"; $container = Container::instance(); if ($container->exists($this, $method)) { return $container->invoke($this, $method, ['record' => $record, 'data' => $data]); } if ($action === Action::READ) { return $data; } return $extra; }
php
{ "resource": "" }
q264368
Collection.extend
test
public function extend(Collection $collection) { foreach ($collection as $entity) { $this->append($entity); } return $this; }
php
{ "resource": "" }
q264369
Collection.append
test
public function append($data) { if (is_array($data) || $data instanceof \Traversable) { foreach ($data as $entity) { if (!$entity instanceof Entity) { throw new InvalidArgumentException('Collection can contain only Entities class'); } parent::append($entity); } } else { parent::append($data); } return $this; }
php
{ "resource": "" }
q264370
Collection.prepend
test
public function prepend($entity) { $collection = $this->getNewCollection(); $collection->append($entity); foreach ($this as $entity) { $collection->append($entity); } $this->clear(); $this->append($collection); return $this; }
php
{ "resource": "" }
q264371
Collection.__isset
test
public function __isset($name) { if ($this->count() > 1) { throw new LogicException( 'Collection has more then one element, you cannot get entity property directly' ); } $current = $this->first(); if (!$current) { return false; } return isset($current->$name); }
php
{ "resource": "" }
q264372
Collection.last
test
public function last() { $this->seek($this->count() - 1); $entity = $this->current(); $this->rewind(); return $entity; }
php
{ "resource": "" }
q264373
Collection.getElementMovedByOffset
test
private function getElementMovedByOffset($offset) { if (!is_int($this->key())) { throw new LogicException(sprintf("Can't get element moved by %s as current key is not numeric", $offset)); } $oldPosition = $this->key(); $newPosition = $oldPosition + $offset; $this->seek($newPosition); if (!is_int($this->key())) { throw new LogicException(sprintf("Can't get element moved by %s as next key is not numeric", $offset)); } $value = $this->current(); $this->seek($oldPosition); return $value; }
php
{ "resource": "" }
q264374
Collection.has
test
public function has($field, $value, $strict = false) { return !(false === $this->search($field, $value, $strict)); }
php
{ "resource": "" }
q264375
Collection.search
test
public function search($field, $value, $strict = false) { $value = is_array($value) ? $value : array($value); foreach ($this as $key => $entity) { if (isset($entity->$field) && in_array($entity->$field, $value, $strict)) { return $key; } } return false; }
php
{ "resource": "" }
q264376
Collection.shift
test
public function shift() { $slice = $this->slice(0, 1); $offset = $slice->getKeys(); $this->offsetUnset($offset[0]); return $slice->first(); }
php
{ "resource": "" }
q264377
Collection.filter
test
public function filter(\Closure $callback) { $offsetToRemove = []; foreach ($this as $offset => $entity) { if (!$callback($entity)) { $offsetToRemove[] = $offset; } } $this->offsetUnset($offsetToRemove); return $this; }
php
{ "resource": "" }
q264378
Collection.getBy
test
public function getBy(\Closure $callback) { $instanceCopy = $this->getNewCollection(); foreach ($this as $offset => $entity) { if ($callback($entity)) { $instanceCopy->append($entity); } } return $instanceCopy; }
php
{ "resource": "" }
q264379
Collection.chunk
test
public function chunk($size) { $collection = $this->getNewCollection(); foreach (array_chunk($this->getKeys(), $size) as $chunkIndex => $keys) { $collection[$chunkIndex] = $this->getNewCollection(); foreach ($keys as $key) { $collection[$chunkIndex]->append($this[$key]); } } return $collection; }
php
{ "resource": "" }
q264380
Collection.slice
test
public function slice($offset, $length = null) { $keys = $this->getKeys(); $keys = array_slice($keys, $offset, $length); $collection = $this->getNewCollection(); foreach ($this as $key => $entity) { if (in_array($key, $keys)) { $collection[$key] = $entity; } } return $collection; }
php
{ "resource": "" }
q264381
Collection.split
test
public function split($parts) { $elementsPerChunk = ceil($this->count() / $parts); return $this->chunk($elementsPerChunk); }
php
{ "resource": "" }
q264382
Collection.offsetUnset
test
public function offsetUnset($index) { $index = is_array($index) ? $index : (array)$index; foreach ($index as $key) { parent::offsetUnset($key); } return $this; }
php
{ "resource": "" }
q264383
Collection.distinctOn
test
public function distinctOn($propertyName) { $values = []; $keys = []; foreach ($this as $key => $entity) { if (in_array($entity->$propertyName, $values)) { $keys[] = $key; } else { $values[] = $entity->$propertyName; } } $this->offsetUnset($keys); return $this; }
php
{ "resource": "" }
q264384
Collection.reverse
test
public function reverse() { $positions = array_flip($this->getKeys()); $this->uksort( function ($a, $b) use ($positions) { return ($positions[$a] < $positions[$b] ? 1 : -1); } ); return $this; }
php
{ "resource": "" }
q264385
Collection.getAllValuesForProperty
test
public function getAllValuesForProperty($name) { $values = []; foreach ($this as $entity) { if (isset($entity->$name)) { $value = $entity->$name; if (!($value === null || $value instanceof Collection && $value->isEmpty())) { if (is_scalar($value)) { $values[$value] = $value; } else { $values[] = $value; } } } } return array_values($values); }
php
{ "resource": "" }
q264386
Collection.bindCollection
test
public function bindCollection(Collection $collection, array $compareKeys, $propertyName) { $reflection = new \ReflectionClass($collection); $fromKey = key($compareKeys); $toKey = $compareKeys[$fromKey]; $collection = $collection->groupByField($fromKey); foreach ($this as $entity) { if (!isset($entity->$propertyName)) { $entity->$propertyName = new $reflection->name; } if (!isset($entity->$toKey) || ($value = $entity->$toKey) === null) { continue; //do not try to bind to null or non existing property } if (isset($collection[$value])) { $entity->$propertyName->append($collection[$value]); } } return $this; }
php
{ "resource": "" }
q264387
Collection.groupByField
test
private function groupByField($name) { $collection = $this->getNewCollection(); foreach ($this as $entity) { if (!isset($entity->$name) || $entity->$name === null) { continue; //when entity dosen't have set property it will be omitted } $value = $entity->$name; if (!isset($collection[$value])) { $collection[$value] = $this->getNewCollection(); } $collection[$value]->append($entity); } return $collection; }
php
{ "resource": "" }
q264388
Configurator.prepareScopes
test
public function prepareScopes() { $result = []; foreach ($this->scopes as $key => $scope) { // If no scope configuration has been provided, just make scope's name to be its alias if (!is_array($scope)) { $result[$scope] = ['alias' => $scope]; continue; } $result[$key] = $scope; // If no alias has been provided, make it to be scope's name if (!isset($scope['alias'])) { $result[$key]['alias'] = $key; } } return $result; }
php
{ "resource": "" }
q264389
Configurator.parseScopeArguments
test
public function parseScopeArguments(array $scope) { $scope = new MosaicArray($scope); $result = []; // If "type" key has been provided, we have to typecast the result $type = $scope->getItem('type'); // Get default scope argument value $default = $scope->getItem('default'); // Get request parameter value $value = $this->getInputManager()->get($scope['alias'], null); // If there are no parameters with the scope name: // 1) in a case when no default value is set, return null to ignore this scope // 2) if default value is set, return it if (is_null($value)) { return !is_null($default) ? [$default] : null; } // If "keys" configuration key has been provided, we are dealing with an array parameter (e.g. <input name="somename[somekey]">) $keys = $scope->getItem('keys'); // If "keys" are empty, we have to perform some DRY actions if (is_null($keys)) { $keys = ['default']; $value = ['default' => $value]; } foreach ((array) $keys as $key) { $arg = $this->setType($value[$key], $type); // Empty arguments are not allowed by default in order to allow default scope argument values // Set allowEmpty option to `true` if you want to change this behavior if ($arg !== '' or $scope->getItem('allowEmpty')) { $result[] = $arg; } } return $result; }
php
{ "resource": "" }
q264390
Configurator.setType
test
protected function setType($variable, $type) { // Do nothing if $type is not a string if (is_string($type)) { if (in_array($type, ['bool', 'boolean'])) { // Only 1, '1', true and 'true' values will be converted to boolean true // Any other value will be converted to boolean false $variable = in_array($variable, [1, '1', true, 'true'], true); } else { settype($variable, $type); } } return $variable; }
php
{ "resource": "" }
q264391
DoctrineInstallUtils.registerAnnotationBasedEntities
test
public function registerAnnotationBasedEntities($namespace, $directory) { $mappingDriver = InstallUtils::getOrCreateInstance('mappingDriver.'.$namespace, null, $this->moufManager); $mappingDriver->setCode('return new Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver($container->get(\'annotationReader\'), [ROOT_PATH . "'.$directory.'"]);'); $this->addDriverToChain($namespace, $mappingDriver); }
php
{ "resource": "" }
q264392
PathToNamespaceClassname.convert
test
public function convert($string) { $stringToCamelCase = new StringToCamelCase(); $parts = []; foreach (explode('/', trim($string, '/')) as $part) { $parts[] = ucfirst($stringToCamelCase->convert($part, '-')); } return implode('\\', $parts); }
php
{ "resource": "" }
q264393
Settings.prepareDataForInsert
test
private function prepareDataForInsert($data) { $items = []; foreach ($data as $key => $value) { $items[] = ['key' => $key, 'value' => $value]; } return $items; }
php
{ "resource": "" }
q264394
Settings.updateData
test
private function updateData($data) { $this->data = $data; $cache = Yii::$app->{$this->cache}; $cache->delete($this->cacheName); if (is_array($this->data) && count($this->data)) { $cache->set($this->cacheName, serialize($this->data)); } }
php
{ "resource": "" }
q264395
ModelParser.parseFilterFields
test
protected function parseFilterFields(array $data = []): array { $filters = []; foreach ($data as $name => $value) { if (is_array($value) && $name === '__filter__') { $filters = $this->parseFilterRules($filters, $value); continue; } if (!$this->has($name)) { $class = static::class; $json = JSON::encode($data); throw new SimplesRunTimeError( "There is no property `{$name}` in `{$class}` parsing {$json}" ); } $filters[] = Filter::create($this->get($name), $value); } return $filters; }
php
{ "resource": "" }
q264396
ModelParser.parseFilterValues
test
protected function parseFilterValues(array $filters = []): array { $values = []; foreach ($filters as $filter) { if (is_array($filter)) { $values = array_merge($values, $this->parseFilterValues($filter['filter'])); continue; } /** @var Filter $filter */ $value = $filter->getParsedValue($this->getDriver()); if (!is_array($value)) { $values[] = $value; continue; } $values = array_merge($values, $value); } return $values; }
php
{ "resource": "" }
q264397
ArrayToObject.convert
test
public function convert($data) { if (is_array($data)) { if (!is_numeric(key($data))) { return (object) array_map(__METHOD__, $data); } /** @var stdClass $data */ return $data; } else { /** @var stdClass $data */ return $data; } }
php
{ "resource": "" }
q264398
MenuItem.getLabel
test
public function getLabel() { if ($this->translationService) { return $this->translationService->getTranslation($this->label); } else { return $this->label; } }
php
{ "resource": "" }
q264399
MenuItem.getAdditionalStyleByType
test
public function getAdditionalStyleByType($type) { $return = null; if($this->additionalStyles) { foreach ($this->additionalStyles as $additionalStyle) { if($additionalStyle instanceof $type) { if($return === null) $return = $additionalStyle; else throw new \Exception("MenuItem: There are many instance of $type, please use getAdditionalStylesByType function to get all instance"); } } } return $return; }
php
{ "resource": "" }