Exemplo n.º 1
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);
 }
Exemplo n.º 2
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);
 }
Exemplo n.º 3
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));
 }
Exemplo n.º 4
0
 /**
  * @param PromotionCouponGeneratorInstructionInterface $instruction
  *
  * @return int
  *
  * @throws \InvalidArgumentException
  */
 private function calculatePossibleGenerationAmount(PromotionCouponGeneratorInstructionInterface $instruction)
 {
     $expectedAmount = $instruction->getAmount();
     $expectedCodeLength = $instruction->getCodeLength();
     Assert::allNotNull([$expectedAmount, $expectedCodeLength], 'Code length or amount cannot be null.');
     $generatedAmount = $this->couponRepository->countByCodeLength($expectedCodeLength);
     return floor(pow(16, $expectedCodeLength) * $this->ratio - $generatedAmount);
 }