From a1adb6fd02a6557b7b96363ba973477b319d824a Mon Sep 17 00:00:00 2001 From: Jaroslav Hanslik Date: Fri, 14 Aug 2015 21:52:40 +0200 Subject: [PATCH] PHP7 scalar and return type hints support --- .travis.yml | 3 +- composer.json | 2 +- src/Iterators/CachingIterator.php | 24 +++--- src/Iterators/Mapper.php | 2 + src/Utils/ArrayHash.php | 10 ++- src/Utils/ArrayList.php | 6 +- src/Utils/Arrays.php | 12 +-- src/Utils/Callback.php | 16 ++-- src/Utils/DateTime.php | 12 +-- src/Utils/FileSystem.php | 14 ++-- src/Utils/Html.php | 60 +++++++-------- src/Utils/IHtmlString.php | 4 +- src/Utils/ITranslator.php | 4 +- src/Utils/Image.php | 42 ++++++----- src/Utils/Json.php | 6 +- src/Utils/Object.php | 14 ++-- src/Utils/ObjectMixin.php | 26 ++++--- src/Utils/Paginator.php | 34 +++++---- src/Utils/Random.php | 4 +- src/Utils/Strings.php | 74 ++++++++++--------- src/Utils/Validators.php | 34 +++++---- src/Utils/exceptions.php | 2 + tests/Iterators/CachingIterator.basic.phpt | 2 + .../Iterators/CachingIterator.construct.phpt | 2 + tests/Iterators/CachingIterator.width.phpt | 2 + tests/Iterators/Mapper.phpt | 2 + tests/Utils/ArrayHash.phpt | 2 + tests/Utils/ArrayList.phpt | 2 + tests/Utils/Arrays.associate().error.phpt | 2 + tests/Utils/Arrays.associate().phpt | 2 + tests/Utils/Arrays.flatten().phpt | 2 + tests/Utils/Arrays.get().phpt | 2 + tests/Utils/Arrays.getRef().phpt | 2 + tests/Utils/Arrays.grep().errors.phpt | 2 + tests/Utils/Arrays.grep().phpt | 2 + tests/Utils/Arrays.insertBefore().phpt | 2 + tests/Utils/Arrays.isList.phpt | 2 + tests/Utils/Arrays.normalize.phpt | 2 + tests/Utils/Arrays.pick().phpt | 2 + tests/Utils/Arrays.renameKey().phpt | 2 + tests/Utils/Arrays.searchKey().phpt | 2 + tests/Utils/Callback.check.phpt | 2 + tests/Utils/Callback.closure.phpt | 2 + tests/Utils/Callback.invoke.phpt | 2 + tests/Utils/Callback.invokeSafe.phpt | 2 + tests/Utils/DateTime.JSON.phpt | 2 + tests/Utils/DateTime.createFromFormat.phpt | 2 + tests/Utils/DateTime.from.phpt | 2 + tests/Utils/FileSystem.phpt | 2 + tests/Utils/Html.basic.phpt | 2 + tests/Utils/Html.children.phpt | 2 + tests/Utils/Html.construct.phpt | 2 + tests/Utils/Html.data.phpt | 2 + tests/Utils/Html.style.phpt | 2 + tests/Utils/Image.alpha1.phpt | 2 + tests/Utils/Image.clone.phpt | 2 + tests/Utils/Image.drawing.phpt | 2 + tests/Utils/Image.factories.phpt | 2 + tests/Utils/Image.resize.phpt | 2 + tests/Utils/Image.save.phpt | 2 + tests/Utils/Image.send.phpt | 2 + tests/Utils/Json.decode().phpt | 2 + tests/Utils/Json.encode().phpt | 2 + tests/Utils/Object.arrayProperty.phpt | 2 + tests/Utils/Object.closureProperty.phpt | 2 + tests/Utils/Object.events.phpt | 2 + tests/Utils/Object.extensionMethod.phpt | 2 + .../Object.extensionMethodViaInterface.phpt | 2 + tests/Utils/Object.magicMethod.errors.phpt | 2 + .../Utils/Object.magicMethod.inheritance.phpt | 2 + tests/Utils/Object.magicMethod.phpt | 2 + tests/Utils/Object.magicMethod.types.phpt | 2 + tests/Utils/Object.methodGetter.phpt | 2 + tests/Utils/Object.property.phpt | 2 + tests/Utils/Object.referenceProperty.phpt | 2 + tests/Utils/Object.reflection.phpt | 2 + tests/Utils/Object.undeclaredMethod.phpt | 2 + tests/Utils/Object.unsetProperty.phpt | 2 + tests/Utils/ObjectMixin.checkType().phpt | 2 + tests/Utils/Paginator.phpt | 2 + tests/Utils/Random.generate().no-mcrypt.phpt | 2 + tests/Utils/Random.generate().no-openssl.phpt | 2 + tests/Utils/Random.generate().phpt | 2 + .../Strings.Regexp.errors.backtrack.phpt | 2 + .../Strings.Regexp.errors.compilation.phpt | 2 + tests/Utils/Strings.Regexp.errors.utf8.phpt | 2 + tests/Utils/Strings.after().phpt | 2 + tests/Utils/Strings.before().phpt | 2 + tests/Utils/Strings.checkEncoding().phpt | 2 + tests/Utils/Strings.chr().phpt | 2 + tests/Utils/Strings.compare().phpt | 2 + tests/Utils/Strings.convertCase.phpt | 2 + tests/Utils/Strings.endsWith().phpt | 6 +- tests/Utils/Strings.findPrefix().phpt | 2 + tests/Utils/Strings.fixEncoding().phpt | 2 + tests/Utils/Strings.indent().phpt | 2 + tests/Utils/Strings.indexOf().phpt | 2 + tests/Utils/Strings.length().phpt | 2 + tests/Utils/Strings.match().phpt | 2 + tests/Utils/Strings.matchAll().phpt | 2 + tests/Utils/Strings.normalize().phpt | 2 + tests/Utils/Strings.normalizeNewLines().phpt | 2 + tests/Utils/Strings.pad.phpt | 2 + tests/Utils/Strings.random().phpt | 2 + .../Strings.replace().errors.callback.phpt | 2 + tests/Utils/Strings.replace().php53.phpt | 2 + tests/Utils/Strings.replace().phpt | 2 + tests/Utils/Strings.reverse().phpt | 2 + tests/Utils/Strings.split().phpt | 2 + tests/Utils/Strings.startsWith().phpt | 6 +- tests/Utils/Strings.substring().phpt | 2 + tests/Utils/Strings.toAscii().phpt | 2 + tests/Utils/Strings.trim().phpt | 2 + tests/Utils/Strings.truncate().phpt | 2 + tests/Utils/Strings.webalize().phpt | 2 + tests/Utils/Validators.assert().phpt | 2 + tests/Utils/Validators.assertField().phpt | 2 + tests/Utils/Validators.is().phpt | 2 + tests/Utils/Validators.isInRange().phpt | 2 + tests/bootstrap.php | 2 + 120 files changed, 424 insertions(+), 185 deletions(-) diff --git a/.travis.yml b/.travis.yml index dd0439bd0..ac14ed078 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: php php: - - 5.6 - 7.0 - hhvm @@ -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: diff --git a/composer.json b/composer.json index 900673207..038692466 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ } ], "require": { - "php": ">=5.6.0" + "php": ">=7.0.0" }, "require-dev": { "nette/tester": "~1.0" diff --git a/src/Iterators/CachingIterator.php b/src/Iterators/CachingIterator.php index 9d25e5216..5b9e9f66e 100644 --- a/src/Iterators/CachingIterator.php +++ b/src/Iterators/CachingIterator.php @@ -5,6 +5,8 @@ * Copyright (c) 2004 David Grudl (https://davidgrudl.com) */ +declare(strict_types = 1); + namespace Nette\Iterators; use Nette; @@ -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); } @@ -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); } @@ -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; } @@ -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; } @@ -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; } @@ -107,7 +109,7 @@ public function isEven() * Returns the counter. * @return int */ - public function getCounter() + public function getCounter(): int { return $this->counter; } @@ -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) { @@ -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); } @@ -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); } @@ -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); } @@ -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); } diff --git a/src/Iterators/Mapper.php b/src/Iterators/Mapper.php index 16f1faf28..f849c21d6 100644 --- a/src/Iterators/Mapper.php +++ b/src/Iterators/Mapper.php @@ -5,6 +5,8 @@ * Copyright (c) 2004 David Grudl (https://davidgrudl.com) */ +declare(strict_types = 1); + namespace Nette\Iterators; use Nette; diff --git a/src/Utils/ArrayHash.php b/src/Utils/ArrayHash.php index 1e00bbb8b..212febdaf 100644 --- a/src/Utils/ArrayHash.php +++ b/src/Utils/ArrayHash.php @@ -5,6 +5,8 @@ * Copyright (c) 2004 David Grudl (https://davidgrudl.com) */ +declare(strict_types = 1); + namespace Nette\Utils; use Nette; @@ -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) { @@ -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); } @@ -49,7 +51,7 @@ public function getIterator() * Returns items count. * @return int */ - public function count() + public function count(): int { return count((array) $this); } diff --git a/src/Utils/ArrayList.php b/src/Utils/ArrayList.php index 056eac232..e5bfeea81 100644 --- a/src/Utils/ArrayList.php +++ b/src/Utils/ArrayList.php @@ -5,6 +5,8 @@ * Copyright (c) 2004 David Grudl (https://davidgrudl.com) */ +declare(strict_types = 1); + namespace Nette\Utils; use Nette; @@ -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); } @@ -32,7 +34,7 @@ public function getIterator() * Returns items count. * @return int */ - public function count() + public function count(): int { return count($this->list); } diff --git a/src/Utils/Arrays.php b/src/Utils/Arrays.php index 547d91331..67db65fe9 100644 --- a/src/Utils/Arrays.php +++ b/src/Utils/Arrays.php @@ -5,6 +5,8 @@ * Copyright (c) 2004 David Grudl (https://davidgrudl.com) */ +declare(strict_types = 1); + namespace Nette\Utils; use Nette; @@ -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) { @@ -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]); } @@ -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 @@ -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)); } @@ -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) { diff --git a/src/Utils/Callback.php b/src/Utils/Callback.php index 40c763cd1..d0eac6692 100644 --- a/src/Utils/Callback.php +++ b/src/Utils/Callback.php @@ -5,6 +5,8 @@ * Copyright (c) 2004 David Grudl (https://davidgrudl.com) */ +declare(strict_types = 1); + namespace Nette\Utils; use Nette; @@ -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]; @@ -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']; } @@ -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 @@ -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); @@ -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); } @@ -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) === '}') { diff --git a/src/Utils/DateTime.php b/src/Utils/DateTime.php index f87efa5a7..6ebe8a60f 100644 --- a/src/Utils/DateTime.php +++ b/src/Utils/DateTime.php @@ -5,6 +5,8 @@ * Copyright (c) 2004 David Grudl (https://davidgrudl.com) */ +declare(strict_types = 1); + namespace Nette\Utils; use Nette; @@ -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()); @@ -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'); } @@ -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; @@ -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); @@ -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'); } diff --git a/src/Utils/FileSystem.php b/src/Utils/FileSystem.php index 62d9ad769..4d0b739f0 100644 --- a/src/Utils/FileSystem.php +++ b/src/Utils/FileSystem.php @@ -5,6 +5,8 @@ * Copyright (c) 2004 David Grudl (https://davidgrudl.com) */ +declare(strict_types = 1); + namespace Nette\Utils; use Nette; @@ -21,7 +23,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)) { // intentionally @; not atomic throw new Nette\IOException("Unable to create directory '$dir'."); @@ -34,7 +36,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."); @@ -69,7 +71,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'; @@ -94,7 +96,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."); @@ -117,7 +119,7 @@ public static function rename($name, $newName, $overwrite = TRUE) * @return void * @throws Nette\IOException */ - public static function write($file, $content, $mode = 0666) + public static function write(string $file, $content, int $mode = 0666) { static::createDir(dirname($file)); if (@file_put_contents($file, $content) === FALSE) { // @ is escalated to exception @@ -133,7 +135,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); } diff --git a/src/Utils/Html.php b/src/Utils/Html.php index 1388bb62f..3a120f80e 100644 --- a/src/Utils/Html.php +++ b/src/Utils/Html.php @@ -5,6 +5,8 @@ * Copyright (c) 2004 David Grudl (https://davidgrudl.com) */ +declare(strict_types = 1); + namespace Nette\Utils; use Nette; @@ -52,7 +54,7 @@ class Html extends Nette\Object implements \ArrayAccess, \Countable, \IteratorAg * @param array|string element's attributes or plain text content * @return self */ - public static function el($name = NULL, $attrs = NULL) + public static function el(string $name = NULL, $attrs = NULL): self { $el = new static; $parts = explode(' ', (string) $name, 2); @@ -82,7 +84,7 @@ public static function el($name = NULL, $attrs = NULL) * @return self * @throws Nette\InvalidArgumentException */ - public function setName($name, $isEmpty = NULL) + public function setName(string $name, bool $isEmpty = NULL): self { if ($name !== NULL && !is_string($name)) { throw new Nette\InvalidArgumentException(sprintf('Name must be string or NULL, %s given.', gettype($name))); @@ -98,7 +100,7 @@ public function setName($name, $isEmpty = NULL) * Returns element's name. * @return string */ - public function getName() + public function getName(): string { return $this->name; } @@ -108,7 +110,7 @@ public function getName() * Is element empty? * @return bool */ - public function isEmpty() + public function isEmpty(): bool { return $this->isEmpty; } @@ -119,7 +121,7 @@ public function isEmpty() * @param array * @return self */ - public function addAttributes(array $attrs) + public function addAttributes(array $attrs): self { $this->attrs = array_merge($this->attrs, $attrs); return $this; @@ -132,7 +134,7 @@ public function addAttributes(array $attrs) * @param mixed HTML attribute value * @return void */ - public function __set($name, $value) + public function __set(string $name, $value) { $this->attrs[$name] = $value; } @@ -143,7 +145,7 @@ public function __set($name, $value) * @param string HTML attribute name * @return mixed HTML attribute value */ - public function &__get($name) + public function &__get(string $name) { return $this->attrs[$name]; } @@ -154,7 +156,7 @@ public function &__get($name) * @param string HTML attribute name * @return bool */ - public function __isset($name) + public function __isset(string $name): bool { return isset($this->attrs[$name]); } @@ -165,7 +167,7 @@ public function __isset($name) * @param string HTML attribute name * @return void */ - public function __unset($name) + public function __unset(string $name) { unset($this->attrs[$name]); } @@ -177,7 +179,7 @@ public function __unset($name) * @param array (string) HTML attribute value or pair? * @return mixed */ - public function __call($m, $args) + public function __call(string $m, array $args) { $p = substr($m, 0, 3); if ($p === 'get' || $p === 'set' || $p === 'add') { @@ -216,7 +218,7 @@ public function __call($m, $args) * @param array query * @return self */ - public function href($path, $query = NULL) + public function href(string $path, array $query = NULL): self { if ($query) { $query = http_build_query($query, '', '&'); @@ -233,7 +235,7 @@ public function href($path, $query = NULL) * Setter for data-* attributes. Booleans are converted to 'true' resp. 'false'. * @return self */ - public function data($name, $value = NULL) + public function data(string $name, $value = NULL): self { if (func_num_args() === 1) { $this->attrs['data'] = $name; @@ -250,13 +252,13 @@ public function data($name, $value = NULL) * @return self * @throws Nette\InvalidArgumentException */ - public function setHtml($html) + public function setHtml(string $html): self { if (is_array($html)) { throw new Nette\InvalidArgumentException(sprintf('Textual content must be a scalar, %s given.', gettype($html))); } $this->removeChildren(); - $this->children[] = (string) $html; + $this->children[] = $html; return $this; } @@ -265,7 +267,7 @@ public function setHtml($html) * Returns element's HTML content. * @return string */ - public function getHtml() + public function getHtml(): string { $s = ''; foreach ($this->children as $child) { @@ -281,11 +283,11 @@ public function getHtml() /** * Sets element's textual content. - * @param string + * @param mixed * @return self * @throws Nette\InvalidArgumentException */ - public function setText($text) + public function setText($text): self { if (!is_array($text) && !$text instanceof self) { $text = htmlspecialchars((string) $text, ENT_NOQUOTES, 'UTF-8'); @@ -298,7 +300,7 @@ public function setText($text) * Returns element's textual content. * @return string */ - public function getText() + public function getText(): string { return html_entity_decode(strip_tags($this->getHtml()), ENT_QUOTES, 'UTF-8'); } @@ -309,7 +311,7 @@ public function getText() * @param Html|string Html node or raw HTML string * @return self */ - public function add($child) + public function add($child): self { return $this->insert(NULL, $child); } @@ -321,7 +323,7 @@ public function add($child) * @param array|string element's attributes or raw HTML string * @return self created element */ - public function create($name, $attrs = NULL) + public function create(string $name, $attrs = NULL): self { $this->insert(NULL, $child = static::el($name, $attrs)); return $child; @@ -336,7 +338,7 @@ public function create($name, $attrs = NULL) * @return self * @throws Nette\InvalidArgumentException */ - public function insert($index, $child, $replace = FALSE) + public function insert($index, $child, bool $replace = FALSE): self { if ($child instanceof self || is_scalar($child)) { if ($index === NULL) { // append @@ -405,7 +407,7 @@ public function offsetUnset($index) * Returns children count. * @return int */ - public function count() + public function count(): int { return count($this->children); } @@ -425,7 +427,7 @@ public function removeChildren() * Iterates over a elements. * @return \ArrayIterator */ - public function getIterator() + public function getIterator(): \ArrayIterator { return new \ArrayIterator($this->children); } @@ -435,7 +437,7 @@ public function getIterator() * Returns all of children. * @return array */ - public function getChildren() + public function getChildren(): array { return $this->children; } @@ -446,7 +448,7 @@ public function getChildren() * @param int * @return string */ - public function render($indent = NULL) + public function render(int $indent = NULL): string { $s = $this->startTag(); @@ -474,7 +476,7 @@ public function render($indent = NULL) } - public function __toString() + public function __toString(): string { return $this->render(); } @@ -484,7 +486,7 @@ public function __toString() * Returns element's start tag. * @return string */ - public function startTag() + public function startTag(): string { if ($this->name) { return '<' . $this->name . $this->attributes() . (static::$xhtml && $this->isEmpty ? ' />' : '>'); @@ -499,7 +501,7 @@ public function startTag() * Returns element's end tag. * @return string */ - public function endTag() + public function endTag(): string { return $this->name && !$this->isEmpty ? 'name . '>' : ''; } @@ -510,7 +512,7 @@ public function endTag() * @return string * @internal */ - public function attributes() + public function attributes(): string { if (!is_array($this->attrs)) { return ''; diff --git a/src/Utils/IHtmlString.php b/src/Utils/IHtmlString.php index 71e44ca94..5fb24f408 100644 --- a/src/Utils/IHtmlString.php +++ b/src/Utils/IHtmlString.php @@ -5,6 +5,8 @@ * Copyright (c) 2004 David Grudl (https://davidgrudl.com) */ +declare(strict_types = 1); + namespace Nette\Utils; @@ -14,6 +16,6 @@ interface IHtmlString /** * @return string in HTML format */ - function __toString(); + function __toString(): string; } diff --git a/src/Utils/ITranslator.php b/src/Utils/ITranslator.php index 6c62415e6..43b9d21b7 100644 --- a/src/Utils/ITranslator.php +++ b/src/Utils/ITranslator.php @@ -5,6 +5,8 @@ * Copyright (c) 2004 David Grudl (https://davidgrudl.com) */ +declare(strict_types = 1); + namespace Nette\Localization; @@ -20,6 +22,6 @@ interface ITranslator * @param int plural count * @return string */ - function translate($message, $count = NULL); + function translate(string $message, int $count = NULL): string; } diff --git a/src/Utils/Image.php b/src/Utils/Image.php index 7148b02b8..83738bfab 100644 --- a/src/Utils/Image.php +++ b/src/Utils/Image.php @@ -5,6 +5,8 @@ * Copyright (c) 2004 David Grudl (https://davidgrudl.com) */ +declare(strict_types = 1); + namespace Nette\Utils; use Nette; @@ -124,7 +126,7 @@ class Image extends Nette\Object * @param int transparency 0..127 * @return array */ - public static function rgb($red, $green, $blue, $transparency = 0) + public static function rgb(int $red, int $green, int $blue, int $transparency = 0): array { return [ 'red' => max(0, min(255, (int) $red)), @@ -143,7 +145,7 @@ public static function rgb($red, $green, $blue, $transparency = 0) * @throws UnknownImageFileException if file not found or file type is not known * @return self */ - public static function fromFile($file, & $format = NULL) + public static function fromFile(string $file, & $format = NULL): self { if (!extension_loaded('gd')) { throw new Nette\NotSupportedException('PHP extension GD is not loaded.'); @@ -159,7 +161,7 @@ public static function fromFile($file, & $format = NULL) if (!isset($funcs[$format])) { throw new UnknownImageFileException(is_file($file) ? "Unknown type of file '$file'." : "File '$file' not found."); } - return new static(Callback::invokeSafe($funcs[$format], [$file], function ($message) { + return new static(Callback::invokeSafe($funcs[$format], [$file], function (string $message) { throw new ImageException($message); })); } @@ -172,7 +174,7 @@ public static function fromFile($file, & $format = NULL) * @return self * @throws ImageException */ - public static function fromString($s, & $format = NULL) + public static function fromString(string $s, & $format = NULL): self { if (!extension_loaded('gd')) { throw new Nette\NotSupportedException('PHP extension GD is not loaded.'); @@ -183,7 +185,7 @@ public static function fromString($s, & $format = NULL) $format = in_array($tmp, [self::JPEG, self::PNG, self::GIF], TRUE) ? $tmp : NULL; } - return new static(Callback::invokeSafe('imagecreatefromstring', [$s], function ($message) { + return new static(Callback::invokeSafe('imagecreatefromstring', [$s], function (string $message) { throw new ImageException($message); })); } @@ -196,7 +198,7 @@ public static function fromString($s, & $format = NULL) * @param array * @return self */ - public static function fromBlank($width, $height, $color = NULL) + public static function fromBlank(int $width, int $height, array $color = NULL): self { if (!extension_loaded('gd')) { throw new Nette\NotSupportedException('PHP extension GD is not loaded.'); @@ -235,7 +237,7 @@ public function __construct($image) * Returns image width. * @return int */ - public function getWidth() + public function getWidth(): int { return imagesx($this->image); } @@ -245,7 +247,7 @@ public function getWidth() * Returns image height. * @return int */ - public function getHeight() + public function getHeight(): int { return imagesy($this->image); } @@ -256,7 +258,7 @@ public function getHeight() * @param resource * @return self */ - protected function setImageResource($image) + protected function setImageResource($image): self { if (!is_resource($image) || get_resource_type($image) !== 'gd') { throw new Nette\InvalidArgumentException('Image is not valid.'); @@ -283,7 +285,7 @@ public function getImageResource() * @param int flags * @return self */ - public function resize($width, $height, $flags = self::FIT) + public function resize($width, $height, int $flags = self::FIT): self { if ($flags & self::EXACT) { return $this->resize($width, $height, self::FILL)->crop('50%', '50%', $width, $height); @@ -317,7 +319,7 @@ public function resize($width, $height, $flags = self::FIT) * @param int flags * @return array */ - public static function calculateSize($srcWidth, $srcHeight, $newWidth, $newHeight, $flags = self::FIT) + public static function calculateSize($srcWidth, $srcHeight, $newWidth, $newHeight, int $flags = self::FIT): array { if (is_string($newWidth) && substr($newWidth, -1) === '%') { $newWidth = (int) round($srcWidth / 100 * abs($newWidth)); @@ -382,7 +384,7 @@ public static function calculateSize($srcWidth, $srcHeight, $newWidth, $newHeigh * @param mixed height in pixels or percent * @return self */ - public function crop($left, $top, $width, $height) + public function crop($left, $top, $width, $height): self { list($r['x'], $r['y'], $r['width'], $r['height']) = static::calculateCutout($this->getWidth(), $this->getHeight(), $left, $top, $width, $height); @@ -407,7 +409,7 @@ public function crop($left, $top, $width, $height) * @param mixed height in pixels or percent * @return array */ - public static function calculateCutout($srcWidth, $srcHeight, $left, $top, $newWidth, $newHeight) + public static function calculateCutout($srcWidth, $srcHeight, $left, $top, $newWidth, $newHeight): array { if (is_string($newWidth) && substr($newWidth, -1) === '%') { $newWidth = (int) round($srcWidth / 100 * $newWidth); @@ -439,7 +441,7 @@ public static function calculateCutout($srcWidth, $srcHeight, $left, $top, $newW * Sharpen image. * @return self */ - public function sharpen() + public function sharpen(): self { imageconvolution($this->image, [ // my magic numbers ;) [-1, -1, -1], @@ -458,7 +460,7 @@ public function sharpen() * @param int opacity 0..100 * @return self */ - public function place(Image $image, $left = 0, $top = 0, $opacity = 100) + public function place(Image $image, $left = 0, $top = 0, int $opacity = 100): self { $opacity = max(0, min(100, (int) $opacity)); @@ -504,7 +506,7 @@ public function place(Image $image, $left = 0, $top = 0, $opacity = 100) * @param int optional image type * @return bool TRUE on success or FALSE on failure. */ - public function save($file = NULL, $quality = NULL, $type = NULL) + public function save(string $file = NULL, int $quality = NULL, int $type = NULL): bool { if ($type === NULL) { switch (strtolower($ext = pathinfo($file, PATHINFO_EXTENSION))) { @@ -547,7 +549,7 @@ public function save($file = NULL, $quality = NULL, $type = NULL) * @param int quality 0..100 (for JPEG and PNG) * @return string */ - public function toString($type = self::JPEG, $quality = NULL) + public function toString(int $type = self::JPEG, int $quality = NULL): string { ob_start(); $this->save(NULL, $quality, $type); @@ -559,7 +561,7 @@ public function toString($type = self::JPEG, $quality = NULL) * Outputs image to string. * @return string */ - public function __toString() + public function __toString(): string { try { return $this->toString(); @@ -578,7 +580,7 @@ public function __toString() * @param int quality 0..100 (for JPEG and PNG) * @return bool TRUE on success or FALSE on failure. */ - public function send($type = self::JPEG, $quality = NULL) + public function send(int $type = self::JPEG, int $quality = NULL): bool { if (!in_array($type, [self::JPEG, self::PNG, self::GIF], TRUE)) { throw new Nette\InvalidArgumentException("Unsupported image type '$type'."); @@ -596,7 +598,7 @@ public function send($type = self::JPEG, $quality = NULL) * @return mixed * @throws Nette\MemberAccessException */ - public function __call($name, $args) + public function __call(string $name, array $args) { $function = 'image' . $name; if (!function_exists($function)) { diff --git a/src/Utils/Json.php b/src/Utils/Json.php index 8bdbf6e86..d3c08f9bf 100644 --- a/src/Utils/Json.php +++ b/src/Utils/Json.php @@ -5,6 +5,8 @@ * Copyright (c) 2004 David Grudl (https://davidgrudl.com) */ +declare(strict_types = 1); + namespace Nette\Utils; use Nette; @@ -34,7 +36,7 @@ final public function __construct() * @param int accepts Json::PRETTY * @return string */ - public static function encode($value, $options = 0) + public static function encode($value, int $options = 0): string { $flags = JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | ($options & self::PRETTY ? JSON_PRETTY_PRINT : 0); @@ -54,7 +56,7 @@ public static function encode($value, $options = 0) * @param int accepts Json::FORCE_ARRAY * @return mixed */ - public static function decode($json, $options = 0) + public static function decode(string $json, int $options = 0) { $json = (string) $json; if (defined('JSON_C_VERSION') && !preg_match('##u', $json)) { diff --git a/src/Utils/Object.php b/src/Utils/Object.php index fee765cf6..763e01080 100644 --- a/src/Utils/Object.php +++ b/src/Utils/Object.php @@ -5,6 +5,8 @@ * Copyright (c) 2004 David Grudl (https://davidgrudl.com) */ +declare(strict_types = 1); + namespace Nette; use Nette; @@ -70,7 +72,7 @@ public static function getReflection() * @return mixed * @throws MemberAccessException */ - public function __call($name, $args) + public function __call(string $name, array $args) { return ObjectMixin::call($this, $name, $args); } @@ -95,7 +97,7 @@ public static function __callStatic($name, $args) * @param callable * @return mixed */ - public static function extensionMethod($name, $callback = NULL) + public static function extensionMethod(string $name, callable $callback = NULL) { if (strpos($name, '::') === FALSE) { $class = get_called_class(); @@ -117,7 +119,7 @@ public static function extensionMethod($name, $callback = NULL) * @return mixed property value * @throws MemberAccessException if the property is not defined. */ - public function &__get($name) + public function &__get(string $name) { return ObjectMixin::get($this, $name); } @@ -130,7 +132,7 @@ public function &__get($name) * @return void * @throws 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); } @@ -141,7 +143,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); } @@ -153,7 +155,7 @@ public function __isset($name) * @return void * @throws MemberAccessException */ - public function __unset($name) + public function __unset(string $name) { ObjectMixin::remove($this, $name); } diff --git a/src/Utils/ObjectMixin.php b/src/Utils/ObjectMixin.php index cac75b5a6..a4754255e 100644 --- a/src/Utils/ObjectMixin.php +++ b/src/Utils/ObjectMixin.php @@ -5,6 +5,8 @@ * Copyright (c) 2004 David Grudl (https://davidgrudl.com) */ +declare(strict_types = 1); + namespace Nette\Utils; use Nette; @@ -43,7 +45,7 @@ final public function __construct() * @return mixed * @throws MemberAccessException */ - public static function call($_this, $name, $args) + public static function call($_this, string $name, array $args) { $class = get_class($_this); $isProp = self::hasProperty($class, $name); @@ -110,7 +112,7 @@ public static function call($_this, $name, $args) * @return void * @throws MemberAccessException */ - public static function callStatic($class, $method, $args) + public static function callStatic(string $class, string $method, array $args) { $hint = self::getSuggestion(array_filter( get_class_methods($class), @@ -127,7 +129,7 @@ function ($m) use ($class) { return (new \ReflectionMethod($class, $m))->isStati * @return mixed property value * @throws MemberAccessException if the property is not defined. */ - public static function & get($_this, $name) + public static function & get($_this, string $name) { $class = get_class($_this); $uname = ucfirst($name); @@ -182,7 +184,7 @@ public static function & get($_this, $name) * @return void * @throws MemberAccessException if the property is not defined or is read-only */ - public static function set($_this, $name, $value) + public static function set($_this, string $name, $value) { $class = get_class($_this); $uname = ucfirst($name); @@ -217,7 +219,7 @@ public static function set($_this, $name, $value) * @return void * @throws MemberAccessException */ - public static function remove($_this, $name) + public static function remove($_this, string $name) { $class = get_class($_this); if (!self::hasProperty($class, $name)) { // strict class @@ -232,7 +234,7 @@ public static function remove($_this, $name) * @param string property name * @return bool */ - public static function has($_this, $name) + public static function has($_this, string $name): bool { $name = ucfirst($name); $methods = & self::getMethods(get_class($_this)); @@ -244,7 +246,7 @@ public static function has($_this, $name) * Checks if the public non-static property exists. * @return mixed */ - private static function hasProperty($class, $name) + private static function hasProperty(string $class, string $name) { $prop = & self::$props[$class][$name]; if ($prop === NULL) { @@ -265,7 +267,7 @@ private static function hasProperty($class, $name) * Returns array of public (static, non-static and magic) methods. * @return array */ - private static function & getMethods($class) + private static function & getMethods(string $class) { if (!isset(self::$methods[$class])) { self::$methods[$class] = array_fill_keys(get_class_methods($class), 0) + self::getMagicMethods($class); @@ -281,7 +283,7 @@ private static function & getMethods($class) * Returns array of magic methods defined by annotation @method. * @return array */ - public static function getMagicMethods($class) + public static function getMagicMethods(string $class): array { $rc = new \ReflectionClass($class); preg_match_all('~^ @@ -321,7 +323,7 @@ public static function getMagicMethods($class) * @return bool * @internal */ - public static function checkType(& $val, $type) + public static function checkType(& $val, string $type): bool { if (strpos($type, '|') !== FALSE) { $found = NULL; @@ -390,7 +392,7 @@ public static function checkType(& $val, $type) * @param mixed callable * @return void */ - public static function setExtensionMethod($class, $name, $callback) + public static function setExtensionMethod(string $class, string $name, callable $callback) { $name = strtolower($name); self::$extMethods[$name][$class] = Callback::check($callback); @@ -404,7 +406,7 @@ public static function setExtensionMethod($class, $name, $callback) * @param string * @return mixed */ - public static function getExtensionMethod($class, $name) + public static function getExtensionMethod(string $class, string $name) { $list = & self::$extMethods[strtolower($name)]; $cache = & $list[''][$class]; diff --git a/src/Utils/Paginator.php b/src/Utils/Paginator.php index c2ce308fb..60e87424c 100644 --- a/src/Utils/Paginator.php +++ b/src/Utils/Paginator.php @@ -5,6 +5,8 @@ * Copyright (c) 2004 David Grudl (https://davidgrudl.com) */ +declare(strict_types = 1); + namespace Nette\Utils; use Nette; @@ -46,9 +48,9 @@ class Paginator extends Nette\Object * @param int * @return self */ - public function setPage($page) + public function setPage(int $page): self { - $this->page = (int) $page; + $this->page = $page; return $this; } @@ -57,7 +59,7 @@ public function setPage($page) * Returns current page number. * @return int */ - public function getPage() + public function getPage(): int { return $this->base + $this->getPageIndex(); } @@ -67,7 +69,7 @@ public function getPage() * Returns first page number. * @return int */ - public function getFirstPage() + public function getFirstPage(): int { return $this->base; } @@ -88,9 +90,9 @@ public function getLastPage() * @param int * @return self */ - public function setBase($base) + public function setBase(int $base): self { - $this->base = (int) $base; + $this->base = $base; return $this; } @@ -99,7 +101,7 @@ public function setBase($base) * Returns first page (base) number. * @return int */ - public function getBase() + public function getBase(): int { return $this->base; } @@ -109,7 +111,7 @@ public function getBase() * Returns zero-based page number. * @return int */ - protected function getPageIndex() + protected function getPageIndex(): int { $index = max(0, $this->page - $this->base); return $this->itemCount === NULL ? $index : min($index, max(0, $this->getPageCount() - 1)); @@ -120,7 +122,7 @@ protected function getPageIndex() * Is the current page the first one? * @return bool */ - public function isFirst() + public function isFirst(): bool { return $this->getPageIndex() === 0; } @@ -130,7 +132,7 @@ public function isFirst() * Is the current page the last one? * @return bool */ - public function isLast() + public function isLast(): bool { return $this->itemCount === NULL ? FALSE : $this->getPageIndex() >= $this->getPageCount() - 1; } @@ -151,9 +153,9 @@ public function getPageCount() * @param int * @return self */ - public function setItemsPerPage($itemsPerPage) + public function setItemsPerPage(int $itemsPerPage): self { - $this->itemsPerPage = max(1, (int) $itemsPerPage); + $this->itemsPerPage = max(1, $itemsPerPage); return $this; } @@ -162,7 +164,7 @@ public function setItemsPerPage($itemsPerPage) * Returns the number of items to display on a single page. * @return int */ - public function getItemsPerPage() + public function getItemsPerPage(): int { return $this->itemsPerPage; } @@ -173,9 +175,9 @@ public function getItemsPerPage() * @param int (or NULL as infinity) * @return self */ - public function setItemCount($itemCount) + public function setItemCount(int $itemCount = NULL): self { - $this->itemCount = ($itemCount === FALSE || $itemCount === NULL) ? NULL : max(0, (int) $itemCount); + $this->itemCount = $itemCount === NULL ? NULL : max(0, $itemCount); return $this; } @@ -194,7 +196,7 @@ public function getItemCount() * Returns the absolute index of the first item on current page. * @return int */ - public function getOffset() + public function getOffset(): int { return $this->getPageIndex() * $this->itemsPerPage; } diff --git a/src/Utils/Random.php b/src/Utils/Random.php index 5b93083b9..3d7fe649e 100644 --- a/src/Utils/Random.php +++ b/src/Utils/Random.php @@ -5,6 +5,8 @@ * Copyright (c) 2004 David Grudl (https://davidgrudl.com) */ +declare(strict_types = 1); + namespace Nette\Utils; use Nette; @@ -22,7 +24,7 @@ class Random * @param string * @return string */ - public static function generate($length = 10, $charlist = '0-9a-z') + public static function generate(int $length = 10, string $charlist = '0-9a-z'): string { $charlist = count_chars(preg_replace_callback('#.-.#', function (array $m) { return implode('', range($m[0][0], $m[0][2])); diff --git a/src/Utils/Strings.php b/src/Utils/Strings.php index 66ccc6ebc..b960a5a84 100644 --- a/src/Utils/Strings.php +++ b/src/Utils/Strings.php @@ -5,6 +5,8 @@ * Copyright (c) 2004 David Grudl (https://davidgrudl.com) */ +declare(strict_types = 1); + namespace Nette\Utils; use Nette; @@ -33,7 +35,7 @@ final public function __construct() * @param string byte stream to check * @return bool */ - public static function checkEncoding($s) + public static function checkEncoding(string $s): bool { return $s === self::fixEncoding($s); } @@ -44,7 +46,7 @@ public static function checkEncoding($s) * @param string byte stream to fix * @return string */ - public static function fixEncoding($s) + public static function fixEncoding(string $s): string { // removes xD800-xDFFF, x110000 and higher return htmlspecialchars_decode(htmlspecialchars($s, ENT_NOQUOTES | ENT_IGNORE, 'UTF-8'), ENT_NOQUOTES); @@ -57,7 +59,7 @@ public static function fixEncoding($s) * @return string * @throws Nette\InvalidArgumentException if code point is not in valid range */ - public static function chr($code) + public static function chr(int $code): string { if ($code < 0 || ($code >= 0xD800 && $code <= 0xDFFF) || $code > 0x10FFFF) { throw new Nette\InvalidArgumentException('Code point must be in range 0x0 to 0xD7FF or 0xE000 to 0x10FFFF.'); @@ -72,7 +74,7 @@ public static function chr($code) * @param string * @return bool */ - public static function startsWith($haystack, $needle) + public static function startsWith(string $haystack, string $needle): bool { return strncmp($haystack, $needle, strlen($needle)) === 0; } @@ -84,7 +86,7 @@ public static function startsWith($haystack, $needle) * @param string * @return bool */ - public static function endsWith($haystack, $needle) + public static function endsWith(string $haystack, string $needle): bool { return strlen($needle) === 0 || substr($haystack, -strlen($needle)) === $needle; } @@ -96,7 +98,7 @@ public static function endsWith($haystack, $needle) * @param string * @return bool */ - public static function contains($haystack, $needle) + public static function contains(string $haystack, string $needle): bool { return strpos($haystack, $needle) !== FALSE; } @@ -109,7 +111,7 @@ public static function contains($haystack, $needle) * @param int in characters (code points) * @return string */ - public static function substring($s, $start, $length = NULL) + public static function substring(string $s, int $start, int $length = NULL): string { if (function_exists('mb_substr')) { return mb_substr($s, $start, $length, 'UTF-8'); // MB is much faster @@ -127,7 +129,7 @@ public static function substring($s, $start, $length = NULL) * @param string UTF-8 encoding * @return string */ - public static function normalize($s) + public static function normalize(string $s): string { $s = self::normalizeNewLines($s); @@ -149,7 +151,7 @@ public static function normalize($s) * @param string UTF-8 encoding or 8-bit * @return string */ - public static function normalizeNewLines($s) + public static function normalizeNewLines(string $s): string { return str_replace(["\r\n", "\r"], "\n", $s); } @@ -160,7 +162,7 @@ public static function normalizeNewLines($s) * @param string UTF-8 encoding * @return string ASCII */ - public static function toAscii($s) + public static function toAscii(string $s): string { $s = preg_replace('#[^\x09\x0A\x0D\x20-\x7E\xA0-\x{2FF}\x{370}-\x{10FFFF}]#u', '', $s); $s = strtr($s, '`\'"^~?', "\x01\x02\x03\x04\x05\x06"); @@ -199,7 +201,7 @@ public static function toAscii($s) * @param bool * @return string */ - public static function webalize($s, $charlist = NULL, $lower = TRUE) + public static function webalize(string $s, string $charlist = NULL, bool $lower = TRUE): string { $s = self::toAscii($s); if ($lower) { @@ -218,7 +220,7 @@ public static function webalize($s, $charlist = NULL, $lower = TRUE) * @param string UTF-8 encoding * @return string */ - public static function truncate($s, $maxLen, $append = "\xE2\x80\xA6") + public static function truncate(string $s, int $maxLen, string $append = "\xE2\x80\xA6"): string { if (self::length($s) > $maxLen) { $maxLen = $maxLen - self::length($append); @@ -243,7 +245,7 @@ public static function truncate($s, $maxLen, $append = "\xE2\x80\xA6") * @param string * @return string */ - public static function indent($s, $level = 1, $chars = "\t") + public static function indent(string $s, int $level = 1, string $chars = "\t"): string { if ($level > 0) { $s = self::replace($s, '#(?:^|[\r\n]+)(?=[^\r\n])#', '$0' . str_repeat($chars, $level)); @@ -257,7 +259,7 @@ public static function indent($s, $level = 1, $chars = "\t") * @param string UTF-8 encoding * @return string */ - public static function lower($s) + public static function lower(string $s): string { return mb_strtolower($s, 'UTF-8'); } @@ -268,7 +270,7 @@ public static function lower($s) * @param string UTF-8 encoding * @return string */ - public static function firstLower($s) + public static function firstLower(string $s): string { return self::lower(self::substring($s, 0, 1)) . self::substring($s, 1); } @@ -279,7 +281,7 @@ public static function firstLower($s) * @param string UTF-8 encoding * @return string */ - public static function upper($s) + public static function upper(string $s): string { return mb_strtoupper($s, 'UTF-8'); } @@ -290,7 +292,7 @@ public static function upper($s) * @param string UTF-8 encoding * @return string */ - public static function firstUpper($s) + public static function firstUpper(string $s): string { return self::upper(self::substring($s, 0, 1)) . self::substring($s, 1); } @@ -301,7 +303,7 @@ public static function firstUpper($s) * @param string UTF-8 encoding * @return string */ - public static function capitalize($s) + public static function capitalize(string $s): string { return mb_convert_case($s, MB_CASE_TITLE, 'UTF-8'); } @@ -314,7 +316,7 @@ public static function capitalize($s) * @param int * @return bool */ - public static function compare($left, $right, $len = NULL) + public static function compare(string $left, string $right, int $len = NULL): bool { if ($len < 0) { $left = self::substring($left, $len, -$len); @@ -332,7 +334,7 @@ public static function compare($left, $right, $len = NULL) * @param string|array * @return string */ - public static function findPrefix(...$strings) + public static function findPrefix(...$strings): string { if (is_array($strings[0])) { $strings = $strings[0]; @@ -358,7 +360,7 @@ public static function findPrefix(...$strings) * @param string * @return int */ - public static function length($s) + public static function length(string $s): int { return function_exists('mb_strlen') ? mb_strlen($s, 'UTF-8') : strlen(utf8_decode($s)); } @@ -370,7 +372,7 @@ public static function length($s) * @param string * @return string */ - public static function trim($s, $charlist = self::TRIM_CHARACTERS) + public static function trim(string $s, string $charlist = self::TRIM_CHARACTERS): string { $charlist = preg_quote($charlist, '#'); return self::replace($s, '#^['.$charlist.']+|['.$charlist.']+\z#u', ''); @@ -384,7 +386,7 @@ public static function trim($s, $charlist = self::TRIM_CHARACTERS) * @param string * @return string */ - public static function padLeft($s, $length, $pad = ' ') + public static function padLeft(string $s, int $length, string $pad = ' '): string { $length = max(0, $length - self::length($s)); $padLen = self::length($pad); @@ -399,7 +401,7 @@ public static function padLeft($s, $length, $pad = ' ') * @param string * @return string */ - public static function padRight($s, $length, $pad = ' ') + public static function padRight(string $s, int $length, string $pad = ' '): string { $length = max(0, $length - self::length($s)); $padLen = self::length($pad); @@ -412,7 +414,7 @@ public static function padRight($s, $length, $pad = ' ') * @param string UTF-8 encoding * @return string */ - public static function reverse($s) + public static function reverse(string $s): string { return iconv('UTF-32LE', 'UTF-8', strrev(iconv('UTF-8', 'UTF-32BE', $s))); } @@ -422,7 +424,7 @@ public static function reverse($s) * Use Nette\Utils\Random::generate * @deprecated */ - public static function random($length = 10, $charlist = '0-9a-z') + public static function random(int $length = 10, string $charlist = '0-9a-z'): string { return Random::generate($length, $charlist); } @@ -435,7 +437,7 @@ public static function random($length = 10, $charlist = '0-9a-z') * @param int negative value means searching from the end * @return string|FALSE returns FALSE if the needle was not found */ - public static function before($haystack, $needle, $nth = 1) + public static function before(string $haystack, string $needle, int $nth = 1) { $pos = self::pos($haystack, $needle, $nth); return $pos === FALSE @@ -451,7 +453,7 @@ public static function before($haystack, $needle, $nth = 1) * @param int negative value means searching from the end * @return string|FALSE returns FALSE if the needle was not found */ - public static function after($haystack, $needle, $nth = 1) + public static function after(string $haystack, string $needle, int $nth = 1) { $pos = self::pos($haystack, $needle, $nth); return $pos === FALSE @@ -467,7 +469,7 @@ public static function after($haystack, $needle, $nth = 1) * @param int negative value means searching from the end * @return int|FALSE offset in characters or FALSE if the needle was not found */ - public static function indexOf($haystack, $needle, $nth = 1) + public static function indexOf(string $haystack, string $needle, int $nth = 1) { $pos = self::pos($haystack, $needle, $nth); return $pos === FALSE @@ -480,7 +482,7 @@ public static function indexOf($haystack, $needle, $nth = 1) * Returns position of $nth occurence of $needle in $haystack. * @return int|FALSE offset in bytes or FALSE if the needle was not found */ - private static function pos($haystack, $needle, $nth = 1) + private static function pos(string $haystack, string $needle, int $nth = 1) { if (!$nth) { return FALSE; @@ -513,7 +515,7 @@ private static function pos($haystack, $needle, $nth = 1) * @param int * @return array */ - public static function split($subject, $pattern, $flags = 0) + public static function split(string $subject, string $pattern, int $flags = 0): array { return self::pcre('preg_split', [$pattern, $subject, -1, $flags | PREG_SPLIT_DELIM_CAPTURE]); } @@ -527,7 +529,7 @@ public static function split($subject, $pattern, $flags = 0) * @param int offset in bytes * @return mixed */ - public static function match($subject, $pattern, $flags = 0, $offset = 0) + public static function match(string $subject, string $pattern, int $flags = 0, int $offset = 0) { if ($offset > strlen($subject)) { return NULL; @@ -546,7 +548,7 @@ public static function match($subject, $pattern, $flags = 0, $offset = 0) * @param int offset in bytes * @return array */ - public static function matchAll($subject, $pattern, $flags = 0, $offset = 0) + public static function matchAll(string $subject, string $pattern, int $flags = 0, int $offset = 0): array { if ($offset > strlen($subject)) { return []; @@ -568,7 +570,7 @@ public static function matchAll($subject, $pattern, $flags = 0, $offset = 0) * @param int * @return string */ - public static function replace($subject, $pattern, $replacement = NULL, $limit = -1) + public static function replace(string $subject, $pattern, $replacement = NULL, int $limit = -1): string { if (is_object($replacement) || is_array($replacement)) { if ($replacement instanceof Nette\Callback) { @@ -591,7 +593,7 @@ public static function replace($subject, $pattern, $replacement = NULL, $limit = /** @internal */ - public static function pcre($func, $args) + public static function pcre(string $func, $args) { static $messages = [ PREG_INTERNAL_ERROR => 'Internal error', @@ -601,7 +603,7 @@ public static function pcre($func, $args) PREG_BAD_UTF8_OFFSET_ERROR => 'Offset didn\'t correspond to the begin of a valid UTF-8 code point', 6 => 'Failed due to limited JIT stack space', // PREG_JIT_STACKLIMIT_ERROR ]; - $res = Callback::invokeSafe($func, $args, function ($message) use ($args) { + $res = Callback::invokeSafe($func, $args, function (string $message) use ($args) { // compile-time error, not detectable by preg_last_error throw new RegexpException($message . ' in pattern: ' . implode(' or ', (array) $args[0])); }); diff --git a/src/Utils/Validators.php b/src/Utils/Validators.php index 21a5b649e..1be010cf8 100644 --- a/src/Utils/Validators.php +++ b/src/Utils/Validators.php @@ -5,6 +5,8 @@ * Copyright (c) 2004 David Grudl (https://davidgrudl.com) */ +declare(strict_types = 1); + namespace Nette\Utils; use Nette; @@ -71,7 +73,7 @@ class Validators extends Nette\Object * @param string label * @return void */ - public static function assert($value, $expected, $label = 'variable') + public static function assert($value, string $expected, string $label = 'variable') { if (!static::is($value, $expected)) { $expected = str_replace(['|', ':'], [' or ', ' in range '], $expected); @@ -97,7 +99,7 @@ public static function assert($value, $expected, $label = 'variable') * @param string * @return void */ - public static function assertField($arr, $field, $expected = NULL, $label = "item '%' in array") + public static function assertField($arr, string $field, string $expected = NULL, string $label = "item '%' in array") { self::assert($arr, 'array', 'first argument'); if (!array_key_exists($field, $arr)) { @@ -115,7 +117,7 @@ public static function assertField($arr, $field, $expected = NULL, $label = "ite * @param string expected types separated by pipe with optional ranges * @return bool */ - public static function is($value, $expected) + public static function is($value, string $expected): bool { foreach (explode('|', $expected) as $item) { list($type) = $item = explode(':', $item, 2); @@ -158,7 +160,7 @@ public static function is($value, $expected) * Finds whether a value is an integer. * @return bool */ - public static function isNumericInt($value) + public static function isNumericInt($value): bool { return is_int($value) || is_string($value) && preg_match('#^-?[0-9]+\z#', $value); } @@ -168,7 +170,7 @@ public static function isNumericInt($value) * Finds whether a string is a floating point number in decimal base. * @return bool */ - public static function isNumeric($value) + public static function isNumeric($value): bool { return is_float($value) || is_int($value) || is_string($value) && preg_match('#^-?[0-9]*[.]?[0-9]+\z#', $value); } @@ -178,7 +180,7 @@ public static function isNumeric($value) * Finds whether a value is a syntactically correct callback. * @return bool */ - public static function isCallable($value) + public static function isCallable($value): bool { return $value && is_callable($value, TRUE); } @@ -189,7 +191,7 @@ public static function isCallable($value) * @param string * @return bool */ - public static function isUnicode($value) + public static function isUnicode($value): bool { return is_string($value) && preg_match('##u', $value); } @@ -199,7 +201,7 @@ public static function isUnicode($value) * Finds whether a value is "falsy". * @return bool */ - public static function isNone($value) + public static function isNone($value): bool { return $value == NULL; // intentionally == } @@ -210,7 +212,7 @@ public static function isNone($value) * @param array * @return bool */ - public static function isList($value) + public static function isList($value): bool { return Arrays::isList($value); } @@ -222,7 +224,7 @@ public static function isList($value) * @param array min and max value pair * @return bool */ - public static function isInRange($value, $range) + public static function isInRange($value, array $range): bool { return (!isset($range[0]) || $range[0] === '' || $value >= $range[0]) && (!isset($range[1]) || $range[1] === '' || $value <= $range[1]); @@ -234,7 +236,7 @@ public static function isInRange($value, $range) * @param string * @return bool */ - public static function isEmail($value) + public static function isEmail(string $value): bool { $atom = "[-a-z0-9!#$%&'*+/=?^_`{|}~]"; // RFC 5322 unquoted characters in local-part $alpha = "a-z\x80-\xFF"; // superset of IDN @@ -252,7 +254,7 @@ public static function isEmail($value) * @param string * @return bool */ - public static function isUrl($value) + public static function isUrl(string $value): bool { $alpha = "a-z\x80-\xFF"; return (bool) preg_match("(^ @@ -273,7 +275,7 @@ public static function isUrl($value) * @param string * @return bool */ - public static function isUri($value) + public static function isUri(string $value): bool { return (bool) preg_match('#^[a-z\d+\.-]+:\S+\z#i', $value); } @@ -284,9 +286,9 @@ public static function isUri($value) * @param string * @return bool */ - public static function isType($type) + public static function isType(string $type): bool { - return class_exists($type) || interface_exists($type) || trait_exists($type); + return class_exists($type) || interface_exists($type) || (PHP_VERSION_ID >= 50400 && trait_exists($type)); } @@ -294,7 +296,7 @@ public static function isType($type) * Checks whether the input is a valid PHP identifier. * @return bool */ - public static function isPhpIdentifier($value) + public static function isPhpIdentifier(string $value): bool { return is_string($value) && preg_match('#^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*\z#', $value); } diff --git a/src/Utils/exceptions.php b/src/Utils/exceptions.php index 0b759ff06..2b4451b19 100644 --- a/src/Utils/exceptions.php +++ b/src/Utils/exceptions.php @@ -5,6 +5,8 @@ * Copyright (c) 2004 David Grudl (https://davidgrudl.com) */ +declare(strict_types = 1); + namespace Nette; diff --git a/tests/Iterators/CachingIterator.basic.phpt b/tests/Iterators/CachingIterator.basic.phpt index 244ff0878..82c7556d7 100644 --- a/tests/Iterators/CachingIterator.basic.phpt +++ b/tests/Iterators/CachingIterator.basic.phpt @@ -4,6 +4,8 @@ * Test: Nette\Iterators\CachingIterator basic usage. */ +declare(strict_types = 1); + use Nette\Iterators; use Tester\Assert; diff --git a/tests/Iterators/CachingIterator.construct.phpt b/tests/Iterators/CachingIterator.construct.phpt index 748f1ef45..19bf1f3fe 100644 --- a/tests/Iterators/CachingIterator.construct.phpt +++ b/tests/Iterators/CachingIterator.construct.phpt @@ -4,6 +4,8 @@ * Test: Nette\Iterators\CachingIterator constructor. */ +declare(strict_types = 1); + use Nette\Iterators; use Tester\Assert; diff --git a/tests/Iterators/CachingIterator.width.phpt b/tests/Iterators/CachingIterator.width.phpt index 09a3d236b..a75227dda 100644 --- a/tests/Iterators/CachingIterator.width.phpt +++ b/tests/Iterators/CachingIterator.width.phpt @@ -4,6 +4,8 @@ * Test: Nette\Iterators\CachingIterator width. */ +declare(strict_types = 1); + use Nette\Iterators; use Tester\Assert; diff --git a/tests/Iterators/Mapper.phpt b/tests/Iterators/Mapper.phpt index 34458572a..2f8cd8b38 100644 --- a/tests/Iterators/Mapper.phpt +++ b/tests/Iterators/Mapper.phpt @@ -4,6 +4,8 @@ * Test: Nette\Iterators\Mapper */ +declare(strict_types = 1); + use Nette\Iterators; use Tester\Assert; diff --git a/tests/Utils/ArrayHash.phpt b/tests/Utils/ArrayHash.phpt index 720a9d2c9..a5c5131f2 100644 --- a/tests/Utils/ArrayHash.phpt +++ b/tests/Utils/ArrayHash.phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\ArrayHash basic usage. */ +declare(strict_types = 1); + use Nette\Utils\ArrayHash; use Tester\Assert; diff --git a/tests/Utils/ArrayList.phpt b/tests/Utils/ArrayList.phpt index c85798398..1b60df6de 100644 --- a/tests/Utils/ArrayList.phpt +++ b/tests/Utils/ArrayList.phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\ArrayList basic usage. */ +declare(strict_types = 1); + use Nette\Utils\ArrayList; use Tester\Assert; diff --git a/tests/Utils/Arrays.associate().error.phpt b/tests/Utils/Arrays.associate().error.phpt index d9a7cb542..878a9c312 100644 --- a/tests/Utils/Arrays.associate().error.phpt +++ b/tests/Utils/Arrays.associate().error.phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Arrays::associate() */ +declare(strict_types = 1); + use Nette\Utils\Arrays; use Tester\Assert; diff --git a/tests/Utils/Arrays.associate().phpt b/tests/Utils/Arrays.associate().phpt index 8878c29b9..b4c6fbef9 100644 --- a/tests/Utils/Arrays.associate().phpt +++ b/tests/Utils/Arrays.associate().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Arrays::associate() */ +declare(strict_types = 1); + use Nette\Utils\Arrays; use Nette\Utils\DateTime; use Tester\Assert; diff --git a/tests/Utils/Arrays.flatten().phpt b/tests/Utils/Arrays.flatten().phpt index e73189dff..c0f9c758e 100644 --- a/tests/Utils/Arrays.flatten().phpt +++ b/tests/Utils/Arrays.flatten().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Arrays::flatten() */ +declare(strict_types = 1); + use Nette\Utils\Arrays; use Tester\Assert; diff --git a/tests/Utils/Arrays.get().phpt b/tests/Utils/Arrays.get().phpt index 4611caa61..2d5a684f4 100644 --- a/tests/Utils/Arrays.get().phpt +++ b/tests/Utils/Arrays.get().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Arrays::get() */ +declare(strict_types = 1); + use Nette\Utils\Arrays; use Tester\Assert; diff --git a/tests/Utils/Arrays.getRef().phpt b/tests/Utils/Arrays.getRef().phpt index 285caade9..1266026a4 100644 --- a/tests/Utils/Arrays.getRef().phpt +++ b/tests/Utils/Arrays.getRef().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Arrays::getRef() */ +declare(strict_types = 1); + use Nette\Utils\Arrays; use Tester\Assert; diff --git a/tests/Utils/Arrays.grep().errors.phpt b/tests/Utils/Arrays.grep().errors.phpt index bd2203875..474797fae 100644 --- a/tests/Utils/Arrays.grep().errors.phpt +++ b/tests/Utils/Arrays.grep().errors.phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Arrays::grep() errors. */ +declare(strict_types = 1); + use Nette\Utils\Arrays; use Tester\Assert; diff --git a/tests/Utils/Arrays.grep().phpt b/tests/Utils/Arrays.grep().phpt index c7576e580..5b2758164 100644 --- a/tests/Utils/Arrays.grep().phpt +++ b/tests/Utils/Arrays.grep().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Arrays::grep() */ +declare(strict_types = 1); + use Nette\Utils\Arrays; use Tester\Assert; diff --git a/tests/Utils/Arrays.insertBefore().phpt b/tests/Utils/Arrays.insertBefore().phpt index cc38c86a8..cc25a7095 100644 --- a/tests/Utils/Arrays.insertBefore().phpt +++ b/tests/Utils/Arrays.insertBefore().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Arrays::insertBefore() & insertAfter() */ +declare(strict_types = 1); + use Nette\Utils\Arrays; use Tester\Assert; diff --git a/tests/Utils/Arrays.isList.phpt b/tests/Utils/Arrays.isList.phpt index e048b82be..5c8b0aa03 100644 --- a/tests/Utils/Arrays.isList.phpt +++ b/tests/Utils/Arrays.isList.phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Arrays::isList() */ +declare(strict_types = 1); + use Nette\Utils\Arrays; use Tester\Assert; diff --git a/tests/Utils/Arrays.normalize.phpt b/tests/Utils/Arrays.normalize.phpt index e80fde131..6753017d2 100644 --- a/tests/Utils/Arrays.normalize.phpt +++ b/tests/Utils/Arrays.normalize.phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Arrays::searchKey() */ +declare(strict_types = 1); + use Nette\Utils\Arrays; use Tester\Assert; diff --git a/tests/Utils/Arrays.pick().phpt b/tests/Utils/Arrays.pick().phpt index e266f724a..b5920a548 100644 --- a/tests/Utils/Arrays.pick().phpt +++ b/tests/Utils/Arrays.pick().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Arrays::pick() */ +declare(strict_types = 1); + use Nette\Utils\Arrays; use Tester\Assert; diff --git a/tests/Utils/Arrays.renameKey().phpt b/tests/Utils/Arrays.renameKey().phpt index 01c479c1e..e3100b39c 100644 --- a/tests/Utils/Arrays.renameKey().phpt +++ b/tests/Utils/Arrays.renameKey().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Arrays::renameKey() */ +declare(strict_types = 1); + use Nette\Utils\Arrays; use Tester\Assert; diff --git a/tests/Utils/Arrays.searchKey().phpt b/tests/Utils/Arrays.searchKey().phpt index 13f701afa..29da1631f 100644 --- a/tests/Utils/Arrays.searchKey().phpt +++ b/tests/Utils/Arrays.searchKey().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Arrays::searchKey() */ +declare(strict_types = 1); + use Nette\Utils\Arrays; use Tester\Assert; diff --git a/tests/Utils/Callback.check.phpt b/tests/Utils/Callback.check.phpt index 2e0766a1a..9aec79b0e 100644 --- a/tests/Utils/Callback.check.phpt +++ b/tests/Utils/Callback.check.phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Callback::check() */ +declare(strict_types = 1); + use Nette\Utils\Callback; use Tester\Assert; diff --git a/tests/Utils/Callback.closure.phpt b/tests/Utils/Callback.closure.phpt index f196fe755..5b2182071 100644 --- a/tests/Utils/Callback.closure.phpt +++ b/tests/Utils/Callback.closure.phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Callback closures tests. */ +declare(strict_types = 1); + use Nette\Utils\Callback; use Tester\Assert; diff --git a/tests/Utils/Callback.invoke.phpt b/tests/Utils/Callback.invoke.phpt index 7294c9e84..0fb805851 100644 --- a/tests/Utils/Callback.invoke.phpt +++ b/tests/Utils/Callback.invoke.phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Callback::invoke() and invokeArgs() */ +declare(strict_types = 1); + use Nette\Utils\Callback; use Tester\Assert; diff --git a/tests/Utils/Callback.invokeSafe.phpt b/tests/Utils/Callback.invokeSafe.phpt index d3549e8d6..9e5adbd33 100644 --- a/tests/Utils/Callback.invokeSafe.phpt +++ b/tests/Utils/Callback.invokeSafe.phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Callback::invokeSafe() */ +declare(strict_types = 1); + use Nette\Utils\Callback; use Tester\Assert; diff --git a/tests/Utils/DateTime.JSON.phpt b/tests/Utils/DateTime.JSON.phpt index eb57b297f..02294e4af 100644 --- a/tests/Utils/DateTime.JSON.phpt +++ b/tests/Utils/DateTime.JSON.phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\DateTime & JSON. */ +declare(strict_types = 1); + use Tester\Assert; use Nette\Utils\DateTime; diff --git a/tests/Utils/DateTime.createFromFormat.phpt b/tests/Utils/DateTime.createFromFormat.phpt index efa6574cf..d50401fe8 100644 --- a/tests/Utils/DateTime.createFromFormat.phpt +++ b/tests/Utils/DateTime.createFromFormat.phpt @@ -4,6 +4,8 @@ * Test: Nette\DateTime::createFromFormat(). */ +declare(strict_types = 1); + use Tester\Assert; use Nette\Utils\DateTime; diff --git a/tests/Utils/DateTime.from.phpt b/tests/Utils/DateTime.from.phpt index 4f50cb73b..646c6a34a 100644 --- a/tests/Utils/DateTime.from.phpt +++ b/tests/Utils/DateTime.from.phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\DateTime::from(). */ +declare(strict_types = 1); + use Tester\Assert; use Nette\Utils\DateTime; diff --git a/tests/Utils/FileSystem.phpt b/tests/Utils/FileSystem.phpt index eef6706e0..5d44324d8 100644 --- a/tests/Utils/FileSystem.phpt +++ b/tests/Utils/FileSystem.phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\FileSystem basic usage. */ +declare(strict_types = 1); + use Nette\Utils\FileSystem; use Tester\Assert; diff --git a/tests/Utils/Html.basic.phpt b/tests/Utils/Html.basic.phpt index 6c16a9788..ec0de6284 100644 --- a/tests/Utils/Html.basic.phpt +++ b/tests/Utils/Html.basic.phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Html basic usage. */ +declare(strict_types = 1); + use Nette\Utils\Html; use Tester\Assert; diff --git a/tests/Utils/Html.children.phpt b/tests/Utils/Html.children.phpt index 39571f4dc..4e6a4911f 100644 --- a/tests/Utils/Html.children.phpt +++ b/tests/Utils/Html.children.phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Html children usage. */ +declare(strict_types = 1); + use Nette\Utils\Html; use Tester\Assert; diff --git a/tests/Utils/Html.construct.phpt b/tests/Utils/Html.construct.phpt index cb93ab3be..c102168ab 100644 --- a/tests/Utils/Html.construct.phpt +++ b/tests/Utils/Html.construct.phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Html::__construct() */ +declare(strict_types = 1); + use Nette\Utils\Html; use Tester\Assert; diff --git a/tests/Utils/Html.data.phpt b/tests/Utils/Html.data.phpt index 74d5b7d9e..df7926b63 100644 --- a/tests/Utils/Html.data.phpt +++ b/tests/Utils/Html.data.phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Html user data attribute. */ +declare(strict_types = 1); + use Nette\Utils\Html; use Tester\Assert; diff --git a/tests/Utils/Html.style.phpt b/tests/Utils/Html.style.phpt index 84f7d7aca..29d280e6f 100644 --- a/tests/Utils/Html.style.phpt +++ b/tests/Utils/Html.style.phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Html style & class attribute. */ +declare(strict_types = 1); + use Nette\Utils\Html; use Tester\Assert; diff --git a/tests/Utils/Image.alpha1.phpt b/tests/Utils/Image.alpha1.phpt index 3ea70e0fa..3e6f3a198 100644 --- a/tests/Utils/Image.alpha1.phpt +++ b/tests/Utils/Image.alpha1.phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Image alpha channel. */ +declare(strict_types = 1); + use Nette\Utils\Image; use Tester\Assert; diff --git a/tests/Utils/Image.clone.phpt b/tests/Utils/Image.clone.phpt index 84d94cd0f..306b4dbbd 100644 --- a/tests/Utils/Image.clone.phpt +++ b/tests/Utils/Image.clone.phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Image cloning. */ +declare(strict_types = 1); + use Nette\Utils\Image; use Tester\Assert; diff --git a/tests/Utils/Image.drawing.phpt b/tests/Utils/Image.drawing.phpt index d0b008914..aaa9d021f 100644 --- a/tests/Utils/Image.drawing.phpt +++ b/tests/Utils/Image.drawing.phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Image drawing. */ +declare(strict_types = 1); + use Nette\Utils\Image; use Tester\Assert; diff --git a/tests/Utils/Image.factories.phpt b/tests/Utils/Image.factories.phpt index 753138079..382850d9b 100644 --- a/tests/Utils/Image.factories.phpt +++ b/tests/Utils/Image.factories.phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Image factories. */ +declare(strict_types = 1); + use Nette\Utils\Image; use Tester\Assert; diff --git a/tests/Utils/Image.resize.phpt b/tests/Utils/Image.resize.phpt index 56d9b211b..d265c8a1a 100644 --- a/tests/Utils/Image.resize.phpt +++ b/tests/Utils/Image.resize.phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Image crop, resize & flip. */ +declare(strict_types = 1); + use Nette\Utils\Image; use Tester\Assert; diff --git a/tests/Utils/Image.save.phpt b/tests/Utils/Image.save.phpt index 654f7e4e1..c5b6417f9 100644 --- a/tests/Utils/Image.save.phpt +++ b/tests/Utils/Image.save.phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Image save method exceptions. */ +declare(strict_types = 1); + use Nette\Utils\Image; use Tester\Assert; diff --git a/tests/Utils/Image.send.phpt b/tests/Utils/Image.send.phpt index f6a543866..07c27de1a 100644 --- a/tests/Utils/Image.send.phpt +++ b/tests/Utils/Image.send.phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Image send method exceptions. */ +declare(strict_types = 1); + use Nette\Utils\Image; use Tester\Assert; diff --git a/tests/Utils/Json.decode().phpt b/tests/Utils/Json.decode().phpt index 3b407e29f..2663f9df6 100644 --- a/tests/Utils/Json.decode().phpt +++ b/tests/Utils/Json.decode().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Json::decode() */ +declare(strict_types = 1); + use Nette\Utils\Json; use Tester\Assert; diff --git a/tests/Utils/Json.encode().phpt b/tests/Utils/Json.encode().phpt index 726f98a37..3f6d41109 100644 --- a/tests/Utils/Json.encode().phpt +++ b/tests/Utils/Json.encode().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Json::encode() */ +declare(strict_types = 1); + use Nette\Utils\Json; use Tester\Assert; diff --git a/tests/Utils/Object.arrayProperty.phpt b/tests/Utils/Object.arrayProperty.phpt index 9ead8f7a7..3f2bd036f 100644 --- a/tests/Utils/Object.arrayProperty.phpt +++ b/tests/Utils/Object.arrayProperty.phpt @@ -4,6 +4,8 @@ * Test: Nette\Object array property. */ +declare(strict_types = 1); + use Tester\Assert; require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Utils/Object.closureProperty.phpt b/tests/Utils/Object.closureProperty.phpt index 4572e2feb..15dcfb4ad 100644 --- a/tests/Utils/Object.closureProperty.phpt +++ b/tests/Utils/Object.closureProperty.phpt @@ -4,6 +4,8 @@ * Test: Nette\Object closure properties. */ +declare(strict_types = 1); + use Tester\Assert; require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Utils/Object.events.phpt b/tests/Utils/Object.events.phpt index 246b2f17f..50338eefb 100644 --- a/tests/Utils/Object.events.phpt +++ b/tests/Utils/Object.events.phpt @@ -4,6 +4,8 @@ * Test: Nette\Object event handlers. */ +declare(strict_types = 1); + use Tester\Assert; require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Utils/Object.extensionMethod.phpt b/tests/Utils/Object.extensionMethod.phpt index 25fbc3659..5ca3a57aa 100644 --- a/tests/Utils/Object.extensionMethod.phpt +++ b/tests/Utils/Object.extensionMethod.phpt @@ -4,6 +4,8 @@ * Test: Nette\Object extension method. */ +declare(strict_types = 1); + use Tester\Assert; require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Utils/Object.extensionMethodViaInterface.phpt b/tests/Utils/Object.extensionMethodViaInterface.phpt index d03d3ae2b..396f08ff3 100644 --- a/tests/Utils/Object.extensionMethodViaInterface.phpt +++ b/tests/Utils/Object.extensionMethodViaInterface.phpt @@ -4,6 +4,8 @@ * Test: Nette\Object extension method via interface. */ +declare(strict_types = 1); + use Nette\Object; use Tester\Assert; diff --git a/tests/Utils/Object.magicMethod.errors.phpt b/tests/Utils/Object.magicMethod.errors.phpt index 404c1f59a..41b8e0246 100644 --- a/tests/Utils/Object.magicMethod.errors.phpt +++ b/tests/Utils/Object.magicMethod.errors.phpt @@ -4,6 +4,8 @@ * Test: Nette\Object magic @methods errors. */ +declare(strict_types = 1); + use Tester\Assert; require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Utils/Object.magicMethod.inheritance.phpt b/tests/Utils/Object.magicMethod.inheritance.phpt index 5e5d6ccfc..d535ac70a 100644 --- a/tests/Utils/Object.magicMethod.inheritance.phpt +++ b/tests/Utils/Object.magicMethod.inheritance.phpt @@ -4,6 +4,8 @@ * Test: Nette\Object magic @methods inheritance. */ +declare(strict_types = 1); + use Tester\Assert; require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Utils/Object.magicMethod.phpt b/tests/Utils/Object.magicMethod.phpt index b9dcdf7e0..513805476 100644 --- a/tests/Utils/Object.magicMethod.phpt +++ b/tests/Utils/Object.magicMethod.phpt @@ -4,6 +4,8 @@ * Test: Nette\Object magic @methods. */ +declare(strict_types = 1); + use Tester\Assert; require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Utils/Object.magicMethod.types.phpt b/tests/Utils/Object.magicMethod.types.phpt index dea9a6bb2..2d3f363d9 100644 --- a/tests/Utils/Object.magicMethod.types.phpt +++ b/tests/Utils/Object.magicMethod.types.phpt @@ -4,6 +4,8 @@ * Test: Nette\Object magic @methods and types. */ +declare(strict_types = 1); + namespace Test; use Nette; diff --git a/tests/Utils/Object.methodGetter.phpt b/tests/Utils/Object.methodGetter.phpt index d090123df..b31c791d2 100644 --- a/tests/Utils/Object.methodGetter.phpt +++ b/tests/Utils/Object.methodGetter.phpt @@ -4,6 +4,8 @@ * Test: Nette\Object closure properties. */ +declare(strict_types = 1); + use Tester\Assert; require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Utils/Object.property.phpt b/tests/Utils/Object.property.phpt index eed1bb283..25c2c906d 100644 --- a/tests/Utils/Object.property.phpt +++ b/tests/Utils/Object.property.phpt @@ -4,6 +4,8 @@ * Test: Nette\Object properties. */ +declare(strict_types = 1); + use Tester\Assert; require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Utils/Object.referenceProperty.phpt b/tests/Utils/Object.referenceProperty.phpt index 1e704268e..888dd684f 100644 --- a/tests/Utils/Object.referenceProperty.phpt +++ b/tests/Utils/Object.referenceProperty.phpt @@ -4,6 +4,8 @@ * Test: Nette\Object reference to property. */ +declare(strict_types = 1); + use Tester\Assert; require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Utils/Object.reflection.phpt b/tests/Utils/Object.reflection.phpt index 38246bcf2..56a4f39bf 100644 --- a/tests/Utils/Object.reflection.phpt +++ b/tests/Utils/Object.reflection.phpt @@ -4,6 +4,8 @@ * Test: Nette\Object reflection. */ +declare(strict_types = 1); + use Tester\Assert; require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Utils/Object.undeclaredMethod.phpt b/tests/Utils/Object.undeclaredMethod.phpt index 8470f1453..a2940abbe 100644 --- a/tests/Utils/Object.undeclaredMethod.phpt +++ b/tests/Utils/Object.undeclaredMethod.phpt @@ -4,6 +4,8 @@ * Test: Nette\Object undeclared method. */ +declare(strict_types = 1); + use Tester\Assert; require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Utils/Object.unsetProperty.phpt b/tests/Utils/Object.unsetProperty.phpt index c125b0a3e..3e529ca63 100644 --- a/tests/Utils/Object.unsetProperty.phpt +++ b/tests/Utils/Object.unsetProperty.phpt @@ -4,6 +4,8 @@ * Test: Nette\Object properties. */ +declare(strict_types = 1); + use Tester\Assert; require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Utils/ObjectMixin.checkType().phpt b/tests/Utils/ObjectMixin.checkType().phpt index 9b4ebf2cc..d02363097 100644 --- a/tests/Utils/ObjectMixin.checkType().phpt +++ b/tests/Utils/ObjectMixin.checkType().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\ObjectMixin::checkType() */ +declare(strict_types = 1); + use Nette\Utils\ObjectMixin; use Tester\Assert; diff --git a/tests/Utils/Paginator.phpt b/tests/Utils/Paginator.phpt index 08b29da1c..ef2a3efdd 100644 --- a/tests/Utils/Paginator.phpt +++ b/tests/Utils/Paginator.phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Paginator Base:0 Page:3 test. */ +declare(strict_types = 1); + use Nette\Utils\Paginator; use Tester\Assert; diff --git a/tests/Utils/Random.generate().no-mcrypt.phpt b/tests/Utils/Random.generate().no-mcrypt.phpt index 3f33c9676..ff19fdaec 100644 --- a/tests/Utils/Random.generate().no-mcrypt.phpt +++ b/tests/Utils/Random.generate().no-mcrypt.phpt @@ -5,6 +5,8 @@ * @phpIni disable_functions=openssl_random_pseudo_bytes,mcrypt_create_iv */ +declare(strict_types = 1); + use Nette\Utils\Random; use Tester\Assert; diff --git a/tests/Utils/Random.generate().no-openssl.phpt b/tests/Utils/Random.generate().no-openssl.phpt index 4cf341b27..2d64e749a 100644 --- a/tests/Utils/Random.generate().no-openssl.phpt +++ b/tests/Utils/Random.generate().no-openssl.phpt @@ -5,6 +5,8 @@ * @phpIni disable_functions=openssl_random_pseudo_bytes */ +declare(strict_types = 1); + use Nette\Utils\Random; use Tester\Assert; diff --git a/tests/Utils/Random.generate().phpt b/tests/Utils/Random.generate().phpt index fde1ce06d..4036d2498 100644 --- a/tests/Utils/Random.generate().phpt +++ b/tests/Utils/Random.generate().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Random::generate() */ +declare(strict_types = 1); + use Nette\Utils\Random; use Tester\Assert; diff --git a/tests/Utils/Strings.Regexp.errors.backtrack.phpt b/tests/Utils/Strings.Regexp.errors.backtrack.phpt index 7d8a98ccd..cd3d41eac 100644 --- a/tests/Utils/Strings.Regexp.errors.backtrack.phpt +++ b/tests/Utils/Strings.Regexp.errors.backtrack.phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Strings and RegexpException run-time error. */ +declare(strict_types = 1); + use Nette\Utils\Strings; use Tester\Assert; diff --git a/tests/Utils/Strings.Regexp.errors.compilation.phpt b/tests/Utils/Strings.Regexp.errors.compilation.phpt index c59ddd562..99dee2beb 100644 --- a/tests/Utils/Strings.Regexp.errors.compilation.phpt +++ b/tests/Utils/Strings.Regexp.errors.compilation.phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Strings and RegexpException compile error. */ +declare(strict_types = 1); + use Nette\Utils\Strings; use Tester\Assert; diff --git a/tests/Utils/Strings.Regexp.errors.utf8.phpt b/tests/Utils/Strings.Regexp.errors.utf8.phpt index 795185841..7f086c391 100644 --- a/tests/Utils/Strings.Regexp.errors.utf8.phpt +++ b/tests/Utils/Strings.Regexp.errors.utf8.phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Strings and RegexpException run-time error. */ +declare(strict_types = 1); + use Nette\Utils\Strings; use Tester\Assert; diff --git a/tests/Utils/Strings.after().phpt b/tests/Utils/Strings.after().phpt index ab0cf5d72..682a95a6d 100644 --- a/tests/Utils/Strings.after().phpt +++ b/tests/Utils/Strings.after().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Strings::after() */ +declare(strict_types = 1); + use Nette\Utils\Strings; use Tester\Assert; diff --git a/tests/Utils/Strings.before().phpt b/tests/Utils/Strings.before().phpt index 69675c364..897bcabc1 100644 --- a/tests/Utils/Strings.before().phpt +++ b/tests/Utils/Strings.before().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Strings::before() */ +declare(strict_types = 1); + use Nette\Utils\Strings; use Tester\Assert; diff --git a/tests/Utils/Strings.checkEncoding().phpt b/tests/Utils/Strings.checkEncoding().phpt index 3c8f737de..a3298b468 100644 --- a/tests/Utils/Strings.checkEncoding().phpt +++ b/tests/Utils/Strings.checkEncoding().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Strings::checkEncoding() */ +declare(strict_types = 1); + use Nette\Utils\Strings; use Tester\Assert; diff --git a/tests/Utils/Strings.chr().phpt b/tests/Utils/Strings.chr().phpt index acfa9f828..0665137e7 100644 --- a/tests/Utils/Strings.chr().phpt +++ b/tests/Utils/Strings.chr().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Strings::chr() */ +declare(strict_types = 1); + use Nette\Utils\Strings; use Tester\Assert; diff --git a/tests/Utils/Strings.compare().phpt b/tests/Utils/Strings.compare().phpt index 14ea8be27..60fc0c20b 100644 --- a/tests/Utils/Strings.compare().phpt +++ b/tests/Utils/Strings.compare().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Strings::compare() */ +declare(strict_types = 1); + use Nette\Utils\Strings; use Tester\Assert; diff --git a/tests/Utils/Strings.convertCase.phpt b/tests/Utils/Strings.convertCase.phpt index c8f2d86e0..817595844 100644 --- a/tests/Utils/Strings.convertCase.phpt +++ b/tests/Utils/Strings.convertCase.phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Strings and lower, upper, firstLower, firstUpper, capitalize */ +declare(strict_types = 1); + use Nette\Utils\Strings; use Tester\Assert; diff --git a/tests/Utils/Strings.endsWith().phpt b/tests/Utils/Strings.endsWith().phpt index a2fc4c2ab..4bf556aa7 100644 --- a/tests/Utils/Strings.endsWith().phpt +++ b/tests/Utils/Strings.endsWith().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Strings::endsWith() */ +declare(strict_types = 1); + use Nette\Utils\Strings; use Tester\Assert; @@ -11,7 +13,9 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -Assert::true(Strings::endsWith('123', NULL), "endsWith('123', NULL)"); +Assert::exception(function () { + Strings::endsWith('123', NULL); +}, TypeError::class); Assert::true(Strings::endsWith('123', ''), "endsWith('123', '')"); Assert::true(Strings::endsWith('123', '3'), "endsWith('123', '3')"); Assert::false(Strings::endsWith('123', '2'), "endsWith('123', '2')"); diff --git a/tests/Utils/Strings.findPrefix().phpt b/tests/Utils/Strings.findPrefix().phpt index dbb54fd54..b7b80257b 100644 --- a/tests/Utils/Strings.findPrefix().phpt +++ b/tests/Utils/Strings.findPrefix().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Strings::findPrefix() */ +declare(strict_types = 1); + use Nette\Utils\Strings; use Tester\Assert; diff --git a/tests/Utils/Strings.fixEncoding().phpt b/tests/Utils/Strings.fixEncoding().phpt index cf6396ada..3c4ad3649 100644 --- a/tests/Utils/Strings.fixEncoding().phpt +++ b/tests/Utils/Strings.fixEncoding().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Strings::fixEncoding() */ +declare(strict_types = 1); + use Nette\Utils\Strings; use Tester\Assert; diff --git a/tests/Utils/Strings.indent().phpt b/tests/Utils/Strings.indent().phpt index 6843d075e..1b63b7d98 100644 --- a/tests/Utils/Strings.indent().phpt +++ b/tests/Utils/Strings.indent().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Strings::indent() */ +declare(strict_types = 1); + use Nette\Utils\Strings; use Tester\Assert; diff --git a/tests/Utils/Strings.indexOf().phpt b/tests/Utils/Strings.indexOf().phpt index 5cdc26d96..78dc6bdc2 100644 --- a/tests/Utils/Strings.indexOf().phpt +++ b/tests/Utils/Strings.indexOf().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Strings::indexOf() */ +declare(strict_types = 1); + use Nette\Utils\Strings; use Tester\Assert; diff --git a/tests/Utils/Strings.length().phpt b/tests/Utils/Strings.length().phpt index c808213ac..2f1387ed5 100644 --- a/tests/Utils/Strings.length().phpt +++ b/tests/Utils/Strings.length().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Strings::length() */ +declare(strict_types = 1); + use Nette\Utils\Strings; use Tester\Assert; diff --git a/tests/Utils/Strings.match().phpt b/tests/Utils/Strings.match().phpt index 10c91a613..d4b674a57 100644 --- a/tests/Utils/Strings.match().phpt +++ b/tests/Utils/Strings.match().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Strings::match() */ +declare(strict_types = 1); + use Nette\Utils\Strings; use Tester\Assert; diff --git a/tests/Utils/Strings.matchAll().phpt b/tests/Utils/Strings.matchAll().phpt index 2806efad1..c25955e7a 100644 --- a/tests/Utils/Strings.matchAll().phpt +++ b/tests/Utils/Strings.matchAll().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Strings::matchAll() */ +declare(strict_types = 1); + use Nette\Utils\Strings; use Tester\Assert; diff --git a/tests/Utils/Strings.normalize().phpt b/tests/Utils/Strings.normalize().phpt index da298039e..0f803e2b8 100644 --- a/tests/Utils/Strings.normalize().phpt +++ b/tests/Utils/Strings.normalize().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Strings::normalize() */ +declare(strict_types = 1); + use Nette\Utils\Strings; use Tester\Assert; diff --git a/tests/Utils/Strings.normalizeNewLines().phpt b/tests/Utils/Strings.normalizeNewLines().phpt index 67565fbaa..3dc590b31 100644 --- a/tests/Utils/Strings.normalizeNewLines().phpt +++ b/tests/Utils/Strings.normalizeNewLines().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Strings::normalizeNewLines() */ +declare(strict_types = 1); + use Nette\Utils\Strings; use Tester\Assert; diff --git a/tests/Utils/Strings.pad.phpt b/tests/Utils/Strings.pad.phpt index eac150ee7..827f25157 100644 --- a/tests/Utils/Strings.pad.phpt +++ b/tests/Utils/Strings.pad.phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Strings::padLeft() & padRight() */ +declare(strict_types = 1); + use Nette\Utils\Strings; use Tester\Assert; diff --git a/tests/Utils/Strings.random().phpt b/tests/Utils/Strings.random().phpt index 8250be7b9..508bd6bda 100644 --- a/tests/Utils/Strings.random().phpt +++ b/tests/Utils/Strings.random().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Strings::random() */ +declare(strict_types = 1); + use Nette\Utils\Strings; use Tester\Assert; diff --git a/tests/Utils/Strings.replace().errors.callback.phpt b/tests/Utils/Strings.replace().errors.callback.phpt index 0182053e6..625292d2f 100644 --- a/tests/Utils/Strings.replace().errors.callback.phpt +++ b/tests/Utils/Strings.replace().errors.callback.phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Strings and error in callback. */ +declare(strict_types = 1); + use Nette\Utils\Strings; use Tester\Assert; diff --git a/tests/Utils/Strings.replace().php53.phpt b/tests/Utils/Strings.replace().php53.phpt index 7a87fd4ae..1cb3e9297 100644 --- a/tests/Utils/Strings.replace().php53.phpt +++ b/tests/Utils/Strings.replace().php53.phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Strings::replace() */ +declare(strict_types = 1); + use Nette\Utils\Strings; use Tester\Assert; diff --git a/tests/Utils/Strings.replace().phpt b/tests/Utils/Strings.replace().phpt index 6a09dcf4e..edd4a79a9 100644 --- a/tests/Utils/Strings.replace().phpt +++ b/tests/Utils/Strings.replace().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Strings::replace() */ +declare(strict_types = 1); + use Nette\Utils\Strings; use Tester\Assert; diff --git a/tests/Utils/Strings.reverse().phpt b/tests/Utils/Strings.reverse().phpt index 1407cad90..d20cb997a 100644 --- a/tests/Utils/Strings.reverse().phpt +++ b/tests/Utils/Strings.reverse().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Strings::reverse() */ +declare(strict_types = 1); + use Nette\Utils\Strings; use Tester\Assert; diff --git a/tests/Utils/Strings.split().phpt b/tests/Utils/Strings.split().phpt index b77d7a4bd..07f6d1b25 100644 --- a/tests/Utils/Strings.split().phpt +++ b/tests/Utils/Strings.split().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Strings::split() */ +declare(strict_types = 1); + use Nette\Utils\Strings; use Tester\Assert; diff --git a/tests/Utils/Strings.startsWith().phpt b/tests/Utils/Strings.startsWith().phpt index b6f6559bf..4c3efe82a 100644 --- a/tests/Utils/Strings.startsWith().phpt +++ b/tests/Utils/Strings.startsWith().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Strings::startsWith() */ +declare(strict_types = 1); + use Nette\Utils\Strings; use Tester\Assert; @@ -11,7 +13,9 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -Assert::true(Strings::startsWith('123', NULL), "startsWith('123', NULL)"); +Assert::exception(function () { + Strings::startsWith('123', NULL); +}, TypeError::class); Assert::true(Strings::startsWith('123', ''), "startsWith('123', '')"); Assert::true(Strings::startsWith('123', '1'), "startsWith('123', '1')"); Assert::false(Strings::startsWith('123', '2'), "startsWith('123', '2')"); diff --git a/tests/Utils/Strings.substring().phpt b/tests/Utils/Strings.substring().phpt index 69ffd4dc5..b44df4513 100644 --- a/tests/Utils/Strings.substring().phpt +++ b/tests/Utils/Strings.substring().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Strings::substring() */ +declare(strict_types = 1); + use Nette\Utils\Strings; use Tester\Assert; diff --git a/tests/Utils/Strings.toAscii().phpt b/tests/Utils/Strings.toAscii().phpt index 317a80c1e..1640bb8cf 100644 --- a/tests/Utils/Strings.toAscii().phpt +++ b/tests/Utils/Strings.toAscii().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Strings::toAscii() */ +declare(strict_types = 1); + use Nette\Utils\Strings; use Tester\Assert; diff --git a/tests/Utils/Strings.trim().phpt b/tests/Utils/Strings.trim().phpt index c71974733..316ac7344 100644 --- a/tests/Utils/Strings.trim().phpt +++ b/tests/Utils/Strings.trim().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Strings::trim() */ +declare(strict_types = 1); + use Nette\Utils\Strings; use Tester\Assert; diff --git a/tests/Utils/Strings.truncate().phpt b/tests/Utils/Strings.truncate().phpt index 2d2ed933a..d6a638a93 100644 --- a/tests/Utils/Strings.truncate().phpt +++ b/tests/Utils/Strings.truncate().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Strings::truncate() */ +declare(strict_types = 1); + use Nette\Utils\Strings; use Tester\Assert; diff --git a/tests/Utils/Strings.webalize().phpt b/tests/Utils/Strings.webalize().phpt index dfc516448..654a7dc7d 100644 --- a/tests/Utils/Strings.webalize().phpt +++ b/tests/Utils/Strings.webalize().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Strings::webalize() */ +declare(strict_types = 1); + use Nette\Utils\Strings; use Tester\Assert; diff --git a/tests/Utils/Validators.assert().phpt b/tests/Utils/Validators.assert().phpt index bd647b11c..f220f578b 100644 --- a/tests/Utils/Validators.assert().phpt +++ b/tests/Utils/Validators.assert().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Validators::assert() */ +declare(strict_types = 1); + use Nette\Utils\Validators; use Tester\Assert; diff --git a/tests/Utils/Validators.assertField().phpt b/tests/Utils/Validators.assertField().phpt index 9e5729fdf..7571e887a 100644 --- a/tests/Utils/Validators.assertField().phpt +++ b/tests/Utils/Validators.assertField().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Validators::assertField() */ +declare(strict_types = 1); + use Nette\Utils\Validators; use Tester\Assert; diff --git a/tests/Utils/Validators.is().phpt b/tests/Utils/Validators.is().phpt index 4530ad4a6..14e14335f 100644 --- a/tests/Utils/Validators.is().phpt +++ b/tests/Utils/Validators.is().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Validators::is() */ +declare(strict_types = 1); + use Nette\Utils\Validators; use Tester\Assert; diff --git a/tests/Utils/Validators.isInRange().phpt b/tests/Utils/Validators.isInRange().phpt index 77dfc3974..11200ec80 100644 --- a/tests/Utils/Validators.isInRange().phpt +++ b/tests/Utils/Validators.isInRange().phpt @@ -4,6 +4,8 @@ * Test: Nette\Utils\Validators::isInRange() */ +declare(strict_types = 1); + use Nette\Utils\Validators; use Tester\Assert; diff --git a/tests/bootstrap.php b/tests/bootstrap.php index d5af950ff..bcc1b4784 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -3,6 +3,8 @@ // The Nette Tester command-line runner can be // invoked through the command: ../vendor/bin/tester . +declare(strict_types = 1); + if (@!include __DIR__ . '/../vendor/autoload.php') { echo 'Install Nette Tester using `composer install`'; exit(1);