/** * {@inheritdoc} */ public function checkClaim(JWTInterface $jwt) { if (!$jwt->hasClaim('iat')) { return []; } $iat = (int) $jwt->getClaim('iat'); Assertion::lessOrEqualThan($iat, time(), 'The JWT is issued in the future.'); return ['iat']; }
/** * {@inheritdoc} */ public function checkClaim(JWTInterface $jwt) { if (!$jwt->hasClaim('nbf')) { return []; } $nbf = (int) $jwt->getClaim('nbf'); Assertion::lessOrEqualThan($nbf, time(), 'The JWT can not be used yet.'); return ['nbf']; }
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; }
/** * @dataProvider invalidLessOrEqualProvider */ public function testLessOrEqualThanThrowsException($value, $limit) { $this->setExpectedException('Assert\\AssertionFailedException', null, Assertion::INVALID_LESS_OR_EQUAL); Assertion::lessOrEqualThan($value, $limit); }
/** * @param array[] $urls * * @throws \InvalidArgumentException */ public function __construct(array $urls) { Assertion::allIsInstanceOf($urls, UrlInterface::class); Assertion::lessOrEqualThan(count($urls), UrlSetInterface::URL_MAX_COUNT); $this->urls = $urls; }
/** * 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 TagInterface[] $tags * * @throws \InvalidArgumentException * * @return static */ public function withTags(array $tags) { Assertion::allIsInstanceOf($tags, TagInterface::class); Assertion::lessOrEqualThan(count($tags), VideoInterface::TAG_MAX_COUNT); $instance = clone $this; $instance->tags = $tags; return $instance; }
/** * @param ImageInterface[] $images * * @throws \InvalidArgumentException * * @return static */ public function withImages(array $images) { Assertion::allIsInstanceOf($images, ImageInterface::class); Assertion::lessOrEqualThan(count($this->images), UrlInterface::IMAGE_MAX_COUNT); $instance = clone $this; $instance->images = $images; return $instance; }
/** * @param array $stockTickers * * @throws \InvalidArgumentException * * @return static */ public function withStockTickers(array $stockTickers) { Assertion::allString($stockTickers); Assertion::allNotBlank($stockTickers); Assertion::lessOrEqualThan(count($stockTickers), NewsInterface::STOCK_TICKERS_MAX_COUNT); $instance = clone $this; $instance->stockTickers = $stockTickers; return $instance; }