Nelmio\Alice\Throwable\Error\TypeErrorFactory::createForOptionalValueQuantifier PHP Method

createForOptionalValueQuantifier() public static method

public static createForOptionalValueQuantifier ( $quantifier ) : TypeError
return TypeError
    public static function createForOptionalValueQuantifier($quantifier) : \TypeError
    {
        return new \TypeError(sprintf('Expected quantifier to be either a scalar value or an instance of "%s". Got "%s" instead.', ValueInterface::class, is_object($quantifier) ? get_class($quantifier) : gettype($quantifier)));
    }

Usage Example

Example #1
0
 /**
  * @param int|ValueInterface         $quantifier
  * @param string|ValueInterface      $firstMember
  * @param string|ValueInterface|null $secondMember
  */
 public function __construct($quantifier, $firstMember, $secondMember = null)
 {
     if ($quantifier instanceof ValueInterface) {
         $quantifier = clone $quantifier;
     } elseif (is_scalar($quantifier)) {
         $quantifier = (int) $quantifier;
     } else {
         throw TypeErrorFactory::createForOptionalValueQuantifier($quantifier);
     }
     if (false === is_string($firstMember) && false === $firstMember instanceof ValueInterface) {
         throw TypeErrorFactory::createForOptionalValueFirstMember($firstMember);
     }
     if (null !== $secondMember && false === is_string($secondMember) && false === $secondMember instanceof ValueInterface) {
         throw TypeErrorFactory::createForOptionalValueSecondMember($secondMember);
     }
     $this->quantifier = $quantifier;
     $this->firstMember = $firstMember;
     $this->secondMember = $secondMember;
 }