/** * @param string $direction * @param int $days */ public function __construct($direction, $days) { Assertion::integerish($days); Assertion::choice($direction, [self::DIRECTION_PAST, self::DIRECTION_FUTURE]); $this->direction = $direction; $this->days = (int) $days; }
/** * @param string $resolution * * @throws \InvalidArgumentException * * @return static */ public function withResolution($resolution) { $choices = [PriceInterface::RESOLUTION_HD, PriceInterface::RESOLUTION_SD]; Assertion::choice($resolution, $choices); $instance = clone $this; $instance->resolution = $resolution; return $instance; }
/** * @param string $allowEmbed * * @throws \InvalidArgumentException * * @return static */ public function withAllowEmbed($allowEmbed) { $choices = [PlayerLocationInterface::ALLOW_EMBED_NO, PlayerLocationInterface::ALLOW_EMBED_YES]; Assertion::choice($allowEmbed, $choices); $instance = clone $this; $instance->allowEmbed = $allowEmbed; return $instance; }
/** * Constructor. * * @param Identifier $identifier * @param \DateTimeImmutable $createdAt * @param string $url * @param string $visibility */ public function __construct(Identifier $identifier, \DateTimeImmutable $createdAt, $url, $visibility) { Assertion::choice($visibility, static::$visibilityEnum); Assertion::url($url); $this->identifier = $identifier; $this->createdAt = $createdAt; $this->url = $url; $this->visibility = $visibility; }
/** * @param int $gender * @param string $firstName * @param string $lastName * @param string $email */ public function __construct($gender, $firstName, $lastName, $email) { Assertion::choice($gender, [self::GENDER_MALE, self::GENDER_FEMALE]); Assertion::notEmpty($firstName); Assertion::notEmpty($lastName); Assertion::email($email); $this->gender = $gender; $this->firstName = $firstName; $this->lastName = $lastName; $this->email = $email; }
/** * @param string $result * @param Coords $target * @param Coords $startPoint * @param Coords $endPoint */ private function __construct($result, Coords $target, Coords $startPoint = null, Coords $endPoint = null) { Assertion::choice($result, [static::HIT, static::MISS, static::SANK, static::WIN]); if (in_array($result, [static::SANK, static::WIN])) { Assertion::notNull($startPoint); Assertion::notNull($endPoint); } $this->result = $result; $this->startPoint = $startPoint; $this->endPoint = $endPoint; $this->target = $target; }
/** * Create a Config. * * @param string $sender Sender code to use. * @param string $wsdl WSDL file to use (local path or URL), null means default depending on the debug mode. * @param int $timeoutSec (Optional) Timeout in seconds, null means no timeout. * @param string $operatingMode (Optional) Operating mode, default is "P" for production. "D" = Development, "T" = Test. * @param array $soapClientOptions (Optional) Options for SoapClient. * @param string $receiver (Optional) Receiver code to use, default: YELLOWCUBE. */ function __construct($sender, $wsdl = null, $timeoutSec = null, $operatingMode = 'P', array $soapClientOptions = array(), $receiver = 'YELLOWCUBE') { Assertion::notEmpty($sender, 'Sender must be set.'); Assertion::nullOrNotEmpty($wsdl, 'WSDL must be set.'); Assertion::nullOrInteger($timeoutSec, 'Timeout must be null or an integer in seconds.'); Assertion::choice($operatingMode, array('T', 'D', 'P'), 'Operating mode must be "T", "D" or "P".'); Assertion::notEmpty($receiver, 'Receiver must be set.'); $this->sender = $sender; $this->wsdl = $wsdl; $this->timeoutSec = $timeoutSec; $this->operatingMode = $operatingMode; $this->soapClientOptions = $soapClientOptions; $this->receiver = $receiver; }
/** * @param UuidInterface $id * @param int $type * @param string $street * @param string $streetNumber * @param string $postalCode * @param string $city * @param string $state * @param string $country * @param string $phone */ public function __construct(UuidInterface $id, $type, $street, $streetNumber, $postalCode, $city, $state, $country, $phone) { Assertion::uuid($id->toString()); Assertion::choice($type, [self::TYPE_BILLING, self::TYPE_SHIPPING]); Assertion::notEmpty($street); Assertion::notEmpty($streetNumber); Assertion::notEmpty($postalCode); Assertion::notEmpty($city); Assertion::notEmpty($state); Assertion::notEmpty($country); Assertion::notEmpty($phone); $this->id = $id; $this->type = $type; $this->street = $street; $this->streetNumber = $streetNumber; $this->postalCode = $postalCode; $this->city = $city; $this->state = $state; $this->country = $country; $this->phone = $phone; }
public function __construct($filters, $offset, $limit, $sortField, $sortOrder, $isPaginated) { Assertion::isArray($filters, "Invalid filters"); Assertion::integerish($limit, "Invalid limit"); Assertion::integerish($offset, "Invalid offset"); Assertion::nullOrString($sortField, "Invalid sort field"); Assertion::choice($sortOrder, [null, self::ORDER_ASC, self::ORDER_DESC], "Invalid sort order"); Assertion::boolean($isPaginated, "Invalid value for isPaginated"); if ($limit < 0) { throw new \InvalidArgumentException("Invalid limit"); } if ($offset < 0) { throw new \InvalidArgumentException("Invalid offset"); } $this->filters = $filters; $this->offset = (int) $offset; $this->limit = (int) $limit; $this->sortField = $sortField; $this->sortOrder = $sortOrder; $this->isPaginated = (bool) $isPaginated; }
/** * @param string $live * * @throws \InvalidArgumentException * * @return static */ public function withLive($live) { $choices = [VideoInterface::LIVE_NO, VideoInterface::LIVE_YES]; Assertion::choice($live, $choices); $instance = clone $this; $instance->live = $live; return $instance; }
/** * @param string $relationship * * @throws \InvalidArgumentException */ public function __construct($relationship) { $choices = [PlatformInterface::RELATIONSHIP_ALLOW, PlatformInterface::RELATIONSHIP_DENY]; Assertion::choice($relationship, $choices); $this->relationship = $relationship; }
/** * @param string $value */ private function __construct($value) { Guard::choice($value, $this->possibleValues()); $this->value = $value; }
private function __construct($type) { Assertion::choice($type, ['read', 'write']); $this->type = $type; }
/** * @param string $changeFrequency * * @throws \InvalidArgumentException * * @return static */ public function withChangeFrequency($changeFrequency) { $choices = [UrlInterface::CHANGE_FREQUENCY_ALWAYS, UrlInterface::CHANGE_FREQUENCY_HOURLY, UrlInterface::CHANGE_FREQUENCY_DAILY, UrlInterface::CHANGE_FREQUENCY_WEEKLY, UrlInterface::CHANGE_FREQUENCY_MONTHLY, UrlInterface::CHANGE_FREQUENCY_YEARLY, UrlInterface::CHANGE_FREQUENCY_NEVER]; Assertion::choice($changeFrequency, $choices); $instance = clone $this; $instance->changeFrequency = $changeFrequency; return $instance; }
/** * @param string $algo */ public function __construct($algo) { Assertion::choice($algo, hash_algos()); $this->algo = $algo; }
/** * @param string $minLevel One of the \Psr\Log\LogLevel constants. * @param \Psr\Log\LoggerInterface $logger * * @throws \InvalidArgumentException if log level is invalid. */ public function __construct($minLevel, LoggerInterface $logger) { Assertion::choice($minLevel, self::$levelOrder, "Level '{$minLevel}' is not defined."); $this->minLevel = $minLevel; $this->logger = $logger; }
public function testValidChoice() { Assertion::choice("foo", array("foo")); }
/** * @param string $access * * @throws \InvalidArgumentException * * @return static */ public function withAccess($access) { $choices = [NewsInterface::ACCESS_REGISTRATION, NewsInterface::ACCESS_SUBSCRIPTION]; Assertion::choice($access, $choices); $instance = clone $this; $instance->access = $access; return $instance; }