_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q237600
Validate.isJson
train
public static function isJson($value): bool { if (!static::isStringCastable($value)) { return false; } if (((string) $value) === 'null') { return true; } return (json_decode((string) $value) !== null && json_last_error() === JSON_ERROR_NONE); }
php
{ "resource": "" }
q237601
Validate.isMatch
train
public static function isMatch($value, string $pattern): bool { if (!static::isStringCastable($value)) { return false; } return !!preg_match($pattern, (string) $value); }
php
{ "resource": "" }
q237602
Validate.contains
train
public static function contains($value, string $search, string $encoding = 'UTF-8'): bool { if (!static::isStringCastable($value)) { return false; } return mb_strpos((string) $value, $search, 0, $encoding) !== false; }
php
{ "resource": "" }
q237603
Validate.startsWith
train
public static function startsWith($value, string $search, string $encoding = 'UTF-8'): bool { if (!static::isStringCastable($value)) { return false; } $searchlen = (int) mb_strlen($search, $encoding); $start = mb_substr((string) $value, 0, $searchlen, $encoding); ...
php
{ "resource": "" }
q237604
Validate.endsWith
train
public static function endsWith($value, string $search, string $encoding = 'UTF-8'): bool { if (!static::isStringCastable($value)) { return false; } $searchlen = (int) mb_strlen($search, $encoding); $length = (int) mb_strlen((string) $value, $encoding); $end = mb...
php
{ "resource": "" }
q237605
Validate.exactLength
train
public static function exactLength($value, int $length, string $encoding = 'UTF-8'): bool { if (!static::isStringCastable($value)) { return false; } $strlen = (int) mb_strlen((string) $value, $encoding); return $strlen === $length; }
php
{ "resource": "" }
q237606
Validate.minLength
train
public static function minLength($value, int $minLength, string $encoding = 'UTF-8'): bool { if (!static::isStringCastable($value)) { return false; } $strlen = (int) mb_strlen((string) $value, $encoding); return $strlen >= $minLength; }
php
{ "resource": "" }
q237607
Validate.rangeLength
train
public static function rangeLength($value, int $minLength, int $maxLength, string $encoding = 'UTF-8'): bool { if (!static::isStringCastable($value)) { return false; } $strlen = (int) mb_strlen((string) $value, $encoding); if ($strlen < $minLength) { return ...
php
{ "resource": "" }
q237608
Validate.rangeNumber
train
public static function rangeNumber($value, $minNumber, $maxNumber): bool { if (!is_numeric($value)) { return false; } if ($value < $minNumber) { return false; } if ($value > $maxNumber) { return false; } return true; }
php
{ "resource": "" }
q237609
Validate.intValue
train
public static function intValue($value): bool { if (!is_numeric($value)) { return false; } return strval(intval($value)) == $value; }
php
{ "resource": "" }
q237610
Validate.exactCount
train
public static function exactCount($value, int $count): bool { if (!static::isCountable($value)) { return false; } return count($value) == $count; }
php
{ "resource": "" }
q237611
Validate.minCount
train
public static function minCount($value, int $minCount): bool { if (!static::isCountable($value)) { return false; } return count($value) >= $minCount; }
php
{ "resource": "" }
q237612
Validate.maxCount
train
public static function maxCount($value, int $maxCount): bool { if (!static::isCountable($value)) { return false; } return count($value) <= $maxCount; }
php
{ "resource": "" }
q237613
Validate.rangeCount
train
public static function rangeCount($value, int $minCount, int $maxCount): bool { if (!static::isCountable($value)) { return false; } $count = count($value); if ($count < $minCount) { return false; } if ($count > $maxCount) { return...
php
{ "resource": "" }
q237614
Validate.isOneOf
train
public static function isOneOf($value, iterable $choices): bool { foreach ($choices as $choice) { if ($value === $choice) { return true; } } return false; }
php
{ "resource": "" }
q237615
Validate.keyIsset
train
public static function keyIsset($value, $key): bool { if (!static::isArrayAccessible($value)) { return false; } return isset($value[$key]); }
php
{ "resource": "" }
q237616
Validate.keyNotEmpty
train
public static function keyNotEmpty($value, $key): bool { if (!static::isArrayAccessible($value)) { return false; } return isset($value[$key]) && !empty($value[$key]); }
php
{ "resource": "" }
q237617
Validate.areEqual
train
public static function areEqual($value1, $value2): bool { if (static::isEquatable($value1) && static::areSameType($value1, $value2)) { return $value1->equals($value2); } return $value1 == $value2; }
php
{ "resource": "" }
q237618
Validate.areNotEqual
train
public static function areNotEqual($value1, $value2): bool { if (static::isEquatable($value1) && static::areSameType($value1, $value2)) { return !$value1->equals($value2); } return $value1 != $value2; }
php
{ "resource": "" }
q237619
Validate.areSameType
train
public static function areSameType($value1, $value2): bool { if (!is_object($value1) || !is_object($value2)) { return gettype($value1) === gettype($value2); } return get_class($value1) === get_class($value2); }
php
{ "resource": "" }
q237620
Validate.isType
train
public static function isType($value, ?string $type): bool { if ($type === null) { return true; } $result = self::isSimpleType($value, $type); if ($result !== null) { return $result; } return ($value instanceof $type); }
php
{ "resource": "" }
q237621
Validate.isListOf
train
public static function isListOf($value, ?string $type): bool { if (!static::isTraversable($value)) { return false; } if ($type === null) { return true; } $result = true; foreach ($value as $val) { if (!static::isType($val, $type)...
php
{ "resource": "" }
q237622
Validate.isStringCastable
train
public static function isStringCastable($value): bool { $result = false; $type = strtolower(gettype($value)); switch ($type) { case 'string': case 'null': case 'boolean': case 'integer': case 'double': $result = true...
php
{ "resource": "" }
q237623
Validate.isJsonEncodable
train
public static function isJsonEncodable($value): bool { if ($value === null || is_scalar($value) || is_array($value)) { return true; } if (is_object($value) && ($value instanceof JsonSerializable)) { return true; } return false; }
php
{ "resource": "" }
q237624
Validate.isSerializable
train
public static function isSerializable($value): bool { if ($value === null || is_scalar($value) || is_array($value)) { return true; } if (is_object($value) && ($value instanceof Serializable)) { return true; } return false; }
php
{ "resource": "" }
q237625
Validate.isTraversable
train
public static function isTraversable($value): bool { if (is_array($value)) { return true; } if (is_object($value) && ($value instanceof Traversable)) { return true; } return false; }
php
{ "resource": "" }
q237626
Validate.isCountable
train
public static function isCountable($value): bool { if (is_array($value)) { return true; } if (is_object($value) && ($value instanceof Countable)) { return true; } return false; }
php
{ "resource": "" }
q237627
Validate.isArrayAccessible
train
public static function isArrayAccessible($value): bool { if (is_array($value)) { return true; } if (is_object($value) && ($value instanceof ArrayAccess)) { return true; } return false; }
php
{ "resource": "" }
q237628
Validate.implementsInterface
train
public static function implementsInterface($value, string $interface): bool { if (!is_object($value)) { if (!(static::classExists($value) || static::interfaceExists($value))) { return false; } $value = (string) $value; } $reflection = new ...
php
{ "resource": "" }
q237629
Validate.methodExists
train
public static function methodExists($value, $object): bool { if (!static::isStringCastable($value)) { return false; } return method_exists($object, (string) $value); }
php
{ "resource": "" }
q237630
Validate.isValidTimezone
train
private static function isValidTimezone(string $timezone): bool { // @codeCoverageIgnoreStart if (self::$timezones === null) { self::$timezones = []; foreach (timezone_identifiers_list() as $zone) { self::$timezones[$zone] = true; } } ...
php
{ "resource": "" }
q237631
Validate.isValidUri
train
private static function isValidUri(array $uri): bool { if (!self::isValidUriScheme($uri['scheme'])) { return false; } if (!self::isValidUriPath($uri['path'])) { return false; } if (!self::isValidUriQuery($uri['query'])) { return false; ...
php
{ "resource": "" }
q237632
Validate.isValidUriScheme
train
private static function isValidUriScheme(?string $scheme): bool { // http://tools.ietf.org/html/rfc3986#section-3 // The scheme and path components are required, though the path may be // empty (no characters) if ($scheme === null || $scheme === '') { return false; ...
php
{ "resource": "" }
q237633
Validate.isValidUriAuthority
train
private static function isValidUriAuthority(?string $authority): bool { if ($authority === null || $authority === '') { return true; } // http://tools.ietf.org/html/rfc3986#section-3.2 // authority = [ userinfo "@" ] host [ ":" port ] $pattern = '/\A(?:([^@]*)@)?...
php
{ "resource": "" }
q237634
Validate.isValidUriPath
train
private static function isValidUriPath(string $path): bool { // http://tools.ietf.org/html/rfc3986#section-3 // The scheme and path components are required, though the path may be // empty (no characters) if ($path === '') { return true; } // path ...
php
{ "resource": "" }
q237635
Validate.isValidUriQuery
train
private static function isValidUriQuery(?string $query): bool { if ($query === null || $query === '') { return true; } // http://tools.ietf.org/html/rfc3986#section-3.4 // query = *( pchar / "/" / "?" ) // pchar = unreserved / pct-encoded / sub-delims / ":" / "@"...
php
{ "resource": "" }
q237636
Validate.isValidUriFragment
train
private static function isValidUriFragment(?string $fragment): bool { if ($fragment === null || $fragment === '') { return true; } // http://tools.ietf.org/html/rfc3986#section-3.5 // fragment = *( pchar / "/" / "?" ) // pchar = unreserved / pct-encoded / sub-del...
php
{ "resource": "" }
q237637
Validate.isValidAuthUser
train
private static function isValidAuthUser(?string $userinfo): bool { if ($userinfo === null) { return true; } // http://tools.ietf.org/html/rfc3986#section-3.2.1 // userinfo = *( unreserved / pct-encoded / sub-delims / ":" ) $pattern = sprintf( '/\A(?:[...
php
{ "resource": "" }
q237638
Validate.isValidAuthHost
train
private static function isValidAuthHost(string $host): bool { if ($host === '') { return true; } // http://tools.ietf.org/html/rfc3986#section-3.2.2 // A host identified by an Internet Protocol literal address, version 6 // [RFC3513] or later, is distinguished by...
php
{ "resource": "" }
q237639
Validate.isSimpleType
train
private static function isSimpleType($value, string $type): ?bool { switch ($type) { case 'array': return static::isArray($value); break; case 'object': return static::isObject($value); break; case 'bool': ...
php
{ "resource": "" }
q237640
BaseServiceProvider.startPluginTraits
train
private function startPluginTraits() { foreach ($this->getPluginTraits() as $trait) { if (method_exists(get_called_class(), $method = 'start' . class_basename($trait) . 'Plugin')) { call_user_func([ $this, $method ], $this->app); } } }
php
{ "resource": "" }
q237641
BaseServiceProvider.requiresPlugins
train
public function requiresPlugins() { $has = class_uses_recursive(get_called_class()); $check = array_combine(func_get_args(), func_get_args()); $missing = array_values(array_diff($check, $has)); if (isset($missing[ 0 ])) { $plugin = collect(debug_backtrace())->where(...
php
{ "resource": "" }
q237642
BaseServiceProvider.resolveDirectories
train
private function resolveDirectories() { if ($this->scanDirs !== true) { return; } if ($this->rootDir === null) { $class = new ReflectionClass(get_called_class()); $filePath = $class->getFileName(); $this->dir = $rootDir = path_get_director...
php
{ "resource": "" }
q237643
BaseServiceProvider.getPluginPriority
train
private function getPluginPriority($name, $index = 0) { $priority = 10; if (property_exists($this, "{$name}PluginPriority")) { $value = $this->{$name . 'PluginPriority'}; $priority = is_array($value) ? $value[ $index ] : $value; } return $priority; }
php
{ "resource": "" }
q237644
BaseServiceProvider.onRegister
train
public function onRegister($name, Closure $callback) { $priority = $this->getPluginPriority($name); $this->registerCallbacks[] = compact('name', 'priority', 'callback'); }
php
{ "resource": "" }
q237645
BaseServiceProvider.onBoot
train
public function onBoot($name, Closure $callback) { $priority = $this->getPluginPriority($name, 1); $this->bootCallbacks[] = compact('name', 'priority', 'callback'); }
php
{ "resource": "" }
q237646
BaseServiceProvider.fireCallbacks
train
private function fireCallbacks($name, Closure $modifier = null, Closure $caller = null) { $list = collect($this->{$name . 'Callbacks'}); if ($modifier) { $list = call_user_func_array($modifier, [ $list ]); } $caller = $caller ?: function (Closure $callback) { ...
php
{ "resource": "" }
q237647
FontStyle.formatStylesJs
train
public function formatStylesJs() { $options = []; $options[] = $this->formatStyle('Arial,Arial,Helvetica,sans-serif', 'Arial'); $options[] = $this->formatStyle('Arial Black,Arial Black,Gadget,sans-serif', 'Arial Black'); $options[] = $this->formatStyle('Comic Sans MS,Comic Sans MS,c...
php
{ "resource": "" }
q237648
TextNodeFormHandler.process
train
public function process(Request $request, FormInterface $form) { if ($request->isMethod('POST')) { $form->submit($request); if ($form->isValid()) { return true; } } return false; }
php
{ "resource": "" }
q237649
TextNodeFormHandler.onSuccess
train
public function onSuccess($locale, NodeInterface $node) { $this->eventDispatcher->dispatch(TadckaTreeEvents::NODE_EDIT_SUCCESS, new TreeNodeEvent($locale, $node)); $this->textNodeManager->save(); return $this->translator->trans('success.text_node_save', array(), 'SilvestraTextNodeBundle'); ...
php
{ "resource": "" }
q237650
AbstractFragmentedDuration.all
train
public function all() { $res = []; $len = count($this->fragments); for ($index=0; $index < $len; $index++) { $res[] = $this->get($index); } return $res; }
php
{ "resource": "" }
q237651
AbstractFragmentedDuration.with
train
public function with($index, $value) { $res = clone $this; $res->fragments = $this->insertInList($res->fragments, $index, $value); return $this; }
php
{ "resource": "" }
q237652
AbstractFragmentedDuration.withFragments
train
public function withFragments(array $fragments) { $res = clone $this; $res->fragments = $res->fillArrayInput($fragments); return $res; }
php
{ "resource": "" }
q237653
AbstractFragmentedDuration.withSize
train
public function withSize($index, $value) { $res = clone $this; $res->sizes = $this->insertInList($res->sizes, $index, $value); return $res; }
php
{ "resource": "" }
q237654
AbstractFragmentedDuration.withSizes
train
public function withSizes(array $sizes) { $res = clone $this; $res->sizes = $res->fillArrayInput($sizes); return $res; }
php
{ "resource": "" }
q237655
AbstractFragmentedDuration.insertInList
train
public function insertInList(array $values, $index, $value) { for ($i=count($values); $i < $index; $i++) { $values[$i] = null; } $values[$index] = $value; return $values; }
php
{ "resource": "" }
q237656
AbstractFragmentedDuration.withTransversal
train
public function withTransversal($index, $value) { $res = clone $this; $res->transversals = $this->insertInList($res->transversals, $index, $value); return $res; }
php
{ "resource": "" }
q237657
AbstractFragmentedDuration.withTransversals
train
public function withTransversals(array $transversals) { $res = clone $this; $res->transversals = $res->fillArrayInput($transversals); return $res; }
php
{ "resource": "" }
q237658
Token.expired
train
public function expired(\DateTime $date = null) { // Check if the token has an expiration date. if (!$this->expire) { return false; } $date = $date ?: new \DateTime('now', new \DateTimezone('UTC')); return ($date > $this->expire); }
php
{ "resource": "" }
q237659
TimeOffset.extractAbbreviation
train
protected function extractAbbreviation(DateRepresentationInterface $input) { $offset = $input->getOffset(); if (null === $abbr = $offset->getAbbreviation()) { return $input; } $abbr = strtolower($abbr); $list = DateTimeZone::listAbbreviations(); if (!is...
php
{ "resource": "" }
q237660
Customers.setBirthdate
train
public function setBirthdate($date) { if ($date instanceof DateTime) { $date = $date->format('Y-m-d'); } $this->data->birthDate = $date; return $this; }
php
{ "resource": "" }
q237661
Customers.setTaxDocument
train
public function setTaxDocument(TaxDocument $taxDocument) { $taxDocument->setContext(Moip::PAYMENT); $this->data->taxDocument = $taxDocument->getData(); return $this; }
php
{ "resource": "" }
q237662
Customers.setCreditCard
train
public function setCreditCard(CreditCard $creditCard) { $creditCard->setContext(Moip::PAYMENT); $fundingInstrument = new stdClass; $fundingInstrument->method = 'CREDIT_CARD'; $fundingInstrument->creditCard = $creditCard->getData(); $this->data->fundingInstrument = $fundingI...
php
{ "resource": "" }
q237663
Customers.createNewCreditCard
train
public function createNewCreditCard(CreditCard $creditCard, $id = null) { if (! $id) { $id = $this->data->id; } $creditCard->setContext(Moip::PAYMENT); $this->data = new stdClass; $this->data->method = 'CREDIT_CARD'; $this->data->creditCard = $creditCard...
php
{ "resource": "" }
q237664
Mapper.getEntityClass
train
public function getEntityClass($table, Row $row = null) { $namespace = $this->defaultEntityNamespace . '\\'; return $namespace . ucfirst(Utils::underscoreToCamel($table)); }
php
{ "resource": "" }
q237665
Mapper.getEntityField
train
public function getEntityField($table, $column) { $class = $this->getEntityClass($table); /** @var Entity $entity */ $entity = new $class; $reflection = $entity->getReflection($this); foreach ($reflection->getEntityProperties() as $property) { if ($property->getCo...
php
{ "resource": "" }
q237666
RequestAbstract.hydrateIfJsonToArray
train
private function hydrateIfJsonToArray($data) { if (is_array($data)) { return $data; } elseif (is_string($data)) { $attempt = json_decode($data, true); return empty($attempt) ? $data : $attempt; } return []; }
php
{ "resource": "" }
q237667
RequestAbstract.setData
train
public function setData($data) { $resultData = $this->hydrateIfJsonToArray($data); if (!empty($resultData)) { $this->data = $resultData; } else { $this->data = []; } }
php
{ "resource": "" }
q237668
RequestAbstract.setExtra
train
public function setExtra($extra) { $resultData = $this->hydrateIfJsonToArray($extra); if (!empty($resultData)) { $this->extra = $resultData; } else { $this->extra = []; } }
php
{ "resource": "" }
q237669
TogglService.saveTimeEntry
train
public function saveTimeEntry(TimeEntry $entry) { $startTime = strtotime($entry->getEntryDate()); $endTime = $startTime + $entry->getDurationTime(); $this->uri = 'https://www.toggl.com/api/v8/time_entries/' . $entry->getId(); $data = [ 'time_entry' => [ 'd...
php
{ "resource": "" }
q237670
TogglService.processTogglResponse
train
protected function processTogglResponse($response) { // We only need to do something if results are paginated if ($response->total_count <= 50) { return $response->data; } $reqdata = []; $reqdata = json_encode($reqdata); $pages = ceil($response->total_cou...
php
{ "resource": "" }
q237671
AssuranceMethod.initialize
train
private function initialize(object $object, string $original, string $inverted): void { $this->initMethod($object, $original, true); $this->initMethod($object, $inverted, false); }
php
{ "resource": "" }
q237672
ObjectBlender.mapExternalAssociation
train
public function mapExternalAssociation( ExternalAssociation $externalAssociation ) { // @See https://github.com/doctrine/common/issues/336 //if (!($referenceManager instanceof DocumentManager || $referenceManager instanceof EntityManagerInterface)) { if (!(method_exists($externalAsso...
php
{ "resource": "" }
q237673
ConnectionFactory.create
train
public function create(PDO $pdo) { switch ($pdo->getDatabaseType()) { case 'mysql': $connection = new MySqlConnection($pdo); break; case 'pgsql': $connection = new PostgreSqlConnection($pdo); break; case 'sql...
php
{ "resource": "" }
q237674
GeneratorAbstract.updateElement
train
public function updateElement(Element $element, array $data) { if (isset($data["id"])) { $element->setId($data["id"]); } if (isset($data["class"])) { $element->addClass($data["class"]); } return $element; }
php
{ "resource": "" }
q237675
UploadableType.onPreSetData
train
public function onPreSetData(FormEvent $event) { if (!$event->getData() || !$event->getForm()->getConfig()->getOption('removable')) { return; } $event->getForm()->add('remove', 'checkbox', array( 'label' => $this->options['remove_label'] )); }
php
{ "resource": "" }
q237676
UploadableType.onPreSubmit
train
public function onPreSubmit(FormEvent $event) { $data = $event->getData(); if ($data['file'] instanceof UploadedFile) { $event->getForm()->remove('remove'); } if (empty($data['file']) && (!isset($data['remove']) || !$data['remove'])) { $event->setData($event...
php
{ "resource": "" }
q237677
Configuration.addClientSection
train
private function addClientSection(ArrayNodeDefinition $node) { $node ->children() ->arrayNode('client') ->children() ->scalarNode('application_name')->isRequired()->cannotBeEmpty()->end() ->scalarNode('client_id'...
php
{ "resource": "" }
q237678
AssociationStaticController.singleAssociationAction
train
public function singleAssociationAction() { $this->checkStaticTemplateIsIncluded(); $this->checkSettings(); $this->slotExtendedAssignMultiple([ self::VIEW_VARIABLE_ASSOCIATION_ID => $this->settings[self::SETTINGS_ASSOCIATION_ID] ], __CLASS__, __FUNCTION__); retu...
php
{ "resource": "" }
q237679
Logger.getLogger
train
public function getLogger() { if (null === $this->logger && \Zend_Registry::isRegistered(self::getNamespace())) { $this->setLogger(\Zend_Registry::get(self::getNamespace())); } return $this->logger; }
php
{ "resource": "" }
q237680
FuelServiceProvider.resolveManager
train
public function resolveManager($dic, $placement = 'prepend') { $manager = $dic->resolve('Fuel\\Alias\\Manager'); $manager->register($placement); return $manager; }
php
{ "resource": "" }
q237681
ControllerActionName.controllerName
train
public function controllerName() { $request = $this->stack->getCurrentRequest(); if ($request instanceof Request) { $string = $request->get('_controller'); $parts = explode('::', $string); $controller = $parts[0]; $pattern = "#Controller\\\([a-zA-Z\\\]*)Co...
php
{ "resource": "" }
q237682
ControllerActionName.actionName
train
public function actionName() { $request = $this->stack->getCurrentRequest(); if ($request instanceof Request) { $pattern = "#::([a-zA-Z]*)Action#"; $matches = array(); preg_match($pattern, $request->get('_controller'), $matches); if (isset($matches[1])) { ...
php
{ "resource": "" }
q237683
Base.run
train
public function run($target) { $return = $this->exec($this->getCommand($target)); return $this->output[$target] = $this->cleanOutput($target, $return['output']); }
php
{ "resource": "" }
q237684
UUID.v5
train
public static function v5(string $namespace, string $name) { if (!Validate::isValidUUID($namespace)) { return false; } // Get hexadecimal components of namespace $nhex = str_replace(array('-', '{', '}'), '', $namespace); // Binary Value $nstr = ''; ...
php
{ "resource": "" }
q237685
Field.getFldTypeForPhp
train
public function getFldTypeForPhp() { $type = 'mixed'; switch ($this->getFldType()) { case FFCST::TYPE_INTEGER: case FFCST::TYPE_BIGINT: $type = 'int'; break; case FFCST::TYPE_DATETIME: case FFCST::TYPE_MD5: c...
php
{ "resource": "" }
q237686
Field.getFldTypeForClass
train
public function getFldTypeForClass() { $type = 'TYPE_STRING'; switch ($this->getFldType()) { case FFCST::TYPE_INTEGER: $type = 'TYPE_INTEGER'; break; case FFCST::TYPE_BIGINT: $type = 'TYPE_BIGINT'; break; ...
php
{ "resource": "" }
q237687
Field.getFromPDO
train
public static function getFromPDO(array $p_pdo_description) { $me = self::getNew(); if (is_array($p_pdo_description)) { if (array_key_exists('name', $p_pdo_description)) { $me->setFldName($p_pdo_description['name']); } if (array_key_exists('len', $...
php
{ "resource": "" }
q237688
Response.getBody
train
public function getBody() { $body = json_decode($this->response->getBody(), true); if (!$body) { throw new ResponseWithoutBody('Response without body'); } if (!$this->transformer) { return $body; } return $this->transformer->transformData($b...
php
{ "resource": "" }
q237689
Awale.move
train
public function move($player, $move) { $this->checkPlayer($player); $this->checkMove($move); // Take seeds in hand $hand = $this->grid[$player]['seeds'][$move]; $this->grid[$player]['seeds'][$move] = 0; $row = $player; $box = $move; /** * D...
php
{ "resource": "" }
q237690
Awale.play
train
public function play($player, $move) { if (!$this->isPlayerTurn($player)) { throw new AwaleException('Not your turn.'); } if (0 === $this->grid[$player]['seeds'][$move]) { throw new AwaleException('This container is empty.'); } $this->checkMustFeedOp...
php
{ "resource": "" }
q237691
Awale.getPlayerWithMoreThanHalfSeeds
train
private function getPlayerWithMoreThanHalfSeeds() { $seedsToWin = $this->getSeedsNeededToWin(); if ($this->grid[Awale::PLAYER_0]['attic'] > $seedsToWin) { return self::PLAYER_0; } if ($this->grid[Awale::PLAYER_1]['attic'] > $seedsToWin) { return self::PLAYER...
php
{ "resource": "" }
q237692
Awale.getWinner
train
public function getWinner() { if (!$this->isGameOver()) { return null; } if ($this->getScore(self::PLAYER_0) === $this->getScore(self::PLAYER_1)) { return self::DRAW; } elseif ($this->getScore(self::PLAYER_0) > $this->getScore(self::PLAYER_1)) { r...
php
{ "resource": "" }
q237693
ExceptionLogger.getTrace
train
public function getTrace($trace = array()) { $traceMessage = ''; foreach ($trace as $t) { $traceMessage .= sprintf(' at %s line %s', $t['file'], $t['line']) . "\n"; } return $traceMessage; }
php
{ "resource": "" }
q237694
ExceptionLogger.getStatusCode
train
public function getStatusCode(FlattenException $exception) { $str = ''; if (method_exists($exception, 'getStatusCode') == true) { $str = $exception->getStatusCode(); } elseif (method_exists($exception, 'getCode') == true) { $str = $exception->getCode(); } ...
php
{ "resource": "" }
q237695
ArgumentList.addConfig
train
public function addConfig(ParametersConfig $config):void { array_unshift($this->configs, $config); foreach ($this->info->getNames() as $name) { if ($config->hasValue($name)) { $this->missingValues[$name] = false; } } }
php
{ "resource": "" }
q237696
ArgumentList.getType
train
public function getType(string $name):?string { if (! $this->info->includes($name)) { throw ArgumentListException::parameterNotFound($name); } foreach ($this->configs as $config) { /** @var $config ParametersConfig */ if ($config->hasType($name)) { ...
php
{ "resource": "" }
q237697
ArgumentList.getOptional
train
public function getOptional(int $type = AII::TYPE_BUILTIN | AII::TYPE_UNTYPED | AII::TYPE_CLASS):array { $includeUntyped = ($type & AII::TYPE_UNTYPED) === AII::TYPE_UNTYPED; $includeBuiltin = ($type & AII::TYPE_BUILTIN) === AII::TYPE_BUILTIN; $includeClass = ($type & AII::TYPE_CLASS) === AII...
php
{ "resource": "" }
q237698
ArgumentList.getMissing
train
public function getMissing(int $type = AII::TYPE_BUILTIN | AII::TYPE_UNTYPED | AII::TYPE_CLASS ):array { $includeUntyped = ($type & AII::TYPE_UNTYPED) === AII::TYPE_UNTYPED; $includeBuiltin = ($type & AII::TYPE_BUILTIN) === AII::TYPE_BUILTIN; $includeClass = ($type & AII::TYPE_CLASS) === AII...
php
{ "resource": "" }
q237699
TwitterService.setAccessTokenFromProfile
train
public function setAccessTokenFromProfile(TwitterProfile $profile) { $tokens = $profile->get(['access_token', 'access_token_secret']); if (!empty($tokens['access_token'])) { $this->app['twitter']->setTokens($tokens['access_token'], $tokens['access_token_secret']); $this->pro...
php
{ "resource": "" }