/** * {@inheritdoc} */ public function calculate(ProductVariantInterface $productVariant, array $context) { Assert::keyExists($context, 'channel'); $channelPricing = $productVariant->getChannelPricingForChannel($context['channel']); Assert::notNull($channelPricing); return $channelPricing->getPrice(); }
/** * @param FormEvent $event */ public function preSubmit(FormEvent $event) { $attributeValue = $event->getData(); Assert::keyExists($attributeValue, 'attribute', 'Cannot create an attribute value form on pre submit event without an "attribute" key in data.'); $form = $event->getForm(); $attribute = $this->attributeRepository->find($attributeValue['attribute']); $this->addValueField($form, $attribute); }
/** * @param Suite $suite * @param string $listenerName * @param array $listenerAttributes */ private function addListenerToSuite(Suite $suite, $listenerName, array $listenerAttributes) { Assert::keyExists($listenerAttributes, 'options'); $listener = $this->listenerRegistry->getListener($listenerName); $listenerOptions = $this->optionsProcessor->processConfiguration($listener, $listenerAttributes['options']); $listenerPriority = isset($listenerAttributes['priority']) ? $listenerAttributes['priority'] : 0; $suite->addListener($listener, $listenerOptions, $listenerPriority); }
/** * {@inheritdoc} */ public function filter(array $items, array $configuration) { if (!$this->isConfigured($configuration)) { return $items; } Assert::keyExists($configuration, 'channel'); $filteredItems = []; foreach ($items as $item) { if ($this->isItemVariantInPriceRange($item->getVariant(), $configuration)) { $filteredItems[] = $item; } } return $filteredItems; }
/** * {@inheritDoc} */ public function getSubscribedEvents() { return ['phpab.participation.variant_run' => function (array $options) { Assert::notEmpty($options, 'Array passed to closure cannot be empty.'); Assert::keyExists($options, 1, 'Second parameter passed to closure must be instance of Bag.'); Assert::isInstanceOf($options[1], 'PhpAb\\Test\\Bag', 'Second parameter passed to closure must be instance of Bag.'); Assert::keyExists($options, 2, 'Third parameter passed to closure must be instance of VariantInterface.'); Assert::isInstanceOf($options[2], 'PhpAb\\Variant\\VariantInterface', 'Third parameter passed to closure must be instance of VariantInterface.'); /** @var TestInterface $test */ $test = $options[1]->getTest(); /** @var VariantInterface $chosenVariant */ $chosenVariant = $options[2]; // Call the add method $this->addParticipation($test->getIdentifier(), $chosenVariant->getIdentifier()); }]; }
/** * @param string $code * * @return EmailInterface */ private function getEmailFromConfiguration($code) { Assert::keyExists($this->configuration, $code, sprintf('Email with code "%s" does not exist!', $code)); /** @var EmailInterface $email */ $email = $this->emailFactory->createNew(); $configuration = $this->configuration[$code]; $email->setCode($code); $email->setSubject($configuration['subject']); $email->setTemplate($configuration['template']); if (isset($configuration['enabled']) && false === $configuration['enabled']) { $email->setEnabled(false); } if (isset($configuration['sender']['name'])) { $email->setSenderName($configuration['sender']['name']); } if (isset($configuration['sender']['address'])) { $email->setSenderAddress($configuration['sender']['address']); } return $email; }
/** * {@inheritDoc} */ public function getSubscribedEvents() { return ['phpab.participation.variant_run' => function ($options) { Assert::notEmpty($options, 'Array passed to closure cannot be empty.'); Assert::keyExists($options, 1, 'Second parameter passed to closure must be instance of Bag.'); Assert::isInstanceOf($options[1], 'PhpAb\\Test\\Bag', 'Second parameter passed to closure must be instance of Bag.'); Assert::keyExists($options, 2, 'Third parameter passed to closure must be instance of VariantInterface.'); Assert::isInstanceOf($options[2], 'PhpAb\\Variant\\VariantInterface', 'Third parameter passed to closure must be instance of VariantInterface.'); /** @var TestInterface $test */ $test = $options[1]->getTest(); Assert::keyExists($test->getOptions(), static::EXPERIMENT_ID, 'A Google Analytics Experiment Id must be set as options.'); $experimentId = $test->getOptions()[static::EXPERIMENT_ID]; /** @var VariantInterface $chosenVariant */ $chosenVariant = $options[2]; $variants = $test->getVariants(); // Get the index number of the element $chosenIndex = array_search($chosenVariant->getIdentifier(), array_keys($variants)); // Call the add method $this->addParticipation($experimentId, $chosenIndex); }]; }
/** * {@inheritdoc} */ protected function isConfigurationValid(array $configuration) { Assert::keyExists($configuration, 'amount'); Assert::integer($configuration['amount']); }
/** * @param array $configuration * @param array $keys */ protected function assertConfiguration($configuration, $keys) { foreach ($keys as $key) { Assert::keyExists($configuration, $key, 'Configuration key "%s" is required in action "' . $this->getName() . '"'); } }
/** * {@inheritdoc} */ public function sortBy($fieldName) { $sortableHeaders = $this->tableAccessor->getSortableHeaders($this->getElement('table')); Assert::keyExists($sortableHeaders, $fieldName, sprintf('Column "%s" is not sortable.', $fieldName)); $sortableHeaders[$fieldName]->find('css', 'a')->click(); }
/** * {@inheritdoc} */ public function getPrice(ProductVariantInterface $productVariant, array $context) { Assert::keyExists($context, 'channel'); return $this->productVariantPriceCalculator->calculate($productVariant, $context); }
/** * Assert that an valid dca is loaded. * * @param string $name Dca name. * * @return void * * @SuppressWarnings(PHPMD.Superglobals) */ protected function assertValidDca($name) { Assert::keyExists($GLOBALS['TL_DCA'], $name); Assert::isArray($GLOBALS['TL_DCA'][$name]); }