Extracts an item from a ratelimit bucket.
@param \CharlotteDunois\Yasmin\Interfaces\RatelimitBucketInterface  $item
@return \CharlotteDunois\Yasmin\HTTP\APIRequest|bool|\React\Promise\ExtendedPromiseInterface
773604
protected function extractFromBucket(\CharlotteDunois\Yasmin\Interfaces\RatelimitBucketInterface $item) {
        if($item->size() > 0) {
            $meta = $item->getMeta();
            
            if($meta instanceof \React\Promise\ExtendedPromiseInterface) {
                return $meta->then(function ($data) use (&$item) {
                    if(!$data['limited']) {
                        $this->client->emit('debug', 'Retrieved item from bucket "'.$item->getEndpoint().'"');
                        return $item->shift();
                    }
                    
                    $this->queue[] = $item;
                    
                    $this->client->addTimer(($data['resetTime'] - \microtime(true)), function () {
                        $this->process();
                    });
                }, function ($error) use (&$item) {
                    $this->queue[] = $item;
                    $this->client->emit('error', $error);
                    
                    $this->process();
                    return false;
                });
            } else {
                if(!$meta['limited']) {
                    $this->client->emit('debug', 'Retrieved item from bucket "'.$item->getEndpoint().'"');
                    return $item->shift();
                }
                
                $this->queue[] = $item;
                
                $this->client->addTimer(($meta['resetTime'] - \microtime(true)), function () {
                    $this->process();
                });
            }
        }
        
        return false;
    }
181554
protected function findOrCreateItem(array $item)
    {
        $object = null;
        // If the table was not truncated to begin with, find current object
        // first
        if (!$this->truncate) {
            if (!empty($this->lookupFields)) {
                $lookupConditions = array();
                foreach ($this->lookupFields as $fieldName) {
                    $lookupConditions[$fieldName] = $item[$fieldName];
                }

                $object = call_user_func($this->lookupMethod, $lookupConditions);
            } else {
                $object = $this->objectRepository->find(current($item));
            }
        }

        if (!$object) {
            return $this->getNewInstance();
        }

        return $object;
    }
1236317
private function getUsage($item)
    {
        return $this->getCacheItem(self::CACHE_USAGE, $item, function () {
            return $this->getContext()->invokeApiGet('SHOW_USER_USAGE', ['user' => $this->getUsername()]);
        });
    }
597051
public function getItemHelper(array $item): ItemHelper
    {
        if ($this->level !== 1 && $item['type'] === 'folder') {
            return new HeaderItemHelper($item);
        } elseif ($this->level === 2 || ($this->level > 1 && $this->getPageType() === 'folder')) {
            return new DropdownItemHelper($item);
        } else {
            return new NavItemHelper($item);
        }
    }
157833
protected function validateItem($item)
    {
        // validate not null
        $this->validateNotNull('quantity', $item->getCalcQuantity());

        // validate discount
        $discountPercent = $item->getCalcDiscount();
        if ($discountPercent < 0 || $discountPercent > 100) {
            throw new PriceCalculationException('Discount must be within 0 and 100 percent');
        }
    }
476992
protected function _extract($item, $keys = array('value')) {
        if (is_array($item)) {
            if (isset($item[0])) {
                return $this->_extract($item[0], $keys);

            } else {
                foreach ($keys as $key) {
                    if (!empty($item[$key])) {
                        return trim($item[$key]);

                    } else if (isset($item['attributes'])) {
                        return $this->_extract($item['attributes'], $keys);
                    }
                }
            }
        }

        return trim($item);
    }
220315
public function flushErrorByItem(Item $item) : int
    {
        $queryBuilder = $this->getQueryBuilder();
        $affectedRows = $this->getPreparedFlushErrorQuery($queryBuilder)
            ->andWhere(
                $queryBuilder->expr()->eq('uid', $item->getIndexQueueUid())
            )
            ->execute();
        return $affectedRows;
    }
275053
public function remove($item)
    {
        $hash = spl_object_hash($item);
        if (isset($this->_items[$hash])) {
            unset($this->_items[$hash]);
        }
        
        return $this;
    }
