/** * {@inheritdoc} */ public function release(StockableInterface $stockable, $quantity) { Assert::greaterThan($quantity, 0, 'Quantity of units must be greater than 0.'); $this->dispatchEvent(SyliusStockableEvents::PRE_RELEASE, $stockable); $stockable->setOnHold($stockable->getOnHold() - $quantity); $this->dispatchEvent(SyliusStockableEvents::POST_RELEASE, $stockable); }
/** * Adds a participation to the data collector. * * @param string $testIdentifier It will look like "Qp0gahJ3RAO3DJ18b0XoUQ" * @param int $variationIndex * @throws InvalidArgumentException */ public function addParticipation($testIdentifier, $variationIndex) { Assert::string($testIdentifier, 'Test identifier must be a string'); Assert::integer($variationIndex, 'Variation index must be integer'); Assert::greaterThan($variationIndex, -1, 'Variation index must be integer >= 0'); $this->participations[$testIdentifier] = $variationIndex; }
/** * Sets the name of the command. * * Contrary to the base implementation, the name of an option command must * contain at least two characters. * * @param string $name The name of the command. * * @return static The current instance. */ public function setName($name) { if (null !== $name) { Assert::string($name, 'The command name must be a string or null. Got: %s'); Assert::notEmpty($name, 'The command name must not be empty.'); Assert::greaterThan(strlen($name), 1, sprintf('The command name should contain at least two characters. Got: "%s"', $name)); } parent::setName($name); return $this; }
/** * Creates a new binding. * * @param string $query The resource query. * @param Resource|ResourceCollection $resources The resources to bind. * @param BindingType $type The type to bind against. * @param array $parameters Additional parameters. * @param string $language The language of the resource query. * * @throws NoSuchParameterException If an invalid parameter was passed. * @throws MissingParameterException If a required parameter was not passed. * @throws InvalidArgumentException If the resources are invalid. */ public function __construct($query, $resources, BindingType $type, array $parameters = array(), $language = 'glob') { if ($resources instanceof Resource) { $resources = new ArrayResourceCollection(array($resources)); } if (!$resources instanceof ResourceCollection) { throw new InvalidArgumentException(sprintf('Expected resources of type ResourceInterface or ' . 'ResourceCollectionInterface. Got: %s', is_object($resources) ? get_class($resources) : gettype($resources))); } Assert::greaterThan(count($resources), 0, 'You should pass at least one resource to EagerBinding.'); parent::__construct($query, $type, $parameters, $language); $this->resources = $resources; }
private function assertLongNameValid($longName) { Assert::string($longName, 'The long option name must be a string. Got: %s'); Assert::notEmpty($longName, 'The long option name must not be empty.'); Assert::greaterThan(strlen($longName), 1, sprintf('The long option name must contain more than one character. Got: "%s"', $longName)); Assert::startsWithLetter($longName, 'The long option name must start with a letter.'); Assert::regex($longName, '~^[a-zA-Z0-9\\-]+$~', 'The long option name must contain letters, digits and hyphens only.'); }