Skip to content
Closed
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
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: php
php:
- 5.6
- 7.0
- hhvm

Expand All @@ -20,7 +19,7 @@ before_script:
# Install Nette Tester & Code Checker
- travis_retry composer install --no-interaction --prefer-dist
- travis_retry composer create-project nette/code-checker temp/code-checker ~2.5 --no-interaction

sudo: false

cache:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
],
"require": {
"php": ">=5.6.0"
"php": ">=7.0.0"
},
"require-dev": {
"nette/tester": "~1.0"
Expand Down
24 changes: 13 additions & 11 deletions src/Iterators/CachingIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/

declare(strict_types = 1);

namespace Nette\Iterators;

use Nette;
Expand Down Expand Up @@ -56,7 +58,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 @@ -67,7 +69,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 @@ -77,7 +79,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 @@ -87,7 +89,7 @@ public function isEmpty()
* Is the counter odd?
* @return bool
*/
public function isOdd()
public function isOdd(): bool
{
return $this->counter % 2 === 1;
}
Expand All @@ -97,7 +99,7 @@ public function isOdd()
* Is the counter even?
* @return bool
*/
public function isEven()
public function isEven(): bool
{
return $this->counter % 2 === 0;
}
Expand All @@ -107,7 +109,7 @@ public function isEven()
* Returns the counter.
* @return int
*/
public function getCounter()
public function getCounter(): int
{
return $this->counter;
}
Expand All @@ -117,7 +119,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 Expand Up @@ -195,7 +197,7 @@ public function __call($name, $args)
* @return mixed property value
* @throws Nette\MemberAccessException if the property is not defined.
*/
public function &__get($name)
public function &__get(string $name)
{
return ObjectMixin::get($this, $name);
}
Expand All @@ -208,7 +210,7 @@ public function &__get($name)
* @return void
* @throws Nette\MemberAccessException if the property is not defined or is read-only
*/
public function __set($name, $value)
public function __set(string $name, $value)
{
ObjectMixin::set($this, $name, $value);
}
Expand All @@ -219,7 +221,7 @@ public function __set($name, $value)
* @param string property name
* @return bool
*/
public function __isset($name)
public function __isset(string $name): bool
{
return ObjectMixin::has($this, $name);
}
Expand All @@ -231,7 +233,7 @@ public function __isset($name)
* @return void
* @throws Nette\MemberAccessException
*/
public function __unset($name)
public function __unset(string $name)
{
ObjectMixin::remove($this, $name);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Iterators/Mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/

declare(strict_types = 1);

namespace Nette\Iterators;

use Nette;
Expand Down
10 changes: 6 additions & 4 deletions src/Utils/ArrayHash.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/

declare(strict_types = 1);

namespace Nette\Utils;

use Nette;
Expand All @@ -19,9 +21,9 @@ class ArrayHash extends \stdClass implements \ArrayAccess, \Countable, \Iterator
/**
* @param array to wrap
* @param bool
* @return self
* @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 @@ -39,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($this);
}
Expand All @@ -49,7 +51,7 @@ public function getIterator()
* Returns items count.
* @return int
*/
public function count()
public function count(): int
{
return count((array) $this);
}
Expand Down
6 changes: 4 additions & 2 deletions src/Utils/ArrayList.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/

declare(strict_types = 1);

namespace Nette\Utils;

use Nette;
Expand All @@ -22,7 +24,7 @@ class ArrayList extends Nette\Object implements \ArrayAccess, \Countable, \Itera
* Returns an iterator over all items.
* @return \ArrayIterator
*/
public function getIterator()
public function getIterator(): \ArrayIterator
{
return new \ArrayIterator($this->list);
}
Expand All @@ -32,7 +34,7 @@ public function getIterator()
* Returns items count.
* @return int
*/
public function count()
public function count(): int
{
return count($this->list);
}
Expand Down
12 changes: 7 additions & 5 deletions src/Utils/Arrays.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/

declare(strict_types = 1);

namespace Nette\Utils;

use Nette;
Expand Down Expand Up @@ -73,7 +75,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 @@ -138,7 +140,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 @@ -148,7 +150,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 @@ -163,7 +165,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 @@ -225,7 +227,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
16 changes: 9 additions & 7 deletions src/Utils/Callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/

declare(strict_types = 1);

namespace Nette\Utils;

use Nette;
Expand All @@ -21,7 +23,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 @@ -78,9 +80,9 @@ 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, $onError)
{
$prev = set_error_handler(function ($severity, $message, $file) use ($onError, & $prev, $function) {
$prev = set_error_handler(function (int $severity, string $message, string $file) use ($onError, & $prev, $function) {
if ($file === '' && defined('HHVM_VERSION')) { // https://github.com/facebook/hhvm/issues/4625
$file = func_get_arg(5)[1]['file'];
}
Expand Down Expand Up @@ -108,7 +110,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 +125,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 @@ -166,7 +168,7 @@ public static function toReflection($callable)
/**
* @return bool
*/
public static function isStatic($callable)
public static function isStatic($callable): bool
{
return is_array($callable) ? is_string($callable[0]) : is_string($callable);
}
Expand All @@ -177,7 +179,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
12 changes: 7 additions & 5 deletions src/Utils/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/

declare(strict_types = 1);

namespace Nette\Utils;

use Nette;
Expand Down Expand Up @@ -39,7 +41,7 @@ class DateTime extends \DateTime implements \JsonSerializable
* @param string|int|\DateTimeInterface
* @return self
*/
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'), $time->getTimezone());
Expand All @@ -59,7 +61,7 @@ public static function from($time)
/**
* @return string
*/
public function __toString()
public function __toString(): string
{
return $this->format('Y-m-d H:i:s');
}
Expand All @@ -69,7 +71,7 @@ public function __toString()
* @param string
* @return self
*/
public function modifyClone($modify = '')
public function modifyClone(string $modify = ''): self
{
$dolly = clone $this;
return $modify ? $dolly->modify($modify) : $dolly;
Expand All @@ -80,7 +82,7 @@ public function modifyClone($modify = '')
* @param int
* @return self
*/
public function setTimestamp($timestamp)
public function setTimestamp($timestamp): self
{
$zone = $this->getTimezone();
$this->__construct('@' . $timestamp);
Expand Down Expand Up @@ -126,7 +128,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
Loading