Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/Iterators/CachingIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function __construct($iterator)
* @param int grid width
* @return bool
*/
public function isFirst($width = NULL)
public function isFirst(int $width = NULL): bool
{
return $this->counter === 1 || ($width && $this->counter !== 0 && (($this->counter - 1) % $width) === 0);
}
Expand All @@ -70,7 +70,7 @@ public function isFirst($width = NULL)
* @param int grid width
* @return bool
*/
public function isLast($width = NULL)
public function isLast(int $width = NULL): bool
{
return !$this->hasNext() || ($width && ($this->counter % $width) === 0);
}
Expand All @@ -80,7 +80,7 @@ public function isLast($width = NULL)
* Is the iterator empty?
* @return bool
*/
public function isEmpty()
public function isEmpty(): bool
{
return $this->counter === 0;
}
Expand All @@ -90,7 +90,7 @@ public function isEmpty()
* Is the counter odd?
* @return bool
*/
public function isOdd()
public function isOdd(): bool
{
return $this->counter % 2 === 1;
}
Expand All @@ -100,7 +100,7 @@ public function isOdd()
* Is the counter even?
* @return bool
*/
public function isEven()
public function isEven(): bool
{
return $this->counter % 2 === 0;
}
Expand All @@ -110,7 +110,7 @@ public function isEven()
* Returns the counter.
* @return int
*/
public function getCounter()
public function getCounter(): int
{
return $this->counter;
}
Expand All @@ -120,7 +120,7 @@ public function getCounter()
* Returns the count of elements.
* @return int
*/
public function count()
public function count(): int
{
$inner = $this->getInnerIterator();
if ($inner instanceof \Countable) {
Expand Down
8 changes: 4 additions & 4 deletions src/Utils/ArrayHash.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ArrayHash extends \stdClass implements \ArrayAccess, \Countable, \Iterator
* @param bool
* @return static
*/
public static function from($arr, $recursive = TRUE)
public static function from(array $arr, bool $recursive = TRUE): self
{
$obj = new static;
foreach ($arr as $key => $value) {
Expand All @@ -41,7 +41,7 @@ public static function from($arr, $recursive = TRUE)
* Returns an iterator over all items.
* @return \RecursiveArrayIterator
*/
public function getIterator()
public function getIterator(): \RecursiveArrayIterator
{
return new \RecursiveArrayIterator((array) $this);
}
Expand All @@ -51,7 +51,7 @@ public function getIterator()
* Returns items count.
* @return int
*/
public function count()
public function count(): int
{
return count((array) $this);
}
Expand Down Expand Up @@ -84,7 +84,7 @@ public function offsetGet($key)
* Determines whether a item exists.
* @return bool
*/
public function offsetExists($key)
public function offsetExists($key): bool
{
return isset($this->$key);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Utils/ArrayList.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ArrayList implements \ArrayAccess, \Countable, \IteratorAggregate
* Returns an iterator over all items.
* @return \ArrayIterator
*/
public function getIterator()
public function getIterator(): \ArrayIterator
{
return new \ArrayIterator($this->list);
}
Expand All @@ -36,7 +36,7 @@ public function getIterator()
* Returns items count.
* @return int
*/
public function count()
public function count(): int
{
return count($this->list);
}
Expand Down Expand Up @@ -83,7 +83,7 @@ public function offsetGet($index)
* @param int
* @return bool
*/
public function offsetExists($index)
public function offsetExists($index): bool
{
return $index >= 0 && $index < count($this->list);
}
Expand Down
10 changes: 5 additions & 5 deletions src/Utils/Arrays.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static function &getRef(array &$arr, $key)
* Recursively appends elements of remaining keys from the second array to the first.
* @return array
*/
public static function mergeTree(array $arr1, array $arr2)
public static function mergeTree(array $arr1, array $arr2): array
{
$res = $arr1 + $arr2;
foreach (array_intersect_key($arr1, $arr2) as $k => $v) {
Expand Down Expand Up @@ -133,7 +133,7 @@ public static function renameKey(array &$arr, $oldKey, $newKey)
* Returns array entries that match the pattern.
* @return array
*/
public static function grep(array $arr, $pattern, $flags = 0)
public static function grep(array $arr, string $pattern, int $flags = 0): array
{
return Strings::pcre('preg_grep', [$pattern, $arr, $flags]);
}
Expand All @@ -143,7 +143,7 @@ public static function grep(array $arr, $pattern, $flags = 0)
* Returns flattened array.
* @return array
*/
public static function flatten(array $arr, $preserveKeys = FALSE)
public static function flatten(array $arr, bool $preserveKeys = FALSE): array
{
$res = [];
$cb = $preserveKeys
Expand All @@ -158,7 +158,7 @@ public static function flatten(array $arr, $preserveKeys = FALSE)
* Finds whether a variable is a zero-based integer indexed array.
* @return bool
*/
public static function isList($value)
public static function isList($value): bool
{
return is_array($value) && (!$value || array_keys($value) === range(0, count($value) - 1));
}
Expand Down Expand Up @@ -220,7 +220,7 @@ public static function associate(array $arr, $path)
* Normalizes to associative array.
* @return array
*/
public static function normalize(array $arr, $filling = NULL)
public static function normalize(array $arr, $filling = NULL): array
{
$res = [];
foreach ($arr as $k => $v) {
Expand Down
12 changes: 6 additions & 6 deletions src/Utils/Callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Callback
* @param string method
* @return \Closure
*/
public static function closure($callable, $m = NULL)
public static function closure($callable, string $m = NULL): \Closure
{
if ($m !== NULL) {
$callable = [$callable, $m];
Expand Down Expand Up @@ -82,7 +82,7 @@ public static function invokeArgs($callable, array $args = [])
* @param string
* @return mixed
*/
public static function invokeSafe($function, array $args, $onError)
public static function invokeSafe(string $function, array $args, callable $onError)
{
$prev = set_error_handler(function ($severity, $message, $file) use ($onError, &$prev, $function) {
if ($file === '' && defined('HHVM_VERSION')) { // https://github.com/facebook/hhvm/issues/4625
Expand All @@ -108,7 +108,7 @@ public static function invokeSafe($function, array $args, $onError)
/**
* @return callable
*/
public static function check($callable, $syntax = FALSE)
public static function check($callable, bool $syntax = FALSE)
{
if (!is_callable($callable, $syntax)) {
throw new Nette\InvalidArgumentException($syntax
Expand All @@ -123,7 +123,7 @@ public static function check($callable, $syntax = FALSE)
/**
* @return string
*/
public static function toString($callable)
public static function toString($callable): string
{
if ($callable instanceof \Closure) {
$inner = self::unwrap($callable);
Expand Down Expand Up @@ -163,7 +163,7 @@ public static function toReflection($callable)
/**
* @return bool
*/
public static function isStatic($callable)
public static function isStatic(callable $callable): bool
{
return is_array($callable) ? is_string($callable[0]) : is_string($callable);
}
Expand All @@ -174,7 +174,7 @@ public static function isStatic($callable)
* @internal
* @return callable
*/
public static function unwrap(\Closure $closure)
public static function unwrap(\Closure $closure): callable
{
$r = new \ReflectionFunction($closure);
if (substr($r->getName(), -1) === '}') {
Expand Down
14 changes: 7 additions & 7 deletions src/Utils/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class DateTime extends \DateTime implements \JsonSerializable
* @param string|int|\DateTimeInterface
* @return static
*/
public static function from($time)
public static function from($time): self
{
if ($time instanceof \DateTimeInterface) {
return new static($time->format('Y-m-d H:i:s.u'), $time->getTimezone());
Expand All @@ -64,7 +64,7 @@ public static function from($time)
* Creates DateTime object.
* @return static
*/
public static function fromParts($year, $month, $day, $hour = 0, $minute = 0, $second = 0)
public static function fromParts(int $year, int $month, int $day, int $hour = 0, int $minute = 0, float $second = 0)
{
$s = sprintf("%04d-%02d-%02d %02d:%02d:%02.5f", $year, $month, $day, $hour, $minute, $second);
if (!checkdate($month, $day, $year) || $hour < 0 || $hour > 23 || $minute < 0 || $minute > 59 || $second < 0 || $second >= 60) {
Expand All @@ -77,7 +77,7 @@ public static function fromParts($year, $month, $day, $hour = 0, $minute = 0, $s
/**
* @return string
*/
public function __toString()
public function __toString(): string
{
return $this->format('Y-m-d H:i:s');
}
Expand All @@ -87,18 +87,18 @@ public function __toString()
* @param string
* @return static
*/
public function modifyClone($modify = '')
public function modifyClone(string $modify = ''): self
{
$dolly = clone $this;
return $modify ? $dolly->modify($modify) : $dolly;
}


/**
* @param int
* @param int|string
* @return static
*/
public function setTimestamp($timestamp)
public function setTimestamp($timestamp): self
{
$zone = $this->getTimezone();
$this->__construct('@' . $timestamp);
Expand Down Expand Up @@ -144,7 +144,7 @@ public static function createFromFormat($format, $time, $timezone = NULL)
* Returns JSON representation in ISO 8601 (used by JavaScript).
* @return string
*/
public function jsonSerialize()
public function jsonSerialize(): string
{
return $this->format('c');
}
Expand Down
14 changes: 7 additions & 7 deletions src/Utils/FileSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class FileSystem
* @return void
* @throws Nette\IOException
*/
public static function createDir($dir, $mode = 0777)
public static function createDir(string $dir, int $mode = 0777)
{
if (!is_dir($dir) && !@mkdir($dir, $mode, TRUE) && !is_dir($dir)) { // @ - dir may already exist
throw new Nette\IOException("Unable to create directory '$dir'. " . error_get_last()['message']);
Expand All @@ -37,7 +37,7 @@ public static function createDir($dir, $mode = 0777)
* @return void
* @throws Nette\IOException
*/
public static function copy($source, $dest, $overwrite = TRUE)
public static function copy(string $source, string $dest, bool $overwrite = TRUE)
{
if (stream_is_local($source) && !file_exists($source)) {
throw new Nette\IOException("File or directory '$source' not found.");
Expand Down Expand Up @@ -72,7 +72,7 @@ public static function copy($source, $dest, $overwrite = TRUE)
* @return void
* @throws Nette\IOException
*/
public static function delete($path)
public static function delete(string $path)
{
if (is_file($path) || is_link($path)) {
$func = DIRECTORY_SEPARATOR === '\\' && is_dir($path) ? 'rmdir' : 'unlink';
Expand All @@ -97,7 +97,7 @@ public static function delete($path)
* @throws Nette\IOException
* @throws Nette\InvalidStateException if the target file or directory already exist
*/
public static function rename($name, $newName, $overwrite = TRUE)
public static function rename(string $name, string $newName, bool $overwrite = TRUE)
{
if (!$overwrite && file_exists($newName)) {
throw new Nette\InvalidStateException("File or directory '$newName' already exists.");
Expand All @@ -120,7 +120,7 @@ public static function rename($name, $newName, $overwrite = TRUE)
* @return string
* @throws Nette\IOException
*/
public static function read($file)
public static function read(string $file): string
{
$content = @file_get_contents($file); // @ is escalated to exception
if ($content === FALSE) {
Expand All @@ -135,7 +135,7 @@ public static function read($file)
* @return void
* @throws Nette\IOException
*/
public static function write($file, $content, $mode = 0666)
public static function write(string $file, string $content, int $mode = 0666)
{
static::createDir(dirname($file));
if (@file_put_contents($file, $content) === FALSE) { // @ is escalated to exception
Expand All @@ -151,7 +151,7 @@ public static function write($file, $content, $mode = 0666)
* Is path absolute?
* @return bool
*/
public static function isAbsolute($path)
public static function isAbsolute(string $path): bool
{
return (bool) preg_match('#([a-z]:)?[/\\\\]|[a-z][a-z0-9+.-]*://#Ai', $path);
}
Expand Down
Loading