/** * @param int $index * * @return \Jose\Object\JWKInterface */ public function getKey($index) { Assertion::integer($index, 'The index must be a positive integer.'); Assertion::greaterOrEqualThan($index, 0, 'The index must be a positive integer.'); Assertion::true($this->hasKey($index), 'Undefined index.'); return $this->getKeys()[$index]; }
/** * @param float $value * @param string $currency * * @throws \InvalidArgumentException */ public function __construct($value, $currency) { Assertion::float($value); Assertion::greaterOrEqualThan($value, PriceInterface::VALUE_MIN); $this->value = $value; $this->currency = $currency; }
public function __construct(string $eventStore = 'cqrs.event_store.cqrs_default', UuidInterface $previousEventId = null, int $delaySeconds = 0, int $throttleMicroseconds = 1000000) { Assertion::greaterOrEqualThan($delaySeconds, 0); Assertion::greaterThan($throttleMicroseconds, 0); $this->eventStore = $eventStore; $this->delaySeconds = $delaySeconds; $this->throttleMicroseconds = $throttleMicroseconds; }
/** * ClientAssertionJwt constructor. * * @param \Jose\JWTLoaderInterface $jwt_loader * @param \OAuth2\Exception\ExceptionManagerInterface $exception_manager * @param int $secret_lifetime */ public function __construct(JWTLoaderInterface $jwt_loader, ExceptionManagerInterface $exception_manager, $secret_lifetime = 0) { $this->setJWTLoader($jwt_loader); $this->setExceptionManager($exception_manager); Assertion::integer($secret_lifetime); Assertion::greaterOrEqualThan($secret_lifetime, 0); $this->secret_lifetime = $secret_lifetime; }
/** * ClientSecretBasic constructor. * * @param string $realm * @param int $secret_lifetime */ public function __construct($realm, $secret_lifetime = 0) { Assertion::string($realm); Assertion::integer($secret_lifetime); Assertion::greaterOrEqualThan($secret_lifetime, 0); $this->realm = $realm; $this->secret_lifetime = $secret_lifetime; }
private function __construct(Coords $startPoint, Coords $endPoint, $hits = 0) { Assertion::integer($hits); Assertion::greaterOrEqualThan($hits, 0); $size = $startPoint->distance($endPoint) + 1; Assertion::greaterOrEqualThan($size, static::MINIMUM_SIZE); Assertion::lessOrEqualThan($hits, $size); $this->startPoint = $startPoint; $this->endPoint = $endPoint; $this->hits = $hits; }
/** * A value object that contains a geographical coordinate. * * @param $latitude * @param $longitude */ public function __construct($latitude, $longitude) { Assertion::true(is_int($latitude) || is_float($latitude)); Assertion::true(is_int($longitude) || is_float($longitude)); Assertion::greaterOrEqualThan($latitude, -90.0); Assertion::lessOrEqualThan($latitude, 90.0); Assertion::greaterOrEqualThan($longitude, -180.0); Assertion::lessOrEqualThan($longitude, 180.0); $this->latitude = $latitude; $this->longitude = $longitude; }
/** * If the counter is not provided, the OTP is verified at the actual counter. * * {@inheritdoc} */ public function verify($otp, $counter = null, $window = null) { Assertion::string($otp, 'The OTP must be a string'); Assertion::nullOrInteger($counter, 'The counter must be null or an integer'); Assertion::greaterOrEqualThan($counter, 0, 'The counter must be at least 0.'); Assertion::nullOrInteger($window, 'The window parameter must be null or an integer'); if (null === $counter) { $counter = $this->getCounter(); } elseif ($counter < $this->getCounter()) { return false; } return $this->verifyOtpWithWindow($otp, $counter, $window); }
public function __construct($time, $memory, $nbCalls, Document $traceDocument = null) { Assertion::integer($time, 'Time is not an integer, got "%s"'); Assertion::greaterOrEqualThan($time, 0, 'Time must be greater than 0, got "%s"'); Assertion::integer($memory, 'Memory was not an integer, got "%s"'); Assertion::greaterOrEqualThan($memory, 0); Assertion::integer($nbCalls, 'Number of calls was not an integer, got "%s"'); Assertion::greaterOrEqualThan($nbCalls, 0); $this->time = $time; $this->memory = $memory; $this->nbCalls = $nbCalls; // not serialized. $this->traceDocument = $traceDocument; }
/** * @param mixed $time Time taken to execute the iteration in microseconds. */ public function __construct($time) { Assertion::greaterOrEqualThan($time, 0, 'Time cannot be less than 0, got %s'); Assertion::integer($time); $this->netTime = $time; }
/** * {@inheritdoc} */ public static function createRSAKey(array $values) { Assertion::keyExists($values, 'size', 'The key size is not set.'); $size = $values['size']; unset($values['size']); Assertion::true(0 === $size % 8, 'Invalid key size.'); Assertion::greaterOrEqualThan($size, 384, 'Key length is too short. It needs to be at least 384 bits.'); $key = openssl_pkey_new(['private_key_bits' => $size, 'private_key_type' => OPENSSL_KEYTYPE_RSA]); openssl_pkey_export($key, $out); $rsa = new RSAKey($out); $values = array_merge($values, $rsa->toArray()); return new JWK($values); }
/** * @dataProvider invalidGreaterOrEqualProvider * * @param mixed $value * @param mixed $limit */ public function testGreaterOrEqualThanThrowsException($value, $limit) { $this->setExpectedException('Assert\\AssertionFailedException', null, Assertion::INVALID_GREATER_OR_EQUAL); Assertion::greaterOrEqualThan($value, $limit); }
/** * @param int $viewCount * * @throws \InvalidArgumentException * * @return static */ public function withViewCount($viewCount) { Assertion::integer($viewCount); Assertion::greaterOrEqualThan($viewCount, VideoInterface::VIEW_COUNT_MIN); $instance = clone $this; $instance->viewCount = $viewCount; return $instance; }
public function __construct($offset) { $offset = (int) $offset; Assertion::greaterOrEqualThan($offset, 0, 'Offset cannot be lower than 0'); $this->offset = $offset; }
/** * {@inheritdoc} */ public function setExpiresAt($expires_at) { Assertion::integer($expires_at); Assertion::greaterOrEqualThan($expires_at, 0); $this->expires_at = $expires_at; }
public function __construct($rejectCount) { Assertion::integer($rejectCount, 'Rejection count must be an integer'); Assertion::greaterOrEqualThan($rejectCount, 0, 'Rejection count must be greater or equal to 0'); $this->rejectCount = $rejectCount; }
/** * @param int|null $timestamp * * @return int */ private function getTimestamp($timestamp) { $timestamp = null === $timestamp ? time() : $timestamp; Assertion::greaterOrEqualThan($timestamp, 0, 'Timestamp must be at least 0.'); return $timestamp; }
/** * Performs a request to the symfony application and returns the response. * * @param string $method * @param string $uri * @param mixed[] $parameters * @param bool $expectSuccess * @param string[] $headers * @param mixed[] $files * @param int $expectedStatus * @param bool $toJson * @param string $apiKey * @param bool $disableAssertions * * @throws \Exception If the json decode did not work * * @return string[] */ protected function performRequest($method, $uri, array $parameters = [], $expectSuccess = true, array $headers = [], array $files = [], $expectedStatus = 200, $toJson = true, $apiKey = null, $disableAssertions = false) { if (null !== $apiKey || null !== AppContext::$apiKey) { $headers[ApiKeyAuthenticator::API_KEY_HEADER] = $apiKey ?: AppContext::$apiKey; } $headers = array_combine(array_map(function ($headerName) { return sprintf('HTTP_%s', $headerName); }, array_keys($headers)), array_values($headers)); /** @var \Symfony\Bundle\FrameworkBundle\Client $client */ $client = $this->getContainer()->get('test.client'); $client->enableProfiler(); $client->request($method, $uri, $parameters, $files, $headers); $response = $client->getResponse(); if (!$disableAssertions) { $status = $response->getStatusCode(); if ($expectSuccess) { Assertion::greaterOrEqualThan($status, 200); Assertion::lessOrEqualThan($status, 399); } else { Assertion::greaterOrEqualThan($status, 400); Assertion::lessOrEqualThan($status, 599); } Assertion::same($expectedStatus, $status); } $this->recentClient = $client; if ($toJson) { $content = $response->getContent(); if (empty($content)) { $raw = null; } else { $raw = json_decode($content, true); Assertion::same(JSON_ERROR_NONE, json_last_error()); } return $raw; } return $response; }
/** * @param string $key The Key to wrap * @param bool $padding_enabled */ private static function checkKeySize($key, $padding_enabled) { Assertion::false(false === $padding_enabled && 0 !== mb_strlen($key, '8bit') % 8, 'Bad key size'); Assertion::greaterOrEqualThan(mb_strlen($key, '8bit'), 1, 'Bad key size'); }
public function __construct(int $lengthLimit, $encoding = 'utf-8') { Assertion::greaterOrEqualThan($lengthLimit, 0); $this->lengthLimit = $lengthLimit; $this->encoding = $encoding; }
protected function guardRequiredState() { parent::guardRequiredState(); Assertion::greaterOrEqualThan($this->position, 0); }
/** * @param float $priority * * @throws \InvalidArgumentException * * @return static */ public function withPriority($priority) { Assertion::float($priority); Assertion::greaterOrEqualThan($priority, UrlInterface::PRIORITY_MIN); Assertion::lessOrEqualThan($priority, UrlInterface::PRIORITY_MAX); Assertion::same($priority, round($priority, 1)); $instance = clone $this; $instance->priority = $priority; return $instance; }