1187767
public static function restore($item)
    {
        $isArchived = $item->isArchived();
        $canRestoreToDraft = $item->canRestoreToDraft();

        if (!$canRestoreToDraft) {
            throw new ValidationException(
                _t(
                    __CLASS__ . '.RESTORE_FALIURE_PERMISSION',
                    'Insufficient permission to restore item'
                ),
                403
            );
        }

        if (!$isArchived) {
            throw new ValidationException(
                _t(
                    __CLASS__ . '.RESTORE_FALIURE_STATE',
                    'This item already exists and cannot be restored'
                ),
                409
            );
        }

        $classname = $item->classname;
        $id = $item->ID;

        if (!$classname || !$id) {
            return new ValidationException(
                _t(
                    __CLASS__ . '.RESTORE_FALIURE_RECORD',
                    'Unable to restore item'
                ),
                400
            );
        }

        $changedLocation = self::shouldRestoreToRoot($item);

        $archivedItem = Versioned::get_latest_version($classname, $id);

        if (method_exists($archivedItem, 'doRestoreToStage')) {
            $restoredItem = $archivedItem->doRestoreToStage();
        } else {
            $archivedItem->writeToStage(Versioned::DRAFT);
            $restoredItem = Versioned::get_by_stage($archivedItem->classname, Versioned::DRAFT)
                ->byID($archivedItem->ID);
        }

        $message = self::getRestoreMessage($item, $restoredItem, $changedLocation);

        return $message;
    }
290061
public function addItem($item){
		$itemO=$this->getItemToAdd($item);
		$this->addContent($itemO);
		return $itemO;
	}
661518
public function setItem(Item $item = null)
    {
        if ($this->item !== $item) {
            // romove link on this item for old item
            if ($this->item instanceof Item) {
                $tmp = $this->item;
                $this->item = null;
                $tmp->removeImage($this);
            }
            $this->item = $item;
            // add link on this item
            if ($item instanceof Item) {
                $this->item->addImage($this);
            }
        }

        return $this;
    }
1119646
private function parseItem(Item $item)
    {
        // Get and format an item
        $tmp = $this->getFormattedItem($item);

        // Get related data
        $relationships = $this->getRelationships($item);

        // Closure function to internally parse related includes
        $parseRelationships = function($key, Item $item, array $relationships = []) {
            $related = $this->getFormattedItem($item);

            if (!in_array($related, $this->relationships)) {
                $this->relationships[] = $related;
            }

            unset($related['attributes']);
            unset($related['links']);
            $relationships[$key]['data'][] = $related;

            return $relationships;
        };

        // Loop data to create includes response data
        foreach ($relationships as $key => $value) {
            if ($value instanceof Collection) {
                foreach ($value->getData() as $include_value) {
                    $relationships = $parseRelationships($key, new Item($include_value, $value->getTransformer()), $relationships);
                }
            } else if ($value instanceof Item) {
                $relationships = $parseRelationships($key, $value, $relationships);
            }
        }

        // Pass the relationships data into the item
        $tmp['relationships'] = $relationships;

        // Set the response data
        if (is_array($this->data)) {
            $this->data[] = $tmp;
        } else {
            $this->data = $tmp;
        }

        return $this;
    }
989052
public function fromItem(Item $item)
    {
        foreach ($this->readTransformers as $readTransformer) {
            if ($readTransformer->isValidItem($item)) {
                return $readTransformer->fromItem($item);
            }
        }

        return $item;
    }
631957
protected function getItemTotal($item)
    {
        return $item->getRowTotal() - $item->getDiscountAmount() + $item->getTaxAmount() + $item->getWeeeTaxAppliedRowAmount();
    }
735498
public function removeItem(Item $item)
    {
        if ($this->items->contains($item)) {
            $this->items->removeElement($item);
            $item->removeGenre($this);
        }

        return $this;
    }
1005765
public function getItemId(Item $item)
    {
        /* @var $source \AnimeDb\Bundle\CatalogBundle\Entity\Source */
        foreach ($item->getSources() as $source) {
            if (strpos($source->getUrl(), $this->browser->getHost()) === 0 &&
                preg_match(self::REG_ITEM_ID, $source->getUrl(), $match)
            ) {
                return (int)$match['id'];
            }
        }
        return 0;
    }
75049
private function extendResponseItem($item)
    {
        $handlerFactory = $this->get('task.handler.factory');
        $handler = $handlerFactory->create($item['handlerClass']);

        if ($handler instanceof AutomationTaskHandlerInterface) {
            $item['taskName'] = $handler->getConfiguration()->getTitle();
        }

        $task = $this->get('task.repository.task')->findByUuid($item['taskId']);
        $executions = $this->get('task.repository.task_execution')->findByTask($task);
        if (0 < count($executions)) {
            $item['status'] = $executions[0]->getStatus();
        }

        unset($item['taskId']);

        return $item;
    }