/** * @param int $x * @param int $y */ public function __construct($x, $y) { Assertion::integer($x); Assertion::integer($y); $this->x = $x; $this->y = $y; }
/** * @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]; }
/** * Set the radius in meters. * * @param int $meters * * @return self */ public function setRadius($meters) { Assertion::integer($meters); Assertion::range($meters, 1, 100000); $this->radius = $meters; return $this; }
/** * @param int $id * * @throws SubjectNotFoundException * * @return JusticeRecord|false */ public function findById($id) { Assertion::integer($id); $crawler = $this->client->request('GET', sprintf(self::URL_SUBJECTS, $id)); $detailUrl = $this->extractDetailUrlFromCrawler($crawler); if (false === $detailUrl) { return false; } $people = []; $crawler = $this->client->request('GET', $detailUrl); $crawler->filter('.aunp-content .div-table')->each(function (Crawler $table) use(&$people) { $title = $table->filter('.vr-hlavicka')->text(); try { if ('jednatel: ' === $title) { $person = JusticeJednatelPersonParser::parseFromDomCrawler($table); $people[$person->getName()] = $person; } elseif ('Společník: ' === $title) { $person = JusticeSpolecnikPersonParser::parseFromDomCrawler($table); $people[$person->getName()] = $person; } } catch (\Exception $e) { } }); return new JusticeRecord($people); }
/** * {@inheritdoc} */ public function changeQuantity($quantity) { Assertion::integer($quantity, 'Quantity must be an integer'); $quantity = $this->quantity + $quantity; // Use this to make sure a proper integer check is done after addition $this->setQuantity($quantity); }
/** * @param int $period * * @return self */ private function setPeriod($period) { Assertion::integer($period, 'Period must be at least 1.'); Assertion::greaterThan($period, 0, 'Period must be at least 1.'); $this->setParameter('period', $period); return $this; }
/** * Set the limit. * * @param int $limit * * @return self */ public function setLimit($limit) { Assertion::integer($limit); Assertion::range($limit, 1, 50); $this->limit = $limit; return $this; }
/** * Initialise text item * * @param string $breakChar * @param int $lines */ public function __construct($breakChar = ' ', $lines = 1) { Assertion::string($breakChar); Assertion::integer($lines); $this->breakChar = $breakChar; $this->lines = $lines; }
/** * @param AddStorage $addStorage */ public function add(AddStorage $addStorage) { Assertion::integer($addStorage->storage); Assertion::integer($addStorage->quota); $storage = Storage::withUserDateUsageQuota(User::named($addStorage->name), new \DateTime(), Bytes::allocateUnits((int) $addStorage->storage), Quota::fromBytes(Bytes::allocateUnits((int) $addStorage->quota))); $this->storageRepository->add($storage); }
/** * @param int $width * @param int $height * @param array $shipSizes * @return Fields */ public static function generate($width, $height, array $shipSizes) { Assertion::integer($width); Assertion::integer($height); Assertion::allInteger($shipSizes); $elements = []; for ($y = 0; $y < $height; $y++) { for ($x = 0; $x < $width; $x++) { $elements[] = Field::generate($x, $y); } } $fields = Fields::create($elements); foreach ($shipSizes as $shipSize) { $attempts = 0; while (true) { if ($attempts == static::MAX_ATTEMPTS) { throw new CannotPlaceShipOnGridException(); } $direction = mt_rand(0, 1) == 0 ? 'right' : 'below'; $spot = Coords::create(mt_rand(0, $width - 1), mt_rand(0, $height - 1)); $endPoint = static::validEndpoint($fields, $spot, $shipSize, $direction); if ($endPoint === null) { $attempts++; continue; } // If we end up here the ship can fit at the determined spot $fields->place(Ship::create($spot, $endPoint)); break; } } return $fields; }
/** * @param ClockInterface $clock * @param integer $wait Wait for n milliseconds * @param integer $timeout Timeout after n milliseconds */ public function __construct(ClockInterface $clock, $wait, $timeout) { Assertion::integer($wait); Assertion::integer($timeout); $this->clock = $clock; $this->wait = static::millisecondsToMicroseconds($wait); $this->timeout = static::millisecondsToMicroseconds($timeout); }
public function toFileMakerValue($value) { if (null === $value) { return null; } Assertion::integer($value); return Decimal::fromInteger($value); }
/** * 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; }
/** * 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; }
/** * Orders process logs by started_at DESC * Returns array of process log entry arrays. * Each process log contains the information: * * - process_id => UUID string * - status => running|succeed|failed * - start_message => string|null * - started_at => \DateTime::ISO8601 formatted * - finished_at => \DateTime::ISO8601 formatted * * @param int $offset * @param int $limit * @return array */ public function getLastLoggedProcesses($offset = 0, $limit = 10) { Assertion::integer($offset); Assertion::integer($limit); $query = $this->connection->createQueryBuilder(); $query->select('*')->from(Tables::PROCESS_LOG)->orderBy('started_at', 'DESC')->setFirstResult($offset)->setMaxResults($limit); return $query->execute()->fetchAll(); }
/** * @param $page * @param $itemsPerPage * * @throws \InvalidArgumentException * * @return Item[] */ public function paginate($page, $itemsPerPage) { Assertion::integer($page, 'Page should be an integer'); Assertion::integer($itemsPerPage, 'ItemsPerPage should be an integer'); Assertion::greaterThan($page, 0, 'Page should be grater than 0'); Assertion::greaterThan($itemsPerPage, 0, 'ItemsPerPage should be grater than 0'); return array_slice($this->findBy([], ['price' => 'ASC']), $page - 1, $itemsPerPage); }
/** * StorableJWKSet constructor. * * @param string $filename * @param array $parameters * @param int $nb_keys */ public function __construct($filename, array $parameters, $nb_keys) { Assertion::integer($nb_keys, 'The key set must contain at least one key.'); Assertion::greaterThan($nb_keys, 0, 'The key set must contain at least one key.'); $this->setFilename($filename); $this->parameters = $parameters; $this->nb_keys = $nb_keys; }
public function __construct($width, $height, Fields $fields) { Assertion::integer($width); Assertion::integer($height); $this->width = $width; $this->height = $height; $this->fields = $fields; }
protected function guardRequiredState() { parent::guardRequiredState(); Assertion::regex($this->aggregate_root_type, '#^([a-z][a-z_-]+(?<![_-])\\.){2}[a-z][a-z_-]+(?<![_-])$#'); Assertion::integer($this->seq_number); Assertion::isInstanceOf($this->embedded_entity_events, EmbeddedEntityEventList::CLASS); Assertion::regex($this->aggregate_root_identifier, '/[\\w\\.\\-_]{1,128}\\-\\w{8}\\-\\w{4}\\-\\w{4}\\-\\w{4}\\-\\w{12}\\-\\w{2}_\\w{2}\\-\\d+/'); }
/** * @param WorkflowRunId $aWorkflowRunId * @param ActionId $anActionId * @param Name $anActionName * @param Arguments $anArguments * @param int $aResultSetCount */ public function __construct(WorkflowRunId $aWorkflowRunId, ActionId $anActionId, Name $anActionName, Arguments $anArguments, $aResultSetCount) { Assertion::integer($aResultSetCount, "ResultSetCount must be an integer"); $this->workflowRunId = $aWorkflowRunId; $this->actionId = $anActionId; $this->actionName = $anActionName; $this->actionArguments = $anArguments; $this->resultSetCount = $aResultSetCount; }
/** * @param int $id * @param string $action * @param string $object */ public function __construct($id, $action, $object) { Assertion::integer($id); Assertion::string($action); Assertion::string($object); $this->id = $id; $this->action = $action; $this->object = $object; }
public function __construct(array $results = [], $total_count = 0, $offset = 0, $cursor = null) { Assertion::integer($total_count); Assertion::integer($offset); $this->results = $results; $this->total_count = $total_count; $this->offset = $offset; $this->cursor = $cursor; }
/** * @param UuidInterface $id * @param int $amount * @param Product $product */ public function __construct(UuidInterface $id, $amount, Product $product) { Assertion::uuid($id->toString()); Assertion::integer($amount); Assertion::notEmpty($product); $this->id = $id; $this->amount = $amount; $this->product = $product; }
/** * @param int $current * @param int $real * @param int $peak */ public function __construct($peak, $real, $final) { Assertion::integer($peak, 'Peak memory must be an integer, got "%s"'); Assertion::integer($real, 'Real memory must be an integer, got "%s"'); Assertion::integer($final, 'Final memory must be an integer, got "%s"'); $this->peak = $peak; $this->real = $real; $this->final = $final; }
/** * {@inheritdoc} */ public function checkJWS(Object\JWSInterface $jws, $signature) { Assertion::integer($signature); Assertion::lessThan($signature, $jws->countSignatures()); $checked_claims = $this->checkJWT($jws); $protected_headers = $jws->getSignature($signature)->getProtectedHeaders(); $headers = $jws->getSignature($signature)->getHeaders(); $this->checkHeaders($protected_headers, $headers, $checked_claims); }
public function __construct(array $parameters, $offset, $limit) { Assertion::integer($offset); Assertion::min($offset, 0); Assertion::integer($limit); Assertion::min($limit, 1); $this->parameters = $parameters; $this->offset = $offset; $this->limit = $limit; }
/** * @param Connection $dbalConnection * @param MessageFactory $messageFactory * @param MessageConverter $messageConverter * @param PayloadSerializer $payloadSerializer * @param array $streamTableMap * @param int $loadBatchSize */ public function __construct(Connection $dbalConnection, MessageFactory $messageFactory, MessageConverter $messageConverter, PayloadSerializer $payloadSerializer, array $streamTableMap = [], $loadBatchSize = 10000) { Assertion::integer($loadBatchSize); $this->connection = $dbalConnection; $this->messageFactory = $messageFactory; $this->messageConverter = $messageConverter; $this->payloadSerializer = $payloadSerializer; $this->streamTableMap = $streamTableMap; $this->loadBatchSize = $loadBatchSize; }
/** * @param QueryBuilder $queryBuilder * @param MessageFactory $messageFactory * @param PayloadSerializer $payloadSerializer * @param array $metadata * @param int $batchSize */ public function __construct(QueryBuilder $queryBuilder, MessageFactory $messageFactory, PayloadSerializer $payloadSerializer, array $metadata, $batchSize = 10000) { Assertion::integer($batchSize); $this->queryBuilder = $queryBuilder; $this->messageFactory = $messageFactory; $this->payloadSerializer = $payloadSerializer; $this->metadata = $metadata; $this->batchSize = $batchSize; $this->rewind(); }
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; }
/** * Constructor * * @param AMQPQueue[] $queues * @param float $idleTimeout in seconds * @param int $waitTimeout in microseconds * @param callable $deliveryCallback, * @param callable|null $flushCallback, * @param callable|null $errorCallback * @throws Exception\InvalidArgumentException */ public function __construct(array $queues, $idleTimeout, $waitTimeout, callable $deliveryCallback, callable $flushCallback = null, callable $errorCallback = null) { Assertion::float($idleTimeout); Assertion::integer($waitTimeout); if (function_exists('pcntl_signal_dispatch')) { $this->usePcntlSignalDispatch = true; } if (function_exists('pcntl_signal')) { pcntl_signal(SIGTERM, [$this, 'shutdown']); pcntl_signal(SIGINT, [$this, 'shutdown']); pcntl_signal(SIGHUP, [$this, 'shutdown']); } if (empty($queues)) { throw new Exception\InvalidArgumentException('No queues given'); } $q = []; foreach ($queues as $queue) { if (!$queue instanceof AMQPQueue) { throw new Exception\InvalidArgumentException('Queue must be an instance of AMQPQueue, ' . is_object($queue) ? get_class($queue) : gettype($queue) . ' given'); } if (null === $this->blockSize) { $this->blockSize = $queue->getChannel()->getPrefetchCount(); } $q[] = $queue; } $this->idleTimeout = (double) $idleTimeout; $this->waitTimeout = (int) $waitTimeout; $this->queues = new InfiniteIterator(new ArrayIterator($q)); }