Since: 1.0
Author: Bernhard Schussek (bschussek@gmail.com)
Example #1
0
 /**
  * {@inheritdoc}
  */
 public static function create($body, TypeResolver $typeResolver = null, DescriptionFactory $descriptionFactory = null, Context $context = null)
 {
     Assert::stringNotEmpty($body);
     Assert::allNotNull([$typeResolver, $descriptionFactory]);
     // 1. none or more whitespace
     // 2. optionally the keyword "static" followed by whitespace
     // 3. optionally a word with underscores followed by whitespace : as
     //    type for the return value
     // 4. then optionally a word with underscores followed by () and
     //    whitespace : as method name as used by phpDocumentor
     // 5. then a word with underscores, followed by ( and any character
     //    until a ) and whitespace : as method name with signature
     // 6. any remaining text : as description
     if (!preg_match('/^
             # Static keyword
             # Declares a static method ONLY if type is also present
             (?:
                 (static)
                 \\s+
             )?
             # Return type
             (?:
                 ([\\w\\|_\\\\]+)
                 \\s+
             )?
             # Legacy method name (not captured)
             (?:
                 [\\w_]+\\(\\)\\s+
             )?
             # Method name
             ([\\w\\|_\\\\]+)
             # Arguments
             \\(([^\\)]*)\\)
             \\s*
             # Description
             (.*)
         $/sux', $body, $matches)) {
         return null;
     }
     list(, $static, $returnType, $methodName, $arguments, $description) = $matches;
     $static = $static === 'static';
     $returnType = $typeResolver->resolve($returnType, $context);
     $description = $descriptionFactory->create($description, $context);
     $arguments = explode(',', $arguments);
     foreach ($arguments as &$argument) {
         $argument = explode(' ', trim($argument));
         if ($argument[0][0] === '$') {
             $argumentName = substr($argument[0], 1);
             $argumentType = new Void();
         } else {
             $argumentType = $typeResolver->resolve($argument[0], $context);
             $argumentName = '';
             if (isset($argument[1])) {
                 $argumentName = substr($argument[1], 1);
             }
         }
         $argument = ['name' => $argumentName, 'type' => $argumentType];
     }
     return new static($methodName, $arguments, $returnType, $static, $description);
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function setPositionOfProduct($productName, $position)
 {
     /** @var NodeElement $productsRow */
     $productsRow = $this->getElement('table')->find('css', sprintf('tbody > tr:contains("%s")', $productName));
     Assert::notNull($productsRow, 'There are no row with given product\'s name!');
     $productsRow->find('css', '.sylius-product-taxon-position')->setValue($position);
 }
Example #3
0
 /**
  * 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;
 }
 /**
  * {@inheritdoc}
  */
 public function onCheckoutComplete(GenericEvent $event)
 {
     /** @var OrderInterface $order */
     $order = $event->getSubject();
     Assert::isInstanceOf($order, OrderInterface::class);
     $this->session->set('sylius_order_id', $order->getId());
 }
Example #5
0
 /**
  * @Given /^I am logged in as "([^"]+)" administrator$/
  */
 public function iAmLoggedInAsAdministrator($email)
 {
     $user = $this->userRepository->findOneByEmail($email);
     Assert::notNull($user);
     $this->securityService->logIn($user);
     $this->sharedStorage->set('admin', $user);
 }
Example #6
0
 /**
  * {@inheritdoc}
  */
 public static function create($body, FqsenResolver $resolver = null, DescriptionFactory $descriptionFactory = null, TypeContext $context = null)
 {
     Assert::string($body);
     Assert::allNotNull([$resolver, $descriptionFactory]);
     $parts = preg_split('/\\s+/Su', $body, 2);
     return new static($resolver->resolve($parts[0], $context), $descriptionFactory->create(isset($parts[1]) ? $parts[1] : '', $context));
 }
Example #7
0
 /**
  * Create the tag
  *
  * @param string             $body               Tag body
  * @param DescriptionFactory $descriptionFactory The description factory
  * @param Context|null       $context            The Context is used to resolve Types and FQSENs, although optional
  *                                               it is highly recommended to pass it. If you omit it then it is assumed that
  *                                               the DocBlock is in the global namespace and has no `use` statements.
  *
  * @return SleepTime
  */
 public static function create($body, DescriptionFactory $descriptionFactory = null, Context $context = null)
 {
     Assert::integerish($body, self::MSG);
     Assert::greaterThanEq($body, 0, self::MSG);
     Assert::notNull($descriptionFactory);
     return new static($descriptionFactory->create($body, $context));
 }
Example #8
0
 /**
  * @Transform /^country "([^"]+)"$/
  * @Transform /^"([^"]+)" country$/
  * @Transform /^"([^"]+)" as shipping country$/
  */
 public function getCountryByName($countryName)
 {
     $countryCode = $this->countryNameConverter->convertToCode($countryName);
     $country = $this->countryRepository->findOneBy(['code' => $countryCode]);
     Assert::notNull($country, sprintf('Country with name "%s" does not exist', $countryName));
     return $country;
 }
Example #9
0
 /**
  * Creates the input.
  *
  * @param resource $stream A stream resource.
  */
 public function __construct($stream)
 {
     Assert::resource($stream, 'stream');
     $this->stream = $stream;
     // Not all streams are seekable
     @rewind($this->stream);
 }
 /**
  * @param int $totalSales
  * @param int $numberOfNewOrders
  * @param int $numberOfNewCustomers
  */
 public function __construct($totalSales, $numberOfNewOrders, $numberOfNewCustomers)
 {
     Assert::allInteger([$totalSales, $numberOfNewCustomers, $numberOfNewOrders]);
     $this->totalSales = $totalSales;
     $this->numberOfNewOrders = $numberOfNewOrders;
     $this->numberOfNewCustomers = $numberOfNewCustomers;
 }
Example #11
0
 /**
  * {@inheritdoc}
  */
 public function format($amount, $currency, $locale = 'en')
 {
     $formatter = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
     $result = $formatter->formatCurrency($amount / 100, $currency);
     Assert::notSame(false, $result, sprintf('The amount "%s" of type %s cannot be formatted to currency "%s".', $amount, gettype($amount), $currency));
     return $result;
 }
Example #12
0
 /**
  * @Then I should be viewing the administration panel in :localeCode
  * @Then I should still be viewing the administration panel in :localeCode
  * @Then they should be viewing the administration panel in :localeCode
  */
 public function iShouldBeViewingTheAdministrationPanelIn($localeCode)
 {
     $this->dashboardPage->open();
     $expectedSubHeader = $this->translate('sylius.ui.overview_of_your_store', $localeCode);
     $actualSubHeader = $this->dashboardPage->getSubHeader();
     Assert::same($actualSubHeader, $expectedSubHeader, sprintf('Dashboard header should say "%s", but says "%s" instead.', $expectedSubHeader, $actualSubHeader));
 }
 /**
  * @param UniquenessCheckerInterface $uniquenessChecker
  * @param int $pinLength
  *
  * @throws \InvalidArgumentException
  */
 public function __construct(UniquenessCheckerInterface $uniquenessChecker, $pinLength)
 {
     Assert::integer($pinLength, 'The value of pin length has to be an integer.');
     Assert::range($pinLength, 1, 9, 'The value of pin length has to be in range between 1 to 9.');
     $this->pinLength = $pinLength;
     $this->uniquenessChecker = $uniquenessChecker;
 }
Example #14
0
 /**
  * {@inheritdoc}
  */
 public function undefineType($typeName)
 {
     Assert::stringNotEmpty($typeName, 'The type name must be a non-empty string. Got: %s');
     $this->removeBindingsByType($typeName);
     unset($this->types[$typeName]);
     unset($this->typeIndex[$typeName]);
 }
Example #15
0
 /**
  * @return Element
  */
 private function getLastProvinceElement()
 {
     $provinces = $this->getElement('provinces');
     $items = $provinces->findAll('css', 'div[data-form-collection="item"]');
     Assert::notEmpty($items);
     return end($items);
 }
Example #16
0
 /**
  * {@inheritdoc}
  */
 public function createForPromotion(PromotionInterface $promotion)
 {
     Assert::true($promotion->isCouponBased(), sprintf('Promotion with name %s is not coupon based.', $promotion->getName()));
     $coupon = $this->factory->createNew();
     $coupon->setPromotion($promotion);
     return $coupon;
 }
 /**
  * @param UniquenessCheckerInterface $uniquenessChecker
  * @param int $tokenLength
  *
  * @throws \InvalidArgumentException
  */
 public function __construct(UniquenessCheckerInterface $uniquenessChecker, $tokenLength)
 {
     Assert::integer($tokenLength, 'The value of token length has to be an integer.');
     Assert::range($tokenLength, 1, 40, 'The value of token length has to be in range between 1 to 40.');
     $this->tokenLength = $tokenLength;
     $this->uniquenessChecker = $uniquenessChecker;
 }
 /**
  * {@inheritdoc}
  */
 public function calculate(ProductVariantInterface $productVariant, array $context)
 {
     Assert::keyExists($context, 'channel');
     $channelPricing = $productVariant->getChannelPricingForChannel($context['channel']);
     Assert::notNull($channelPricing);
     return $channelPricing->getPrice();
 }
Example #19
0
 /**
  * Creates a new AsciiDoc descriptor.
  *
  * @param ExecutableFinder $executableFinder The finder used to find the
  *                                           "man" binary.
  * @param ProcessLauncher  $processLauncher  The launcher for executing the
  *                                           "man" binary.
  */
 public function __construct($path, ExecutableFinder $executableFinder = null, ProcessLauncher $processLauncher = null)
 {
     Assert::file($path);
     $this->path = $path;
     $this->executableFinder = $executableFinder ?: new ExecutableFinder();
     $this->processLauncher = $processLauncher ?: new ProcessLauncher();
 }
Example #20
0
 /**
  * @return Element
  */
 private function getLastOptionValueElement()
 {
     $optionValues = $this->getElement('values');
     $items = $optionValues->findAll('css', 'div[data-form-collection="item"]');
     Assert::notEmpty($items);
     return end($items);
 }
Example #21
0
 /**
  * {@inheritdoc}
  */
 public function getMessages(ConversationInterface $conversation, $offset = 0, $limit = 20, $sortDirection = 'ASC')
 {
     Assert::integer($offset, '$offset expected an integer in Repository::getMessages(). Got: %s');
     Assert::integer($limit, '$limit expected an integer in Repository::getMessages(). Got: %s');
     Assert::oneOf(strtoupper($sortDirection), ['ASC', 'DESC'], '$sortDirection expected either ASC or DESC in Repository::getMessages(). Got: %s');
     return $this->driver->findMessages($conversation, $offset, $limit, $sortDirection);
 }
Example #22
0
 /**
  * {@inheritdoc}
  */
 public static function create($body, TypeResolver $typeResolver = null, DescriptionFactory $descriptionFactory = null, TypeContext $context = null)
 {
     Assert::stringNotEmpty($body);
     Assert::allNotNull([$typeResolver, $descriptionFactory]);
     $parts = preg_split('/(\\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE);
     $type = null;
     $variableName = '';
     $isVariadic = false;
     // if the first item that is encountered is not a variable; it is a type
     if (isset($parts[0]) && strlen($parts[0]) > 0 && $parts[0][0] !== '$') {
         $type = $typeResolver->resolve(array_shift($parts), $context);
         array_shift($parts);
     }
     // if the next item starts with a $ or ...$ it must be the variable name
     if (isset($parts[0]) && strlen($parts[0]) > 0 && ($parts[0][0] == '$' || substr($parts[0], 0, 4) === '...$')) {
         $variableName = array_shift($parts);
         array_shift($parts);
         if (substr($variableName, 0, 3) === '...') {
             $isVariadic = true;
             $variableName = substr($variableName, 3);
         }
         if (substr($variableName, 0, 1) === '$') {
             $variableName = substr($variableName, 1);
         }
     }
     $description = $descriptionFactory->create(implode('', $parts), $context);
     return new static($variableName, $type, $isVariadic, $description);
 }
 /**
  * @param FormEvent $event
  */
 public function preSetData(FormEvent $event)
 {
     /** @var ProductInterface $product */
     $product = $event->getData();
     Assert::isInstanceOf($product, ProductInterface::class);
     $this->generator->generate($product);
 }
Example #24
0
 /**
  * {@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);
 }
Example #25
0
 public static function create($body)
 {
     Assert::string($body);
     $scope = preg_split('/(,?\\s+)/Su', $body);
     $scope = array_filter($scope);
     return new static($scope);
 }
Example #26
0
 /**
  * Creates a new tag that represents any unknown tag type.
  *
  * @param string             $body
  * @param string             $name
  * @param DescriptionFactory $descriptionFactory
  * @param Context            $context
  *
  * @return static
  */
 public static function create($body, $name = '', DescriptionFactory $descriptionFactory = null, Context $context = null)
 {
     Assert::string($body);
     Assert::stringNotEmpty($name);
     $description = $descriptionFactory && $body ? $descriptionFactory->create($body, $context) : null;
     return new static($name, $description);
 }
Example #27
0
 /**
  * @Transform /^this order made by "([^"]+)"$/
  */
 public function getOrderByCustomer($email)
 {
     $customer = $this->customerRepository->findOneBy(['email' => $email]);
     Assert::notNull($customer, sprintf('Cannot find customer with email %s.', $email));
     $orders = $this->orderRepository->findByCustomer($customer);
     Assert::notEmpty($orders);
     return end($orders);
 }
 /**
  * {@inheritdoc}
  */
 public function transform($value)
 {
     if (null === $value) {
         return null;
     }
     Assert::isInstanceOf($value, $this->repository->getClassName());
     return PropertyAccess::createPropertyAccessor()->getValue($value, $this->identifier);
 }
 /**
  * @param GenericEvent $event
  */
 public function sendVerificationEmail(GenericEvent $event)
 {
     $customer = $event->getSubject();
     Assert::isInstanceOf($customer, CustomerInterface::class);
     $user = $customer->getUser();
     Assert::notNull($user);
     $this->handleUserVerificationToken($user);
 }
 /**
  * @param GenericEvent $event
  */
 public function uploadTaxonImage(GenericEvent $event)
 {
     $subject = $event->getSubject();
     Assert::isInstanceOf($subject, TaxonInterface::class);
     if ($subject->hasFile()) {
         $this->uploader->upload($subject);
     }
 }