diff --git a/src/Iterators/CachingIterator.php b/src/Iterators/CachingIterator.php
index 0c5538e96..401b97511 100644
--- a/src/Iterators/CachingIterator.php
+++ b/src/Iterators/CachingIterator.php
@@ -57,7 +57,7 @@ public function __construct($iterator)
* @param int grid width
* @return bool
*/
- public function isFirst($width = NULL)
+ public function isFirst($width = null)
{
return $this->counter === 1 || ($width && $this->counter !== 0 && (($this->counter - 1) % $width) === 0);
}
@@ -68,7 +68,7 @@ public function isFirst($width = NULL)
* @param int grid width
* @return bool
*/
- public function isLast($width = NULL)
+ public function isLast($width = null)
{
return !$this->hasNext() || ($width && ($this->counter % $width) === 0);
}
@@ -172,5 +172,4 @@ public function getNextValue()
{
return $this->getInnerIterator()->current();
}
-
}
diff --git a/src/Iterators/Filter.php b/src/Iterators/Filter.php
index d3b64bb5d..430d24b74 100644
--- a/src/Iterators/Filter.php
+++ b/src/Iterators/Filter.php
@@ -32,5 +32,4 @@ public function accept()
{
return call_user_func($this->callback, $this->current(), $this->key(), $this);
}
-
}
diff --git a/src/Iterators/Mapper.php b/src/Iterators/Mapper.php
index 16f1faf28..3593be6fd 100644
--- a/src/Iterators/Mapper.php
+++ b/src/Iterators/Mapper.php
@@ -30,5 +30,4 @@ public function current()
{
return call_user_func($this->callback, parent::current(), parent::key());
}
-
}
diff --git a/src/Iterators/RecursiveFilter.php b/src/Iterators/RecursiveFilter.php
index 8cef36841..f8d2158e4 100644
--- a/src/Iterators/RecursiveFilter.php
+++ b/src/Iterators/RecursiveFilter.php
@@ -14,7 +14,6 @@
*/
class RecursiveFilter extends Filter implements \RecursiveIterator
{
-
public function __construct(\RecursiveIterator $iterator, $callback)
{
trigger_error(__CLASS__ . ' is deprecated, use RecursiveCallbackFilterIterator.', E_USER_WARNING);
@@ -32,5 +31,4 @@ public function getChildren()
{
return new static($this->getInnerIterator()->getChildren(), $this->callback);
}
-
}
diff --git a/src/Utils/ArrayHash.php b/src/Utils/ArrayHash.php
index fa7699f24..91caad70c 100644
--- a/src/Utils/ArrayHash.php
+++ b/src/Utils/ArrayHash.php
@@ -21,12 +21,12 @@ class ArrayHash extends \stdClass implements \ArrayAccess, \Countable, \Iterator
* @param bool
* @return static
*/
- public static function from($arr, $recursive = TRUE)
+ public static function from($arr, $recursive = true)
{
$obj = new static;
foreach ($arr as $key => $value) {
if ($recursive && is_array($value)) {
- $obj->$key = static::from($value, TRUE);
+ $obj->$key = static::from($value, true);
} else {
$obj->$key = $value;
}
@@ -61,7 +61,7 @@ public function count()
*/
public function offsetSet($key, $value)
{
- if (!is_scalar($key)) { // prevents NULL
+ if (!is_scalar($key)) { // prevents null
throw new Nette\InvalidArgumentException(sprintf('Key must be either a string or an integer, %s given.', gettype($key)));
}
$this->$key = $value;
@@ -96,5 +96,4 @@ public function offsetUnset($key)
{
unset($this->$key);
}
-
}
diff --git a/src/Utils/ArrayList.php b/src/Utils/ArrayList.php
index 580fbe4d2..c5c941aff 100644
--- a/src/Utils/ArrayList.php
+++ b/src/Utils/ArrayList.php
@@ -42,14 +42,14 @@ public function count()
/**
* Replaces or appends a item.
- * @param int|NULL
+ * @param int|null
* @param mixed
* @return void
* @throws Nette\OutOfRangeException
*/
public function offsetSet($index, $value)
{
- if ($index === NULL) {
+ if ($index === null) {
$this->list[] = $value;
} elseif ($index < 0 || $index >= count($this->list)) {
@@ -113,5 +113,4 @@ public function prepend($value)
$this->offsetSet(0, $value);
array_splice($this->list, 1, 0, $first);
}
-
}
diff --git a/src/Utils/Arrays.php b/src/Utils/Arrays.php
index 8d7cad71f..ede3450a8 100644
--- a/src/Utils/Arrays.php
+++ b/src/Utils/Arrays.php
@@ -25,7 +25,7 @@ class Arrays
* @return mixed
* @throws Nette\InvalidArgumentException if item does not exist and default value is not provided
*/
- public static function get(array $arr, $key, $default = NULL)
+ public static function get(array $arr, $key, $default = null)
{
foreach (is_array($key) ? $key : [$key] as $k) {
if (is_array($arr) && array_key_exists($k, $arr)) {
@@ -51,7 +51,7 @@ public static function get(array $arr, $key, $default = NULL)
public static function &getRef(array &$arr, $key)
{
foreach (is_array($key) ? $key : [$key] as $k) {
- if (is_array($arr) || $arr === NULL) {
+ if (is_array($arr) || $arr === null) {
$arr = &$arr[$k];
} else {
throw new Nette\InvalidArgumentException('Traversed item is not an array.');
@@ -79,12 +79,12 @@ public static function mergeTree(array $arr1, array $arr2)
/**
* Searches the array for a given key and returns the offset if successful.
- * @return int|FALSE offset if it is found, FALSE otherwise
+ * @return int|false offset if it is found, false otherwise
*/
public static function searchKey(array $arr, $key)
{
- $foo = [$key => NULL];
- return array_search(key($foo), array_keys($arr), TRUE);
+ $foo = [$key => null];
+ return array_search(key($foo), array_keys($arr), true);
}
@@ -95,7 +95,7 @@ public static function searchKey(array $arr, $key)
public static function insertBefore(array &$arr, $key, array $inserted)
{
$offset = (int) self::searchKey($arr, $key);
- $arr = array_slice($arr, 0, $offset, TRUE) + $inserted + array_slice($arr, $offset, count($arr), TRUE);
+ $arr = array_slice($arr, 0, $offset, true) + $inserted + array_slice($arr, $offset, count($arr), true);
}
@@ -106,8 +106,8 @@ public static function insertBefore(array &$arr, $key, array $inserted)
public static function insertAfter(array &$arr, $key, array $inserted)
{
$offset = self::searchKey($arr, $key);
- $offset = $offset === FALSE ? count($arr) : $offset + 1;
- $arr = array_slice($arr, 0, $offset, TRUE) + $inserted + array_slice($arr, $offset, count($arr), TRUE);
+ $offset = $offset === false ? count($arr) : $offset + 1;
+ $arr = array_slice($arr, 0, $offset, true) + $inserted + array_slice($arr, $offset, count($arr), true);
}
@@ -118,7 +118,7 @@ public static function insertAfter(array &$arr, $key, array $inserted)
public static function renameKey(array &$arr, $oldKey, $newKey)
{
$offset = self::searchKey($arr, $oldKey);
- if ($offset !== FALSE) {
+ if ($offset !== false) {
$keys = array_keys($arr);
$keys[$offset] = $newKey;
$arr = array_combine($keys, $arr);
@@ -140,7 +140,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, $preserveKeys = false)
{
$res = [];
$cb = $preserveKeys
@@ -189,7 +189,7 @@ public static function associate(array $arr, $path)
} elseif ($part === '=') {
if (isset($parts[++$i])) {
$x = $row[$parts[$i]];
- $row = NULL;
+ $row = null;
}
} elseif ($part === '->') {
@@ -204,7 +204,7 @@ public static function associate(array $arr, $path)
}
}
- if ($x === NULL) {
+ if ($x === null) {
$x = $row;
}
}
@@ -217,7 +217,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)
{
$res = [];
foreach ($arr as $k => $v) {
@@ -235,7 +235,7 @@ public static function normalize(array $arr, $filling = NULL)
* @return mixed
* @throws Nette\InvalidArgumentException if item does not exist and default value is not provided
*/
- public static function pick(array &$arr, $key, $default = NULL)
+ public static function pick(array &$arr, $key, $default = null)
{
if (array_key_exists($key, $arr)) {
$value = $arr[$key];
@@ -259,10 +259,10 @@ public static function some(array $arr, callable $callback)
{
foreach ($arr as $k => $v) {
if ($callback($v, $k, $arr)) {
- return TRUE;
+ return true;
}
}
- return FALSE;
+ return false;
}
@@ -274,10 +274,10 @@ public static function every(array $arr, callable $callback)
{
foreach ($arr as $k => $v) {
if (!$callback($v, $k, $arr)) {
- return FALSE;
+ return false;
}
}
- return TRUE;
+ return true;
}
@@ -293,5 +293,4 @@ public static function map(array $arr, callable $callback)
}
return $res;
}
-
}
diff --git a/src/Utils/Callback.php b/src/Utils/Callback.php
index bb12ab720..f6e648a35 100644
--- a/src/Utils/Callback.php
+++ b/src/Utils/Callback.php
@@ -22,9 +22,9 @@ class Callback
* @param string method
* @return \Closure
*/
- public static function closure($callable, $m = NULL)
+ public static function closure($callable, $m = null)
{
- if ($m !== NULL) {
+ if ($m !== null) {
$callable = [$callable, $m];
} elseif (is_string($callable) && count($tmp = explode('::', $callable)) === 2) {
@@ -87,11 +87,11 @@ public static function invokeSafe($function, array $args, $onError)
}
if ($file === __FILE__) {
$msg = preg_replace("#^$function\(.*?\): #", '', $message);
- if ($onError($msg, $severity) !== FALSE) {
+ if ($onError($msg, $severity) !== false) {
return;
}
}
- return $prev ? $prev(...func_get_args()) : FALSE;
+ return $prev ? $prev(...func_get_args()) : false;
});
try {
@@ -105,7 +105,7 @@ public static function invokeSafe($function, array $args, $onError)
/**
* @return callable
*/
- public static function check($callable, $syntax = FALSE)
+ public static function check($callable, $syntax = false)
{
if (!is_callable($callable, $syntax)) {
throw new Nette\InvalidArgumentException($syntax
@@ -128,7 +128,7 @@ public static function toString($callable)
} elseif (is_string($callable) && $callable[0] === "\0") {
return '{lambda}';
} else {
- is_callable($callable, TRUE, $textual);
+ is_callable($callable, true, $textual);
return $textual;
}
}
@@ -191,5 +191,4 @@ public static function unwrap(\Closure $closure)
return $r->getName();
}
}
-
}
diff --git a/src/Utils/DateTime.php b/src/Utils/DateTime.php
index 51748c7f3..1638eb94a 100644
--- a/src/Utils/DateTime.php
+++ b/src/Utils/DateTime.php
@@ -52,7 +52,7 @@ public static function from($time)
}
return (new static('@' . $time))->setTimeZone(new \DateTimeZone(date_default_timezone_get()));
- } else { // textual or NULL
+ } else { // textual or null
return new static($time);
}
}
@@ -64,7 +64,7 @@ public static function from($time)
*/
public static function fromParts($year, $month, $day, $hour = 0, $minute = 0, $second = 0)
{
- $s = sprintf("%04d-%02d-%02d %02d:%02d:%02.5f", $year, $month, $day, $hour, $minute, $second);
+ $s = sprintf('%04d-%02d-%02d %02d:%02d:%02.5f', $year, $month, $day, $hour, $minute, $second);
if (!checkdate($month, $day, $year) || $hour < 0 || $hour > 23 || $minute < 0 || $minute > 59 || $second < 0 || $second >= 60) {
throw new Nette\InvalidArgumentException("Invalid date '$s'");
}
@@ -118,12 +118,12 @@ public function getTimestamp()
* Returns new DateTime object formatted according to the specified format.
* @param string The format the $time parameter should be in
* @param string String representing the time
- * @param string|\DateTimeZone desired timezone (default timezone is used if NULL is passed)
- * @return static|FALSE
+ * @param string|\DateTimeZone desired timezone (default timezone is used if null is passed)
+ * @return static|false
*/
- public static function createFromFormat($format, $time, $timezone = NULL)
+ public static function createFromFormat($format, $time, $timezone = null)
{
- if ($timezone === NULL) {
+ if ($timezone === null) {
$timezone = new \DateTimeZone(date_default_timezone_get());
} elseif (is_string($timezone)) {
@@ -134,7 +134,7 @@ public static function createFromFormat($format, $time, $timezone = NULL)
}
$date = parent::createFromFormat($format, $time, $timezone);
- return $date ? static::from($date) : FALSE;
+ return $date ? static::from($date) : false;
}
@@ -146,5 +146,4 @@ public function jsonSerialize()
{
return $this->format('c');
}
-
}
diff --git a/src/Utils/FileSystem.php b/src/Utils/FileSystem.php
index 5402d0fc8..3f05b2b20 100644
--- a/src/Utils/FileSystem.php
+++ b/src/Utils/FileSystem.php
@@ -24,7 +24,7 @@ class FileSystem
*/
public static function createDir($dir, $mode = 0777)
{
- if (!is_dir($dir) && !@mkdir($dir, $mode, TRUE) && !is_dir($dir)) { // @ - dir may already exist
+ if (!is_dir($dir) && !@mkdir($dir, $mode, true) && !is_dir($dir)) { // @ - dir may already exist
throw new Nette\IOException("Unable to create directory '$dir'. " . error_get_last()['message']);
}
}
@@ -35,7 +35,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($source, $dest, $overwrite = true)
{
if (stream_is_local($source) && !file_exists($source)) {
throw new Nette\IOException("File or directory '$source' not found.");
@@ -58,7 +58,7 @@ public static function copy($source, $dest, $overwrite = TRUE)
} else {
static::createDir(dirname($dest));
- if (@stream_copy_to_stream(fopen($source, 'r'), fopen($dest, 'w')) === FALSE) { // @ is escalated to exception
+ if (@stream_copy_to_stream(fopen($source, 'r'), fopen($dest, 'w')) === false) { // @ is escalated to exception
throw new Nette\IOException("Unable to copy file '$source' to '$dest'.");
}
}
@@ -95,7 +95,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($name, $newName, $overwrite = true)
{
if (!$overwrite && file_exists($newName)) {
throw new Nette\InvalidStateException("File or directory '$newName' already exists.");
@@ -121,7 +121,7 @@ public static function rename($name, $newName, $overwrite = TRUE)
public static function read($file)
{
$content = @file_get_contents($file); // @ is escalated to exception
- if ($content === FALSE) {
+ if ($content === false) {
throw new Nette\IOException("Unable to read file '$file'.");
}
return $content;
@@ -136,10 +136,10 @@ public static function read($file)
public static function write($file, $content, $mode = 0666)
{
static::createDir(dirname($file));
- if (@file_put_contents($file, $content) === FALSE) { // @ is escalated to exception
+ if (@file_put_contents($file, $content) === false) { // @ is escalated to exception
throw new Nette\IOException("Unable to write file '$file'.");
}
- if ($mode !== NULL && !@chmod($file, $mode)) { // @ is escalated to exception
+ if ($mode !== null && !@chmod($file, $mode)) { // @ is escalated to exception
throw new Nette\IOException("Unable to chmod file '$file'.");
}
}
@@ -153,5 +153,4 @@ public static function isAbsolute($path)
{
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 bb66b4f11..84de184e4 100644
--- a/src/Utils/Html.php
+++ b/src/Utils/Html.php
@@ -25,20 +25,11 @@ class Html implements \ArrayAccess, \Countable, \IteratorAggregate, IHtmlString
{
use Nette\SmartObject;
- /** @var string element's name */
- private $name;
-
- /** @var bool is element empty? */
- private $isEmpty;
-
/** @var array element's attributes */
public $attrs = [];
- /** @var array of Html | string nodes */
- protected $children = [];
-
/** @var bool use XHTML syntax? */
- public static $xhtml = FALSE;
+ public static $xhtml = false;
/** @var array empty (void) elements */
public static $emptyElements = [
@@ -47,14 +38,23 @@ class Html implements \ArrayAccess, \Countable, \IteratorAggregate, IHtmlString
'isindex' => 1, 'wbr' => 1, 'command' => 1, 'track' => 1,
];
+ /** @var array of Html | string nodes */
+ protected $children = [];
+
+ /** @var string element's name */
+ private $name;
+
+ /** @var bool is element empty? */
+ private $isEmpty;
+
/**
* Static factory.
- * @param string element name (or NULL)
+ * @param string element name (or null)
* @param array|string element's attributes or plain text content
* @return static
*/
- public static function el($name = NULL, $attrs = NULL)
+ public static function el($name = null, $attrs = null)
{
$el = new static;
$parts = explode(' ', (string) $name, 2);
@@ -63,13 +63,13 @@ public static function el($name = NULL, $attrs = NULL)
if (is_array($attrs)) {
$el->attrs = $attrs;
- } elseif ($attrs !== NULL) {
+ } elseif ($attrs !== null) {
$el->setText($attrs);
}
if (isset($parts[1])) {
foreach (Strings::matchAll($parts[1] . ' ', '#([a-z0-9:-]+)(?:=(["\'])?(.*?)(?(2)\\2|\s))?#i') as $m) {
- $el->attrs[$m[1]] = isset($m[3]) ? $m[3] : TRUE;
+ $el->attrs[$m[1]] = isset($m[3]) ? $m[3] : true;
}
}
@@ -84,14 +84,14 @@ public static function el($name = NULL, $attrs = NULL)
* @return static
* @throws Nette\InvalidArgumentException
*/
- public function setName($name, $isEmpty = NULL)
+ public function setName($name, $isEmpty = null)
{
- if ($name !== NULL && !is_string($name)) {
- throw new Nette\InvalidArgumentException(sprintf('Name must be string or NULL, %s given.', gettype($name)));
+ if ($name !== null && !is_string($name)) {
+ throw new Nette\InvalidArgumentException(sprintf('Name must be string or null, %s given.', gettype($name)));
}
$this->name = $name;
- $this->isEmpty = $isEmpty === NULL ? isset(static::$emptyElements[$name]) : (bool) $isEmpty;
+ $this->isEmpty = $isEmpty === null ? isset(static::$emptyElements[$name]) : (bool) $isEmpty;
return $this;
}
@@ -135,7 +135,7 @@ public function addAttributes(array $attrs)
* @param string|bool value option
* @return static
*/
- public function appendAttribute($name, $value, $option = TRUE)
+ public function appendAttribute($name, $value, $option = true)
{
if (is_array($value)) {
$prev = isset($this->attrs[$name]) ? (array) $this->attrs[$name] : [];
@@ -148,7 +148,7 @@ public function appendAttribute($name, $value, $option = TRUE)
$this->attrs[$name][$value] = $option;
} else {
- $this->attrs[$name] = [$this->attrs[$name] => TRUE, $value => $option];
+ $this->attrs[$name] = [$this->attrs[$name] => true, $value => $option];
}
return $this;
}
@@ -174,7 +174,7 @@ public function setAttribute($name, $value)
*/
public function getAttribute($name)
{
- return isset($this->attrs[$name]) ? $this->attrs[$name] : NULL;
+ return isset($this->attrs[$name]) ? $this->attrs[$name] : null;
}
@@ -248,10 +248,10 @@ public function __call($m, $args)
$m = substr($m, 3);
$m[0] = $m[0] | "\x20";
if ($p === 'get') {
- return isset($this->attrs[$m]) ? $this->attrs[$m] : NULL;
+ return isset($this->attrs[$m]) ? $this->attrs[$m] : null;
} elseif ($p === 'add') {
- $args[] = TRUE;
+ $args[] = true;
}
}
@@ -274,7 +274,7 @@ public function __call($m, $args)
* @param array query
* @return static
*/
- public function href($path, $query = NULL)
+ public function href($path, $query = null)
{
if ($query) {
$query = http_build_query($query, '', '&');
@@ -291,7 +291,7 @@ public function href($path, $query = NULL)
* Setter for data-* attributes. Booleans are converted to 'true' resp. 'false'.
* @return static
*/
- public function data($name, $value = NULL)
+ public function data($name, $value = null)
{
if (func_num_args() === 1) {
$this->attrs['data'] = $name;
@@ -379,7 +379,7 @@ public function add($child)
*/
public function addHtml($child)
{
- return $this->insert(NULL, $child);
+ return $this->insert(null, $child);
}
@@ -391,7 +391,7 @@ public function addHtml($child)
public function addText($text)
{
$text = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');
- return $this->insert(NULL, $text);
+ return $this->insert(null, $text);
}
@@ -401,25 +401,25 @@ public function addText($text)
* @param array|string element's attributes or raw HTML string
* @return static created element
*/
- public function create($name, $attrs = NULL)
+ public function create($name, $attrs = null)
{
- $this->insert(NULL, $child = static::el($name, $attrs));
+ $this->insert(null, $child = static::el($name, $attrs));
return $child;
}
/**
* Inserts child node.
- * @param int|NULL position or NULL for appending
+ * @param int|null position or null for appending
* @param Html|string Html node or raw HTML string
* @param bool
* @return static
* @throws Nette\InvalidArgumentException
*/
- public function insert($index, $child, $replace = FALSE)
+ public function insert($index, $child, $replace = false)
{
if ($child instanceof self || is_scalar($child)) {
- if ($index === NULL) { // append
+ if ($index === null) { // append
$this->children[] = $child;
} else { // insert or replace
@@ -436,13 +436,13 @@ public function insert($index, $child, $replace = FALSE)
/**
* Inserts (replaces) child node (\ArrayAccess implementation).
- * @param int|NULL position or NULL for appending
+ * @param int|null position or null for appending
* @param Html|string Html node or raw HTML string
* @return void
*/
public function offsetSet($index, $child)
{
- $this->insert($index, $child, TRUE);
+ $this->insert($index, $child, true);
}
@@ -526,13 +526,13 @@ public function getChildren()
* @param int
* @return string
*/
- public function render($indent = NULL)
+ public function render($indent = null)
{
$s = $this->startTag();
if (!$this->isEmpty) {
// add content
- if ($indent !== NULL) {
+ if ($indent !== null) {
$indent++;
}
foreach ($this->children as $child) {
@@ -547,7 +547,7 @@ public function render($indent = NULL)
$s .= $this->endTag();
}
- if ($indent !== NULL) {
+ if ($indent !== null) {
return "\n" . str_repeat("\t", $indent - 1) . $s . "\n" . str_repeat("\t", max(0, $indent - 2));
}
return $s;
@@ -558,10 +558,10 @@ public function __toString()
{
try {
return $this->render();
- } catch (\Throwable $e) {
} catch (\Exception $e) {
+ } catch (\Throwable $e) {
}
- trigger_error("Exception in " . __METHOD__ . "(): {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}", E_USER_ERROR);
+ trigger_error('Exception in ' . __METHOD__ . "(): {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}", E_USER_ERROR);
}
@@ -612,10 +612,10 @@ public function attributes()
}
foreach ($attrs as $key => $value) {
- if ($value === NULL || $value === FALSE) {
+ if ($value === null || $value === false) {
continue;
- } elseif ($value === TRUE) {
+ } elseif ($value === true) {
if (static::$xhtml) {
$s .= ' ' . $key . '="' . $key . '"';
} else {
@@ -628,14 +628,14 @@ public function attributes()
$value = Json::encode($value);
} else {
- $tmp = NULL;
+ $tmp = null;
foreach ($value as $k => $v) {
- if ($v != NULL) { // intentionally ==, skip NULLs & empty string
+ if ($v != null) { // intentionally ==, skip nulls & empty string
// composite 'style' vs. 'others'
- $tmp[] = $v === TRUE ? $k : (is_string($k) ? $k . ':' . $v : $v);
+ $tmp[] = $v === true ? $k : (is_string($k) ? $k . ':' . $v : $v);
}
}
- if ($tmp === NULL) {
+ if ($tmp === null) {
continue;
}
@@ -649,14 +649,14 @@ public function attributes()
$value = (string) $value;
}
- $q = strpos($value, '"') === FALSE ? '"' : "'";
+ $q = strpos($value, '"') === false ? '"' : "'";
$s .= ' ' . $key . '=' . $q
. str_replace(
['&', $q, '<'],
['&', $q === '"' ? '"' : ''', self::$xhtml ? '<' : '<'],
$value
)
- . (strpos($value, '`') !== FALSE && strpbrk($value, ' <>"\'') === FALSE ? ' ' : '')
+ . (strpos($value, '`') !== false && strpbrk($value, ' <>"\'') === false ? ' ' : '')
. $q;
}
@@ -676,5 +676,4 @@ public function __clone()
}
}
}
-
}
diff --git a/src/Utils/IHtmlString.php b/src/Utils/IHtmlString.php
index 71e44ca94..943349e2a 100644
--- a/src/Utils/IHtmlString.php
+++ b/src/Utils/IHtmlString.php
@@ -15,5 +15,4 @@ interface IHtmlString
* @return string in HTML format
*/
function __toString();
-
}
diff --git a/src/Utils/ITranslator.php b/src/Utils/ITranslator.php
index 6c62415e6..02cb22408 100644
--- a/src/Utils/ITranslator.php
+++ b/src/Utils/ITranslator.php
@@ -20,6 +20,5 @@ interface ITranslator
* @param int plural count
* @return string
*/
- function translate($message, $count = NULL);
-
+ function translate($message, $count = null);
}
diff --git a/src/Utils/Image.php b/src/Utils/Image.php
index 010d5a5b6..e220194e7 100644
--- a/src/Utils/Image.php
+++ b/src/Utils/Image.php
@@ -40,7 +40,7 @@
* @method void colorSet($index, $red, $green, $blue)
* @method array colorsForIndex($index)
* @method int colorsTotal()
- * @method int colorTransparent($color = NULL)
+ * @method int colorTransparent($color = null)
* @method void convolution(array $matrix, float $div, float $offset)
* @method void copy(Image $src, $dstX, $dstY, $srcX, $srcY, $srcW, $srcH)
* @method void copyMerge(Image $src, $dstX, $dstY, $srcX, $srcY, $srcW, $srcH, $opacity)
@@ -58,16 +58,16 @@
* @method void fillToBorder($x, $y, $border, $color)
* @method void filter($filtertype)
* @method void flip(int $mode)
- * @method array ftText($size, $angle, $x, $y, $col, string $fontFile, string $text, array $extrainfo = NULL)
+ * @method array ftText($size, $angle, $x, $y, $col, string $fontFile, string $text, array $extrainfo = null)
* @method void gammaCorrect(float $inputgamma, float $outputgamma)
- * @method int interlace($interlace = NULL)
+ * @method int interlace($interlace = null)
* @method bool isTrueColor()
* @method void layerEffect($effect)
* @method void line($x1, $y1, $x2, $y2, $color)
* @method void paletteCopy(Image $source)
* @method void paletteToTrueColor()
* @method void polygon(array $points, $numPoints, $color)
- * @method array psText(string $text, $font, $size, $color, $backgroundColor, $x, $y, $space = NULL, $tightness = NULL, float $angle = NULL, $antialiasSteps = NULL)
+ * @method array psText(string $text, $font, $size, $color, $backgroundColor, $x, $y, $space = null, $tightness = null, float $angle = null, $antialiasSteps = null)
* @method void rectangle($x1, $y1, $x2, $y2, $col)
* @method Image rotate(float $angle, $backgroundColor)
* @method void saveAlpha(bool $saveflag)
@@ -149,18 +149,18 @@ public static function rgb($red, $green, $blue, $transparency = 0)
* @throws UnknownImageFileException if file not found or file type is not known
* @return static
*/
- public static function fromFile($file, &$format = NULL)
+ public static function fromFile($file, &$format = null)
{
if (!extension_loaded('gd')) {
throw new Nette\NotSupportedException('PHP extension GD is not loaded.');
}
$format = @getimagesize($file)[2]; // @ - files smaller than 12 bytes causes read error
- if (!$format && PHP_VERSION_ID < 70100 && @file_get_contents($file, FALSE, NULL, 8, 4) === 'WEBP') { // @ - may not exists
+ if (!$format && PHP_VERSION_ID < 70100 && @file_get_contents($file, false, null, 8, 4) === 'WEBP') { // @ - may not exists
$format = self::WEBP;
}
if (!isset(self::$formats[$format])) {
- $format = NULL;
+ $format = null;
throw new UnknownImageFileException(is_file($file) ? "Unknown type of file '$file'." : "File '$file' not found.");
}
return new static(Callback::invokeSafe('imagecreatefrom' . self::$formats[$format], [$file], function ($message) {
@@ -176,7 +176,7 @@ public static function fromFile($file, &$format = NULL)
* @return static
* @throws ImageException
*/
- public static function fromString($s, &$format = NULL)
+ public static function fromString($s, &$format = null)
{
if (!extension_loaded('gd')) {
throw new Nette\NotSupportedException('PHP extension GD is not loaded.');
@@ -184,7 +184,7 @@ public static function fromString($s, &$format = NULL)
if (func_num_args() > 1) {
$tmp = @getimagesizefromstring($s)[2]; // @ - strings smaller than 12 bytes causes read error
- $format = isset(self::$formats[$tmp]) ? $tmp : NULL;
+ $format = isset(self::$formats[$tmp]) ? $tmp : null;
}
return new static(Callback::invokeSafe('imagecreatefromstring', [$s], function ($message) {
@@ -200,7 +200,7 @@ public static function fromString($s, &$format = NULL)
* @param array
* @return static
*/
- public static function fromBlank($width, $height, $color = NULL)
+ public static function fromBlank($width, $height, $color = null)
{
if (!extension_loaded('gd')) {
throw new Nette\NotSupportedException('PHP extension GD is not loaded.');
@@ -216,9 +216,9 @@ public static function fromBlank($width, $height, $color = NULL)
if (is_array($color)) {
$color += ['alpha' => 0];
$color = imagecolorresolvealpha($image, $color['red'], $color['green'], $color['blue'], $color['alpha']);
- imagealphablending($image, FALSE);
+ imagealphablending($image, false);
imagefilledrectangle($image, 0, 0, $width - 1, $height - 1, $color);
- imagealphablending($image, TRUE);
+ imagealphablending($image, true);
}
return new static($image);
}
@@ -231,7 +231,7 @@ public static function fromBlank($width, $height, $color = NULL)
public function __construct($image)
{
$this->setImageResource($image);
- imagesavealpha($image, TRUE);
+ imagesavealpha($image, true);
}
@@ -325,7 +325,7 @@ public static function calculateSize($srcWidth, $srcHeight, $newWidth, $newHeigh
{
if (is_string($newWidth) && substr($newWidth, -1) === '%') {
$newWidth = (int) round($srcWidth / 100 * abs(substr($newWidth, 0, -1)));
- $percents = TRUE;
+ $percents = true;
} else {
$newWidth = (int) abs($newWidth);
}
@@ -487,7 +487,7 @@ public function place(Image $image, $left = 0, $top = 0, $opacity = 100)
}
$output = imagecreatetruecolor($width, $height);
- imagealphablending($output, FALSE);
+ imagealphablending($output, false);
if (!$image->isTrueColor()) {
$input = $output;
imagefilledrectangle($output, 0, 0, $width, $height, imagecolorallocatealpha($output, 0, 0, 0, 127));
@@ -500,7 +500,7 @@ public function place(Image $image, $left = 0, $top = 0, $opacity = 100)
\imagesetpixel($output, $x, $y, $c);
}
}
- imagealphablending($output, TRUE);
+ imagealphablending($output, true);
}
imagecopy(
@@ -516,33 +516,33 @@ public function place(Image $image, $left = 0, $top = 0, $opacity = 100)
* @param string filename
* @param int quality (0..100 for JPEG and WEBP, 0..9 for PNG)
* @param int optional image type
- * @return bool TRUE on success or FALSE on failure.
+ * @return bool true on success or false on failure.
*/
- public function save($file = NULL, $quality = NULL, $type = NULL)
+ public function save($file = null, $quality = null, $type = null)
{
- if ($type === NULL) {
+ if ($type === null) {
$extensions = array_flip(self::$formats) + ['jpg' => self::JPEG];
$ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
if (!isset($extensions[$ext])) {
- throw new Nette\InvalidArgumentException("Unsupported file extension '$ext'.");
+ throw new Nette\InvalidArgumentException("Unsupported file extension '$ext'.");
}
$type = $extensions[$ext];
}
switch ($type) {
case self::JPEG:
- $quality = $quality === NULL ? 85 : max(0, min(100, (int) $quality));
+ $quality = $quality === null ? 85 : max(0, min(100, (int) $quality));
return imagejpeg($this->image, $file, $quality);
case self::PNG:
- $quality = $quality === NULL ? 9 : max(0, min(9, (int) $quality));
+ $quality = $quality === null ? 9 : max(0, min(9, (int) $quality));
return imagepng($this->image, $file, $quality);
case self::GIF:
return imagegif($this->image, $file);
case self::WEBP:
- $quality = $quality === NULL ? 80 : max(0, min(100, (int) $quality));
+ $quality = $quality === null ? 80 : max(0, min(100, (int) $quality));
return imagewebp($this->image, $file, $quality);
default:
@@ -557,10 +557,10 @@ public function save($file = NULL, $quality = NULL, $type = NULL)
* @param int quality (0..100 for JPEG and WEBP, 0..9 for PNG)
* @return string
*/
- public function toString($type = self::JPEG, $quality = NULL)
+ public function toString($type = self::JPEG, $quality = null)
{
ob_start(function () {});
- $this->save(NULL, $quality, $type);
+ $this->save(null, $quality, $type);
return ob_get_clean();
}
@@ -573,14 +573,14 @@ public function __toString()
{
try {
return $this->toString();
- } catch (\Throwable $e) {
} catch (\Exception $e) {
+ } catch (\Throwable $e) {
}
if (isset($e)) {
if (func_num_args()) {
throw $e;
}
- trigger_error("Exception in " . __METHOD__ . "(): {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}", E_USER_ERROR);
+ trigger_error('Exception in ' . __METHOD__ . "(): {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}", E_USER_ERROR);
}
}
@@ -589,15 +589,15 @@ public function __toString()
* Outputs image to browser.
* @param int image type
* @param int quality (0..100 for JPEG and WEBP, 0..9 for PNG)
- * @return bool TRUE on success or FALSE on failure.
+ * @return bool true on success or false on failure.
*/
- public function send($type = self::JPEG, $quality = NULL)
+ public function send($type = self::JPEG, $quality = null)
{
if (!isset(self::$formats[$type])) {
throw new Nette\InvalidArgumentException("Unsupported image type '$type'.");
}
header('Content-Type: image/' . self::$formats[$type]);
- return $this->save(NULL, $quality, $type);
+ return $this->save(null, $quality, $type);
}
@@ -642,4 +642,12 @@ public function __clone()
$this->setImageResource(imagecreatefromstring(ob_get_clean()));
}
+
+ /**
+ * Prevents serialization.
+ */
+ public function __sleep()
+ {
+ throw new Nette\NotSupportedException('You cannot serialize or unserialize ' . self::class . ' instances.');
+ }
}
diff --git a/src/Utils/Json.php b/src/Utils/Json.php
index d0620d38d..4846353a9 100644
--- a/src/Utils/Json.php
+++ b/src/Utils/Json.php
@@ -77,5 +77,4 @@ public static function decode($json, $options = 0)
return $value;
}
-
}
diff --git a/src/Utils/Object.php b/src/Utils/Object.php
index 505d65706..59e59f285 100644
--- a/src/Utils/Object.php
+++ b/src/Utils/Object.php
@@ -94,15 +94,15 @@ public static function __callStatic($name, $args)
* @param callable
* @return mixed
*/
- public static function extensionMethod($name, $callback = NULL)
+ public static function extensionMethod($name, $callback = null)
{
- if (strpos($name, '::') === FALSE) {
+ if (strpos($name, '::') === false) {
$class = get_called_class();
} else {
list($class, $name) = explode('::', $name);
$class = (new \ReflectionClass($class))->getName();
}
- if ($callback === NULL) {
+ if ($callback === null) {
return Nette\Utils\ObjectMixin::getExtensionMethod($class, $name);
} else {
Nette\Utils\ObjectMixin::setExtensionMethod($class, $name, $callback);
@@ -156,5 +156,4 @@ public function __unset($name)
{
Nette\Utils\ObjectMixin::remove($this, $name);
}
-
}
diff --git a/src/Utils/ObjectMixin.php b/src/Utils/ObjectMixin.php
index 369cdd4ea..1a285528b 100644
--- a/src/Utils/ObjectMixin.php
+++ b/src/Utils/ObjectMixin.php
@@ -108,8 +108,8 @@ public static function call($_this, $name, $args)
foreach ($_this->$name as $handler) {
Callback::invokeArgs($handler, $args);
}
- } elseif ($_this->$name !== NULL) {
- throw new Nette\UnexpectedValueException("Property $class::$$name must be array or NULL, " . gettype($_this->$name) . ' given.');
+ } elseif ($_this->$name !== null) {
+ throw new Nette\UnexpectedValueException("Property $class::$$name must be array or null, " . gettype($_this->$name) . ' given.');
}
} elseif ($isProp && $_this->$name instanceof \Closure) { // closure in property
@@ -178,7 +178,7 @@ public static function &get($_this, $name)
if ($methods[$m] === 0) {
$methods[$m] = (new \ReflectionMethod($class, $m))->returnsReference();
}
- if ($methods[$m] === TRUE) {
+ if ($methods[$m] === true) {
return $_this->$m();
} else {
$val = $_this->$m();
@@ -274,7 +274,7 @@ public static function getMagicProperties($class)
{
static $cache;
$props = &$cache[$class];
- if ($props !== NULL) {
+ if ($props !== null) {
return $props;
}
@@ -314,7 +314,7 @@ public static function getMagicProperties($class)
public static function getMagicProperty($class, $name)
{
$props = self::getMagicProperties($class);
- return isset($props[$name]) ? $props[$name] : NULL;
+ return isset($props[$name]) ? $props[$name] : null;
}
@@ -343,9 +343,9 @@ public static function getMagicMethods($class)
$name = $op . $prop;
$prop = strtolower($prop[0]) . substr($prop, 1) . ($op === 'add' ? 's' : '');
if ($rc->hasProperty($prop) && ($rp = $rc->getProperty($prop)) && !$rp->isStatic()) {
- $rp->setAccessible(TRUE);
+ $rp->setAccessible(true);
if ($op === 'get' || $op === 'is') {
- $type = NULL;
+ $type = null;
$op = 'get';
} elseif (!$type && preg_match('#@var[ \t]+(\S+)' . ($op === 'add' ? '\[\]#' : '#'), (string) $rp->getDocComment(), $m)) {
$type = $m[1];
@@ -367,53 +367,53 @@ public static function getMagicMethods($class)
*/
public static function checkType(&$val, $type)
{
- if (strpos($type, '|') !== FALSE) {
- $found = NULL;
+ if (strpos($type, '|') !== false) {
+ $found = null;
foreach (explode('|', $type) as $type) {
$tmp = $val;
if (self::checkType($tmp, $type)) {
if ($val === $tmp) {
- return TRUE;
+ return true;
}
$found[] = $tmp;
}
}
if ($found) {
$val = $found[0];
- return TRUE;
+ return true;
}
- return FALSE;
+ return false;
} elseif (substr($type, -2) === '[]') {
if (!is_array($val)) {
- return FALSE;
+ return false;
}
$type = substr($type, 0, -2);
$res = [];
foreach ($val as $k => $v) {
if (!self::checkType($v, $type)) {
- return FALSE;
+ return false;
}
$res[$k] = $v;
}
$val = $res;
- return TRUE;
+ return true;
}
switch (strtolower($type)) {
- case NULL:
+ case null:
case 'mixed':
- return TRUE;
+ return true;
case 'bool':
case 'boolean':
- return ($val === NULL || is_scalar($val)) && settype($val, 'bool');
+ return ($val === null || is_scalar($val)) && settype($val, 'bool');
case 'string':
- return ($val === NULL || is_scalar($val) || (is_object($val) && method_exists($val, '__toString'))) && settype($val, 'string');
+ return ($val === null || is_scalar($val) || (is_object($val) && method_exists($val, '__toString'))) && settype($val, 'string');
case 'int':
case 'integer':
- return ($val === NULL || is_bool($val) || is_numeric($val)) && ((float) (int) $val === (float) $val) && settype($val, 'int');
+ return ($val === null || is_bool($val) || is_numeric($val)) && ((float) (int) $val === (float) $val) && settype($val, 'int');
case 'float':
- return ($val === NULL || is_bool($val) || is_numeric($val)) && settype($val, 'float');
+ return ($val === null || is_bool($val) || is_numeric($val)) && settype($val, 'float');
case 'scalar':
case 'array':
case 'object':
@@ -441,7 +441,7 @@ public static function setExtensionMethod($class, $name, $callback)
{
$name = strtolower($name);
self::$extMethods[$name][$class] = Callback::check($callback);
- self::$extMethods[$name][''] = NULL;
+ self::$extMethods[$name][''] = null;
}
@@ -464,7 +464,7 @@ public static function getExtensionMethod($class, $name)
return $cache = $list[$cl];
}
}
- return $cache = FALSE;
+ return $cache = false;
}
@@ -490,13 +490,13 @@ public static function getExtensionMethods($class)
/**
* Finds the best suggestion (for 8-bit encoding).
- * @return string|NULL
+ * @return string|null
* @internal
*/
public static function getSuggestion(array $possibilities, $value)
{
$norm = preg_replace($re = '#^(get|set|has|is|add)(?=[A-Z])#', '', $value);
- $best = NULL;
+ $best = null;
$min = (strlen($value) / 4 + 1) * 10 + .1;
foreach (array_unique($possibilities, SORT_REGULAR) as $item) {
$item = $item instanceof \Reflector ? $item->getName() : $item;
@@ -535,12 +535,12 @@ public static function hasProperty($class, $name)
{
static $cache;
$prop = &$cache[$class][$name];
- if ($prop === NULL) {
- $prop = FALSE;
+ if ($prop === null) {
+ $prop = false;
try {
$rp = new \ReflectionProperty($class, $name);
if ($rp->isPublic() && !$rp->isStatic()) {
- $prop = $name >= 'onA' && $name < 'on_' ? 'event' : TRUE;
+ $prop = $name >= 'onA' && $name < 'on_' ? 'event' : true;
}
} catch (\ReflectionException $e) {
}
@@ -576,5 +576,4 @@ public static function getSource()
}
}
}
-
}
diff --git a/src/Utils/Paginator.php b/src/Utils/Paginator.php
index 1f72dcc37..dfc4c127c 100644
--- a/src/Utils/Paginator.php
+++ b/src/Utils/Paginator.php
@@ -15,16 +15,16 @@
*
* @property int $page
* @property-read int $firstPage
- * @property-read int|NULL $lastPage
+ * @property-read int|null $lastPage
* @property int $base
* @property-read bool $first
* @property-read bool $last
- * @property-read int|NULL $pageCount
+ * @property-read int|null $pageCount
* @property int $itemsPerPage
- * @property int|NULL $itemCount
+ * @property int|null $itemCount
* @property-read int $offset
- * @property-read int|NULL $countdownOffset
- * @property-read int|NULL $length
+ * @property-read int|null $countdownOffset
+ * @property-read int|null $length
*/
class Paginator
{
@@ -39,7 +39,7 @@ class Paginator
/** @var int */
private $page;
- /** @var int|NULL */
+ /** @var int|null */
private $itemCount;
@@ -77,11 +77,11 @@ public function getFirstPage()
/**
* Returns last page number.
- * @return int|NULL
+ * @return int|null
*/
public function getLastPage()
{
- return $this->itemCount === NULL ? NULL : $this->base + max(0, $this->getPageCount() - 1);
+ return $this->itemCount === null ? null : $this->base + max(0, $this->getPageCount() - 1);
}
@@ -114,7 +114,7 @@ public function getBase()
protected function getPageIndex()
{
$index = max(0, $this->page - $this->base);
- return $this->itemCount === NULL ? $index : min($index, max(0, $this->getPageCount() - 1));
+ return $this->itemCount === null ? $index : min($index, max(0, $this->getPageCount() - 1));
}
@@ -134,17 +134,17 @@ public function isFirst()
*/
public function isLast()
{
- return $this->itemCount === NULL ? FALSE : $this->getPageIndex() >= $this->getPageCount() - 1;
+ return $this->itemCount === null ? false : $this->getPageIndex() >= $this->getPageCount() - 1;
}
/**
* Returns the total number of pages.
- * @return int|NULL
+ * @return int|null
*/
public function getPageCount()
{
- return $this->itemCount === NULL ? NULL : (int) ceil($this->itemCount / $this->itemsPerPage);
+ return $this->itemCount === null ? null : (int) ceil($this->itemCount / $this->itemsPerPage);
}
@@ -172,19 +172,19 @@ public function getItemsPerPage()
/**
* Sets the total number of items.
- * @param int (or NULL as infinity)
+ * @param int (or null as infinity)
* @return static
*/
public function setItemCount($itemCount)
{
- $this->itemCount = ($itemCount === FALSE || $itemCount === NULL) ? NULL : max(0, (int) $itemCount);
+ $this->itemCount = ($itemCount === false || $itemCount === null) ? null : max(0, (int) $itemCount);
return $this;
}
/**
* Returns the total number of items.
- * @return int|NULL
+ * @return int|null
*/
public function getItemCount()
{
@@ -204,25 +204,24 @@ public function getOffset()
/**
* Returns the absolute index of the first item on current page in countdown paging.
- * @return int|NULL
+ * @return int|null
*/
public function getCountdownOffset()
{
- return $this->itemCount === NULL
- ? NULL
+ return $this->itemCount === null
+ ? null
: max(0, $this->itemCount - ($this->getPageIndex() + 1) * $this->itemsPerPage);
}
/**
* Returns the number of items on current page.
- * @return int|NULL
+ * @return int|null
*/
public function getLength()
{
- return $this->itemCount === NULL
+ return $this->itemCount === null
? $this->itemsPerPage
: min($this->itemsPerPage, $this->itemCount - $this->getPageIndex() * $this->itemsPerPage);
}
-
}
diff --git a/src/Utils/Random.php b/src/Utils/Random.php
index ce6d80d87..f1895f139 100644
--- a/src/Utils/Random.php
+++ b/src/Utils/Random.php
@@ -55,10 +55,10 @@ public static function generate($length = 10, $charlist = '0-9a-z')
$bytes = (string) mcrypt_create_iv($length, MCRYPT_DEV_URANDOM);
}
if (strlen($bytes) < $length && !defined('PHP_WINDOWS_VERSION_BUILD') && is_readable('/dev/urandom')) {
- $bytes = (string) file_get_contents('/dev/urandom', FALSE, NULL, -1, $length);
+ $bytes = (string) file_get_contents('/dev/urandom', false, null, -1, $length);
}
if (strlen($bytes) < $length) {
- $rand3 = md5(serialize($_SERVER), TRUE);
+ $rand3 = md5(serialize($_SERVER), true);
$charlist = str_shuffle($charlist);
for ($i = 0; $i < $length; $i++) {
if ($i % 5 === 0) {
@@ -77,5 +77,4 @@ public static function generate($length = 10, $charlist = '0-9a-z')
}
return $res;
}
-
}
diff --git a/src/Utils/Reflection.php b/src/Utils/Reflection.php
index 3feabe31b..5010bf239 100644
--- a/src/Utils/Reflection.php
+++ b/src/Utils/Reflection.php
@@ -19,7 +19,7 @@ class Reflection
private static $builtinTypes = [
'string' => 1, 'int' => 1, 'float' => 1, 'bool' => 1, 'array' => 1,
- 'callable' => 1, 'iterable' => 1, 'void' => 1
+ 'callable' => 1, 'iterable' => 1, 'void' => 1,
];
@@ -34,30 +34,30 @@ public static function isBuiltinType($type)
/**
- * @return string|NULL
+ * @return string|null
*/
public static function getReturnType(\ReflectionFunctionAbstract $func)
{
return PHP_VERSION_ID >= 70000 && $func->hasReturnType()
? self::normalizeType((string) $func->getReturnType(), $func)
- : NULL;
+ : null;
}
/**
- * @return string|NULL
+ * @return string|null
*/
public static function getParameterType(\ReflectionParameter $param)
{
if (PHP_VERSION_ID >= 70000) {
return $param->hasType()
? self::normalizeType((string) $param->getType(), $param)
- : NULL;
+ : null;
} elseif ($param->isArray() || $param->isCallable()) {
return $param->isArray() ? 'array' : 'callable';
} else {
try {
- return ($ref = $param->getClass()) ? $ref->getName() : NULL;
+ return ($ref = $param->getClass()) ? $ref->getName() : null;
} catch (\ReflectionException $e) {
if (preg_match('#Class (.+) does not exist#', $e->getMessage(), $m)) {
return $m[1];
@@ -128,7 +128,7 @@ public static function getPropertyDeclaringClass(\ReflectionProperty $prop)
public static function areCommentsAvailable()
{
static $res;
- return $res === NULL
+ return $res === null
? $res = (bool) (new \ReflectionMethod(__METHOD__))->getDocComment()
: $res;
}
@@ -215,10 +215,10 @@ public static function getUseStatements(\ReflectionClass $class)
* @param string
* @return array of [class => [alias => class, ...]]
*/
- private static function parseUseStatements($code, $forClass = NULL)
+ private static function parseUseStatements($code, $forClass = null)
{
$tokens = token_get_all($code);
- $namespace = $class = $classLevel = $level = NULL;
+ $namespace = $class = $classLevel = $level = null;
$res = $uses = [];
while ($token = current($tokens)) {
@@ -279,7 +279,7 @@ private static function parseUseStatements($code, $forClass = NULL)
case '}':
if ($level === $classLevel) {
- $class = $classLevel = NULL;
+ $class = $classLevel = null;
}
$level--;
}
@@ -291,17 +291,16 @@ private static function parseUseStatements($code, $forClass = NULL)
private static function fetch(&$tokens, $take)
{
- $res = NULL;
+ $res = null;
while ($token = current($tokens)) {
list($token, $s) = is_array($token) ? $token : [$token, $token];
- if (in_array($token, (array) $take, TRUE)) {
+ if (in_array($token, (array) $take, true)) {
$res .= $s;
- } elseif (!in_array($token, [T_DOC_COMMENT, T_WHITESPACE, T_COMMENT], TRUE)) {
+ } elseif (!in_array($token, [T_DOC_COMMENT, T_WHITESPACE, T_COMMENT], true)) {
break;
}
next($tokens);
}
return $res;
}
-
}
diff --git a/src/Utils/SmartObject.php b/src/Utils/SmartObject.php
index b490d951f..34e2f4dae 100644
--- a/src/Utils/SmartObject.php
+++ b/src/Utils/SmartObject.php
@@ -39,8 +39,8 @@ public function __call($name, $args)
foreach ($this->$name as $handler) {
Callback::invokeArgs($handler, $args);
}
- } elseif ($this->$name !== NULL) {
- throw new UnexpectedValueException("Property $class::$$name must be array or NULL, " . gettype($this->$name) . ' given.');
+ } elseif ($this->$name !== null) {
+ throw new UnexpectedValueException("Property $class::$$name must be array or null, " . gettype($this->$name) . ' given.');
}
} elseif ($isProp && $this->$name instanceof \Closure) { // closure in property
@@ -117,7 +117,7 @@ public function &__get($name)
if ($methods[$m] === 0) {
$methods[$m] = (new \ReflectionMethod($class, $m))->returnsReference();
}
- if ($methods[$m] === TRUE) {
+ if ($methods[$m] === true) {
return $this->$m();
} else {
$val = $this->$m();
@@ -212,20 +212,19 @@ public static function getReflection()
* @return mixed
* @deprecated use Nette\Utils\ObjectMixin::setExtensionMethod()
*/
- public static function extensionMethod($name, $callback = NULL)
+ public static function extensionMethod($name, $callback = null)
{
- if (strpos($name, '::') === FALSE) {
+ if (strpos($name, '::') === false) {
$class = get_called_class();
} else {
list($class, $name) = explode('::', $name);
$class = (new \ReflectionClass($class))->getName();
}
trigger_error("Extension methods such as $class::$name() are deprecated" . ObjectMixin::getSource(), E_USER_DEPRECATED);
- if ($callback === NULL) {
+ if ($callback === null) {
return ObjectMixin::getExtensionMethod($class, $name);
} else {
ObjectMixin::setExtensionMethod($class, $name, $callback);
}
}
-
}
diff --git a/src/Utils/StaticClass.php b/src/Utils/StaticClass.php
index b5f7b9400..2133f2967 100644
--- a/src/Utils/StaticClass.php
+++ b/src/Utils/StaticClass.php
@@ -31,5 +31,4 @@ public static function __callStatic($name, $args)
{
Utils\ObjectMixin::strictStaticCall(get_called_class(), $name);
}
-
}
diff --git a/src/Utils/Strings.php b/src/Utils/Strings.php
index 95d8ad30d..3e54a6843 100644
--- a/src/Utils/Strings.php
+++ b/src/Utils/Strings.php
@@ -90,7 +90,7 @@ public static function endsWith($haystack, $needle)
*/
public static function contains($haystack, $needle)
{
- return strpos($haystack, $needle) !== FALSE;
+ return strpos($haystack, $needle) !== false;
}
@@ -101,11 +101,11 @@ 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($s, $start, $length = null)
{
if (function_exists('mb_substr')) {
return mb_substr($s, $start, $length, 'UTF-8'); // MB is much faster
- } elseif ($length === NULL) {
+ } elseif ($length === null) {
$length = self::length($s);
} elseif ($start < 0 && $length < 0) {
$start += self::length($s); // unifies iconv_substr behavior with mb_substr
@@ -154,8 +154,8 @@ public static function normalizeNewLines($s)
*/
public static function toAscii($s)
{
- static $transliterator = NULL;
- if ($transliterator === NULL && class_exists('Transliterator', FALSE)) {
+ static $transliterator = null;
+ if ($transliterator === null && class_exists('Transliterator', false)) {
$transliterator = \Transliterator::create('Any-Latin; Latin-ASCII');
}
@@ -165,7 +165,7 @@ public static function toAscii($s)
["\xE2\x80\x9E", "\xE2\x80\x9C", "\xE2\x80\x9D", "\xE2\x80\x9A", "\xE2\x80\x98", "\xE2\x80\x99", "\xC2\xB0"],
["\x03", "\x03", "\x03", "\x02", "\x02", "\x02", "\x04"], $s
);
- if ($transliterator !== NULL) {
+ if ($transliterator !== null) {
$s = $transliterator->transliterate($s);
}
if (ICONV_IMPL === 'glibc') {
@@ -196,13 +196,13 @@ public static function toAscii($s)
* @param bool
* @return string
*/
- public static function webalize($s, $charlist = NULL, $lower = TRUE)
+ public static function webalize($s, $charlist = null, $lower = true)
{
$s = self::toAscii($s);
if ($lower) {
$s = strtolower($s);
}
- $s = preg_replace('#[^a-z0-9' . ($charlist !== NULL ? preg_quote($charlist, '#') : '') . ']+#i', '-', $s);
+ $s = preg_replace('#[^a-z0-9' . ($charlist !== null ? preg_quote($charlist, '#') : '') . ']+#i', '-', $s);
$s = trim($s, '-');
return $s;
}
@@ -222,7 +222,7 @@ public static function truncate($s, $maxLen, $append = "\xE2\x80\xA6")
if ($maxLen < 1) {
return $append;
- } elseif ($matches = self::match($s, '#^.{1,'.$maxLen.'}(?=[\s\x00-/:-@\[-`{-~])#us')) {
+ } elseif ($matches = self::match($s, '#^.{1,' . $maxLen . '}(?=[\s\x00-/:-@\[-`{-~])#us')) {
return $matches[0] . $append;
} else {
@@ -311,12 +311,12 @@ public static function capitalize($s)
* @param int
* @return bool
*/
- public static function compare($left, $right, $len = NULL)
+ public static function compare($left, $right, $len = null)
{
if ($len < 0) {
$left = self::substring($left, $len, -$len);
$right = self::substring($right, $len, -$len);
- } elseif ($len !== NULL) {
+ } elseif ($len !== null) {
$left = self::substring($left, 0, $len);
$right = self::substring($right, 0, $len);
}
@@ -370,7 +370,7 @@ public static function length($s)
public static function trim($s, $charlist = self::TRIM_CHARACTERS)
{
$charlist = preg_quote($charlist, '#');
- return self::replace($s, '#^['.$charlist.']+|['.$charlist.']+\z#u', '');
+ return self::replace($s, '#^[' . $charlist . ']+|[' . $charlist . ']+\z#u', '');
}
@@ -431,13 +431,13 @@ public static function random($length = 10, $charlist = '0-9a-z')
* @param string
* @param string
* @param int negative value means searching from the end
- * @return string|FALSE returns FALSE if the needle was not found
+ * @return string|false returns false if the needle was not found
*/
public static function before($haystack, $needle, $nth = 1)
{
$pos = self::pos($haystack, $needle, $nth);
- return $pos === FALSE
- ? FALSE
+ return $pos === false
+ ? false
: substr($haystack, 0, $pos);
}
@@ -447,13 +447,13 @@ public static function before($haystack, $needle, $nth = 1)
* @param string
* @param string
* @param int negative value means searching from the end
- * @return string|FALSE returns FALSE if the needle was not found
+ * @return string|false returns false if the needle was not found
*/
public static function after($haystack, $needle, $nth = 1)
{
$pos = self::pos($haystack, $needle, $nth);
- return $pos === FALSE
- ? FALSE
+ return $pos === false
+ ? false
: (string) substr($haystack, $pos + strlen($needle));
}
@@ -463,31 +463,31 @@ public static function after($haystack, $needle, $nth = 1)
* @param string
* @param string
* @param int negative value means searching from the end
- * @return int|FALSE offset in characters or FALSE if the needle was not found
+ * @return int|false offset in characters or false if the needle was not found
*/
public static function indexOf($haystack, $needle, $nth = 1)
{
$pos = self::pos($haystack, $needle, $nth);
- return $pos === FALSE
- ? FALSE
+ return $pos === false
+ ? false
: self::length(substr($haystack, 0, $pos));
}
/**
* Returns position of $nth occurence of $needle in $haystack.
- * @return int|FALSE offset in bytes or FALSE if the needle was not found
+ * @return int|false offset in bytes or false if the needle was not found
*/
private static function pos($haystack, $needle, $nth = 1)
{
if (!$nth) {
- return FALSE;
+ return false;
} elseif ($nth > 0) {
if (strlen($needle) === 0) {
return 0;
}
$pos = 0;
- while (FALSE !== ($pos = strpos($haystack, $needle, $pos)) && --$nth) {
+ while (($pos = strpos($haystack, $needle, $pos)) !== false && --$nth) {
$pos++;
}
} else {
@@ -496,7 +496,7 @@ private static function pos($haystack, $needle, $nth = 1)
return $len;
}
$pos = $len - 1;
- while (FALSE !== ($pos = strrpos($haystack, $needle, $pos - $len)) && ++$nth) {
+ while (($pos = strrpos($haystack, $needle, $pos - $len)) !== false && ++$nth) {
$pos--;
}
}
@@ -528,11 +528,11 @@ public static function split($subject, $pattern, $flags = 0)
public static function match($subject, $pattern, $flags = 0, $offset = 0)
{
if ($offset > strlen($subject)) {
- return NULL;
+ return null;
}
return self::pcre('preg_match', [$pattern, $subject, &$m, $flags, $offset])
? $m
- : NULL;
+ : null;
}
@@ -566,20 +566,20 @@ 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($subject, $pattern, $replacement = null, $limit = -1)
{
if (is_object($replacement) || is_array($replacement)) {
if ($replacement instanceof Nette\Callback) {
trigger_error('Nette\Callback is deprecated, use PHP callback.', E_USER_DEPRECATED);
$replacement = $replacement->getNative();
}
- if (!is_callable($replacement, FALSE, $textual)) {
+ if (!is_callable($replacement, false, $textual)) {
throw new Nette\InvalidStateException("Callback '$textual' is not callable.");
}
return self::pcre('preg_replace_callback', [$pattern, $replacement, $subject, $limit]);
- } elseif ($replacement === NULL && is_array($pattern)) {
+ } elseif ($replacement === null && is_array($pattern)) {
$replacement = array_values($pattern);
$pattern = array_keys($pattern);
}
@@ -605,12 +605,11 @@ public static function pcre($func, $args)
});
if (($code = preg_last_error()) // run-time error, but preg_last_error & return code are liars
- && ($res === NULL || !in_array($func, ['preg_filter', 'preg_replace_callback', 'preg_replace']))
+ && ($res === null || !in_array($func, ['preg_filter', 'preg_replace_callback', 'preg_replace'], true))
) {
throw new RegexpException((isset($messages[$code]) ? $messages[$code] : 'Unknown error')
. ' (pattern: ' . implode(' or ', (array) $args[0]) . ')', $code);
}
return $res;
}
-
}
diff --git a/src/Utils/Validators.php b/src/Utils/Validators.php
index 92d7759ea..dd6488797 100644
--- a/src/Utils/Validators.php
+++ b/src/Utils/Validators.php
@@ -41,7 +41,7 @@ class Validators
'none' => [__CLASS__, 'isNone'],
'type' => [__CLASS__, 'isType'],
'identifier' => [__CLASS__, 'isPhpIdentifier'],
- 'pattern' => NULL,
+ 'pattern' => null,
'alnum' => 'ctype_alnum',
'alpha' => 'ctype_alpha',
'digit' => 'ctype_digit',
@@ -100,7 +100,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, $field, $expected = null, $label = "item '%' in array")
{
self::assert($arr, 'array', 'first argument');
if (!array_key_exists($field, $arr)) {
@@ -123,7 +123,7 @@ public static function is($value, $expected)
foreach (explode('|', $expected) as $item) {
if (substr($item, -2) === '[]') {
if (self::everyIs($value, substr($item, 0, -2))) {
- return TRUE;
+ return true;
}
continue;
}
@@ -135,7 +135,7 @@ public static function is($value, $expected)
}
} elseif ($type === 'pattern') {
if (preg_match('|^' . (isset($item[1]) ? $item[1] : '') . '\z|', $value)) {
- return TRUE;
+ return true;
}
continue;
} elseif (!$value instanceof $type) {
@@ -155,9 +155,9 @@ public static function is($value, $expected)
continue;
}
}
- return TRUE;
+ return true;
}
- return FALSE;
+ return false;
}
@@ -170,14 +170,14 @@ public static function is($value, $expected)
public static function everyIs($values, $expected)
{
if (!self::isIterable($values)) {
- return FALSE;
+ return false;
}
foreach ($values as $value) {
if (!static::is($value, $expected)) {
- return FALSE;
+ return false;
}
}
- return TRUE;
+ return true;
}
@@ -217,7 +217,7 @@ public static function isNumeric($value)
*/
public static function isCallable($value)
{
- return $value && is_callable($value, TRUE);
+ return $value && is_callable($value, true);
}
@@ -238,7 +238,7 @@ public static function isUnicode($value)
*/
public static function isNone($value)
{
- return $value == NULL; // intentionally ==
+ return $value == null; // intentionally ==
}
@@ -261,20 +261,20 @@ public static function isList($value)
*/
public static function isInRange($value, $range)
{
- if ($value === NULL || !(isset($range[0]) || isset($range[1]))) {
- return FALSE;
+ if ($value === null || !(isset($range[0]) || isset($range[1]))) {
+ return false;
}
$limit = isset($range[0]) ? $range[0] : $range[1];
if (is_string($limit)) {
$value = (string) $value;
} elseif ($limit instanceof \DateTimeInterface) {
if (!$value instanceof \DateTimeInterface) {
- return FALSE;
+ return false;
}
} elseif (is_numeric($value)) {
$value *= 1;
} else {
- return FALSE;
+ return false;
}
return (!isset($range[0]) || ($value >= $range[0])) && (!isset($range[1]) || ($value <= $range[1]));
}
@@ -359,5 +359,4 @@ private static function isIterable($value)
{
return is_array($value) || $value instanceof \Traversable;
}
-
}
diff --git a/src/Utils/exceptions.php b/src/Utils/exceptions.php
index 0b759ff06..165342630 100644
--- a/src/Utils/exceptions.php
+++ b/src/Utils/exceptions.php
@@ -114,7 +114,6 @@ class StaticClassException extends \LogicException
{
}
-
namespace Nette\Utils;
diff --git a/tests/Iterators/CachingIterator.construct.phpt b/tests/Iterators/CachingIterator.construct.phpt
index 748f1ef45..1d8400c3a 100644
--- a/tests/Iterators/CachingIterator.construct.phpt
+++ b/tests/Iterators/CachingIterator.construct.phpt
@@ -79,7 +79,7 @@ test(function () { // ==> object
Assert::exception(function () {
$arr = dir('.');
foreach (new Iterators\CachingIterator($arr) as $k => $v);
- }, InvalidArgumentException::class, NULL);
+ }, InvalidArgumentException::class, null);
});
diff --git a/tests/Utils/ArrayHash.phpt b/tests/Utils/ArrayHash.phpt
index 289f0377b..afdc1ccd8 100644
--- a/tests/Utils/ArrayHash.phpt
+++ b/tests/Utils/ArrayHash.phpt
@@ -15,16 +15,17 @@ class Person
{
private $name;
+
public function __construct($name)
{
$this->name = $name;
}
+
public function sayHi()
{
return "My name is $this->name";
}
-
}
@@ -83,7 +84,7 @@ test(function () {
'children' => [
'c' => 'John',
],
- ], FALSE);
+ ], false);
Assert::type(Nette\Utils\ArrayHash::class, $list);
Assert::type('array', $list['children']);
});
@@ -163,7 +164,7 @@ test(function () { // numeric fields
test(function () { // null fields
- $row = ArrayHash::from(['null' => NULL]);
+ $row = ArrayHash::from(['null' => null]);
Assert::null($row->null);
Assert::null($row['null']);
Assert::false(isset($row->null));
diff --git a/tests/Utils/ArrayList.phpt b/tests/Utils/ArrayList.phpt
index 09a177fca..3a81a2a52 100644
--- a/tests/Utils/ArrayList.phpt
+++ b/tests/Utils/ArrayList.phpt
@@ -15,16 +15,17 @@ class Person
{
private $name;
+
public function __construct($name)
{
$this->name = $name;
}
+
public function sayHi()
{
return "My name is $this->name";
}
-
}
diff --git a/tests/Utils/Arrays.associate().phpt b/tests/Utils/Arrays.associate().phpt
index 8878c29b9..9ea9c23f1 100644
--- a/tests/Utils/Arrays.associate().phpt
+++ b/tests/Utils/Arrays.associate().phpt
@@ -15,7 +15,7 @@ require __DIR__ . '/../bootstrap.php';
$arr = [
['name' => 'John', 'age' => 11],
['name' => 'John', 'age' => 22],
- ['name' => 'Mary', 'age' => NULL],
+ ['name' => 'Mary', 'age' => null],
['name' => 'Paul', 'age' => 44],
];
@@ -23,7 +23,7 @@ $arr = [
Assert::same(
[
'John' => ['name' => 'John', 'age' => 11],
- 'Mary' => ['name' => 'Mary', 'age' => NULL],
+ 'Mary' => ['name' => 'Mary', 'age' => null],
'Paul' => ['name' => 'Paul', 'age' => 44],
],
Arrays::associate($arr, 'name')
@@ -37,19 +37,19 @@ Assert::same(
Assert::same(
[
'John' => ['name' => 'John', 'age' => 11],
- 'Mary' => ['name' => 'Mary', 'age' => NULL],
+ 'Mary' => ['name' => 'Mary', 'age' => null],
'Paul' => ['name' => 'Paul', 'age' => 44],
],
Arrays::associate($arr, 'name=')
);
Assert::same(
- ['John' => 22, 'Mary' => NULL, 'Paul' => 44],
+ ['John' => 22, 'Mary' => null, 'Paul' => 44],
Arrays::associate($arr, 'name=age')
);
Assert::same(// path as array
- ['John' => 22, 'Mary' => NULL, 'Paul' => 44],
+ ['John' => 22, 'Mary' => null, 'Paul' => 44],
Arrays::associate($arr, ['name', '=', 'age'])
);
@@ -61,7 +61,7 @@ Assert::equal(
],
'Mary' => (object) [
'name' => 'Mary',
- 'age' => NULL,
+ 'age' => null,
],
'Paul' => (object) [
'name' => 'Paul',
@@ -79,8 +79,8 @@ Assert::equal(
22 => (object) [
'John' => ['name' => 'John', 'age' => 22],
],
- NULL => (object) [
- 'Mary' => ['name' => 'Mary', 'age' => NULL],
+ null => (object) [
+ 'Mary' => ['name' => 'Mary', 'age' => null],
],
44 => (object) [
'Paul' => ['name' => 'Paul', 'age' => 44],
@@ -92,7 +92,7 @@ Assert::equal(
Assert::equal(
(object) [
'John' => ['name' => 'John', 'age' => 11],
- 'Mary' => ['name' => 'Mary', 'age' => NULL],
+ 'Mary' => ['name' => 'Mary', 'age' => null],
'Paul' => ['name' => 'Paul', 'age' => 44],
],
Arrays::associate($arr, '->name')
@@ -110,7 +110,7 @@ Assert::same(
22 => ['name' => 'John', 'age' => 22],
],
'Mary' => [
- NULL => ['name' => 'Mary', 'age' => NULL],
+ null => ['name' => 'Mary', 'age' => null],
],
'Paul' => [
44 => ['name' => 'Paul', 'age' => 44],
@@ -122,7 +122,7 @@ Assert::same(
Assert::same(
[
'John' => ['name' => 'John', 'age' => 11],
- 'Mary' => ['name' => 'Mary', 'age' => NULL],
+ 'Mary' => ['name' => 'Mary', 'age' => null],
'Paul' => ['name' => 'Paul', 'age' => 44],
],
Arrays::associate($arr, 'name|')
@@ -135,7 +135,7 @@ Assert::same(
['name' => 'John', 'age' => 22],
],
'Mary' => [
- ['name' => 'Mary', 'age' => NULL],
+ ['name' => 'Mary', 'age' => null],
],
'Paul' => [
['name' => 'Paul', 'age' => 44],
@@ -148,7 +148,7 @@ Assert::same(
[
['John' => ['name' => 'John', 'age' => 11]],
['John' => ['name' => 'John', 'age' => 22]],
- ['Mary' => ['name' => 'Mary', 'age' => NULL]],
+ ['Mary' => ['name' => 'Mary', 'age' => null]],
['Paul' => ['name' => 'Paul', 'age' => 44]],
],
Arrays::associate($arr, '[]name')
@@ -166,7 +166,7 @@ Assert::same(
[22 => ['name' => 'John', 'age' => 22]],
],
'Mary' => [
- [NULL => ['name' => 'Mary', 'age' => NULL]],
+ [null => ['name' => 'Mary', 'age' => null]],
],
'Paul' => [
[44 => ['name' => 'Paul', 'age' => 44]],
@@ -186,7 +186,7 @@ Assert::same(
Arrays::associate($arr = [
(object) ['name' => 'John', 'age' => 11],
(object) ['name' => 'John', 'age' => 22],
- (object) ['name' => 'Mary', 'age' => NULL],
+ (object) ['name' => 'Mary', 'age' => null],
(object) ['name' => 'Paul', 'age' => 44],
], '[]')
);
diff --git a/tests/Utils/Arrays.every().phpt b/tests/Utils/Arrays.every().phpt
index 4421898de..e4d244bcf 100644
--- a/tests/Utils/Arrays.every().phpt
+++ b/tests/Utils/Arrays.every().phpt
@@ -16,7 +16,7 @@ test(function () {
$log = [];
$res = Arrays::every(
$arr,
- function ($v, $k, $arr) use (&$log) { $log[] = func_get_args(); return FALSE; }
+ function ($v, $k, $arr) use (&$log) { $log[] = func_get_args(); return false; }
);
Assert::true($res);
Assert::same([], $log);
@@ -27,7 +27,7 @@ test(function () {
$log = [];
$res = Arrays::every(
$arr,
- function ($v, $k, $arr) use (&$log) { $log[] = func_get_args(); return TRUE; }
+ function ($v, $k, $arr) use (&$log) { $log[] = func_get_args(); return true; }
);
Assert::true($res);
Assert::same([], $log);
@@ -38,7 +38,7 @@ test(function () {
$log = [];
$res = Arrays::every(
$arr,
- function ($v, $k, $arr) use (&$log) { $log[] = func_get_args(); return FALSE; }
+ function ($v, $k, $arr) use (&$log) { $log[] = func_get_args(); return false; }
);
Assert::false($res);
Assert::same([['a', 0, $arr]], $log);
@@ -49,7 +49,7 @@ test(function () {
$log = [];
$res = Arrays::every(
$arr,
- function ($v, $k, $arr) use (&$log) { $log[] = func_get_args(); return TRUE; }
+ function ($v, $k, $arr) use (&$log) { $log[] = func_get_args(); return true; }
);
Assert::true($res);
Assert::same([['a', 0, $arr], ['b', 1, $arr]], $log);
@@ -71,7 +71,7 @@ test(function () {
$log = [];
$res = Arrays::every(
$arr,
- function ($v, $k, $arr) use (&$log) { $log[] = func_get_args(); return TRUE; }
+ function ($v, $k, $arr) use (&$log) { $log[] = func_get_args(); return true; }
);
Assert::true($res);
Assert::same([['a', 'x', $arr], ['b', 'y', $arr]], $log);
diff --git a/tests/Utils/Arrays.flatten().phpt b/tests/Utils/Arrays.flatten().phpt
index e73189dff..1e7a7dcb2 100644
--- a/tests/Utils/Arrays.flatten().phpt
+++ b/tests/Utils/Arrays.flatten().phpt
@@ -33,7 +33,7 @@ $res = Arrays::flatten([
],
'y' => 'd',
'z' => 'e',
-], TRUE);
+], true);
Assert::same([
5 => 'a',
diff --git a/tests/Utils/Arrays.get().phpt b/tests/Utils/Arrays.get().phpt
index 4611caa61..dad03b3b0 100644
--- a/tests/Utils/Arrays.get().phpt
+++ b/tests/Utils/Arrays.get().phpt
@@ -12,7 +12,7 @@ require __DIR__ . '/../bootstrap.php';
$arr = [
- NULL => 'first',
+ null => 'first',
1 => 'second',
7 => [
'item' => 'third',
@@ -21,7 +21,7 @@ $arr = [
test(function () use ($arr) { // Single item
- Assert::same('first', Arrays::get($arr, NULL));
+ Assert::same('first', Arrays::get($arr, null));
Assert::same('second', Arrays::get($arr, 1));
Assert::same('second', Arrays::get($arr, 1, 'x'));
Assert::same('x', Arrays::get($arr, 'undefined', 'x'));
diff --git a/tests/Utils/Arrays.getRef().phpt b/tests/Utils/Arrays.getRef().phpt
index 07e529cf0..58c82c68e 100644
--- a/tests/Utils/Arrays.getRef().phpt
+++ b/tests/Utils/Arrays.getRef().phpt
@@ -12,7 +12,7 @@ require __DIR__ . '/../bootstrap.php';
$arr = [
- NULL => 'first',
+ null => 'first',
1 => 'second',
7 => [
'item' => 'third',
@@ -22,7 +22,7 @@ $arr = [
test(function () use ($arr) { // Single item
$dolly = $arr;
- $item = &Arrays::getRef($dolly, NULL);
+ $item = &Arrays::getRef($dolly, null);
$item = 'changed';
Assert::same([
'' => 'changed',
diff --git a/tests/Utils/Arrays.insertBefore().phpt b/tests/Utils/Arrays.insertBefore().phpt
index cc38c86a8..5260a23a8 100644
--- a/tests/Utils/Arrays.insertBefore().phpt
+++ b/tests/Utils/Arrays.insertBefore().phpt
@@ -12,8 +12,8 @@ require __DIR__ . '/../bootstrap.php';
$arr = [
- NULL => 'first',
- FALSE => 'second',
+ null => 'first',
+ false => 'second',
1 => 'third',
7 => 'fourth',
];
@@ -28,7 +28,7 @@ Assert::same([
test(function () use ($arr) { // First item
$dolly = $arr;
- Arrays::insertBefore($dolly, NULL, ['new' => 'value']);
+ Arrays::insertBefore($dolly, null, ['new' => 'value']);
Assert::same([
'new' => 'value',
'' => 'first',
@@ -39,7 +39,7 @@ test(function () use ($arr) { // First item
$dolly = $arr;
- Arrays::insertAfter($dolly, NULL, ['new' => 'value']);
+ Arrays::insertAfter($dolly, null, ['new' => 'value']);
Assert::same([
'' => 'first',
'new' => 'value',
diff --git a/tests/Utils/Arrays.isList.phpt b/tests/Utils/Arrays.isList.phpt
index 2b376cea6..5efb7ce9b 100644
--- a/tests/Utils/Arrays.isList.phpt
+++ b/tests/Utils/Arrays.isList.phpt
@@ -11,7 +11,7 @@ use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
-Assert::false(Arrays::isList(NULL));
+Assert::false(Arrays::isList(null));
Assert::true(Arrays::isList([]));
Assert::true(Arrays::isList([1]));
Assert::true(Arrays::isList(['a', 'b', 'c']));
diff --git a/tests/Utils/Arrays.map().phpt b/tests/Utils/Arrays.map().phpt
index dbaba0e49..028a2a9c2 100644
--- a/tests/Utils/Arrays.map().phpt
+++ b/tests/Utils/Arrays.map().phpt
@@ -16,7 +16,7 @@ test(function () {
$log = [];
$res = Arrays::map(
$arr,
- function ($v, $k, $arr) use (&$log) { $log[] = func_get_args(); return TRUE; }
+ function ($v, $k, $arr) use (&$log) { $log[] = func_get_args(); return true; }
);
Assert::same([], $res);
Assert::same([], $log);
diff --git a/tests/Utils/Arrays.normalize.phpt b/tests/Utils/Arrays.normalize.phpt
index e80fde131..3d00dd991 100644
--- a/tests/Utils/Arrays.normalize.phpt
+++ b/tests/Utils/Arrays.normalize.phpt
@@ -13,10 +13,10 @@ require __DIR__ . '/../bootstrap.php';
Assert::same(
[
- 'first' => NULL,
+ 'first' => null,
'a' => 'second',
'd' => ['third'],
- 'fourth' => NULL,
+ 'fourth' => null,
],
Arrays::normalize([
1 => 'first',
@@ -29,11 +29,11 @@ Assert::same(
Assert::same(
[
- 'first' => TRUE,
+ 'first' => true,
'' => 'second',
],
Arrays::normalize([
1 => 'first',
'' => 'second',
- ], TRUE)
+ ], true)
);
diff --git a/tests/Utils/Arrays.pick().phpt b/tests/Utils/Arrays.pick().phpt
index e266f724a..20d0921d4 100644
--- a/tests/Utils/Arrays.pick().phpt
+++ b/tests/Utils/Arrays.pick().phpt
@@ -12,14 +12,14 @@ require __DIR__ . '/../bootstrap.php';
$arr = [
- NULL => 'null', // NULL is ''
+ null => 'null', // null is ''
1 => 'first',
2 => 'second',
];
test(function () use ($arr) { // Single item
- Assert::same('null', Arrays::pick($arr, NULL));
+ Assert::same('null', Arrays::pick($arr, null));
Assert::same('first', Arrays::pick($arr, 1));
Assert::same('x', Arrays::pick($arr, 1, 'x'));
Assert::exception(function () use ($arr) {
diff --git a/tests/Utils/Arrays.renameKey().phpt b/tests/Utils/Arrays.renameKey().phpt
index 01c479c1e..4030c88f4 100644
--- a/tests/Utils/Arrays.renameKey().phpt
+++ b/tests/Utils/Arrays.renameKey().phpt
@@ -12,8 +12,8 @@ require __DIR__ . '/../bootstrap.php';
$arr = [
- NULL => 'first',
- FALSE => 'second',
+ null => 'first',
+ false => 'second',
1 => 'third',
7 => 'fourth',
];
@@ -28,7 +28,7 @@ Assert::same([
Arrays::renameKey($arr, '1', 'new1');
Arrays::renameKey($arr, 0, 'new2');
-Arrays::renameKey($arr, NULL, 'new3');
+Arrays::renameKey($arr, null, 'new3');
Arrays::renameKey($arr, '', 'new4');
Arrays::renameKey($arr, 'undefined', 'new5');
diff --git a/tests/Utils/Arrays.searchKey().phpt b/tests/Utils/Arrays.searchKey().phpt
index 13f701afa..4bd65fbc8 100644
--- a/tests/Utils/Arrays.searchKey().phpt
+++ b/tests/Utils/Arrays.searchKey().phpt
@@ -12,8 +12,8 @@ require __DIR__ . '/../bootstrap.php';
$arr = [
- NULL => 'first',
- FALSE => 'second',
+ null => 'first',
+ false => 'second',
1 => 'third',
7 => 'fourth',
];
@@ -29,6 +29,6 @@ Assert::same([
Assert::same(2, Arrays::searchKey($arr, '1'));
Assert::same(2, Arrays::searchKey($arr, 1));
Assert::same(1, Arrays::searchKey($arr, 0));
-Assert::same(0, Arrays::searchKey($arr, NULL));
+Assert::same(0, Arrays::searchKey($arr, null));
Assert::same(0, Arrays::searchKey($arr, ''));
Assert::false(Arrays::searchKey($arr, 'undefined'));
diff --git a/tests/Utils/Arrays.some().phpt b/tests/Utils/Arrays.some().phpt
index cf64145da..ab7f1ca85 100644
--- a/tests/Utils/Arrays.some().phpt
+++ b/tests/Utils/Arrays.some().phpt
@@ -16,7 +16,7 @@ test(function () {
$log = [];
$res = Arrays::some(
$arr,
- function ($v, $k, $arr) use (&$log) { $log[] = func_get_args(); return FALSE; }
+ function ($v, $k, $arr) use (&$log) { $log[] = func_get_args(); return false; }
);
Assert::false($res);
Assert::same([], $log);
@@ -27,7 +27,7 @@ test(function () {
$log = [];
$res = Arrays::some(
$arr,
- function ($v, $k, $arr) use (&$log) { $log[] = func_get_args(); return TRUE; }
+ function ($v, $k, $arr) use (&$log) { $log[] = func_get_args(); return true; }
);
Assert::false($res);
Assert::same([], $log);
@@ -38,7 +38,7 @@ test(function () {
$log = [];
$res = Arrays::some(
$arr,
- function ($v, $k, $arr) use (&$log) { $log[] = func_get_args(); return FALSE; }
+ function ($v, $k, $arr) use (&$log) { $log[] = func_get_args(); return false; }
);
Assert::false($res);
Assert::same([['a', 0, $arr], ['b', 1, $arr]], $log);
@@ -49,7 +49,7 @@ test(function () {
$log = [];
$res = Arrays::some(
$arr,
- function ($v, $k, $arr) use (&$log) { $log[] = func_get_args(); return TRUE; }
+ function ($v, $k, $arr) use (&$log) { $log[] = func_get_args(); return true; }
);
Assert::true($res);
Assert::same([['a', 0, $arr]], $log);
diff --git a/tests/Utils/Callback.check.phpt b/tests/Utils/Callback.check.phpt
index 2e0766a1a..00ad2c7ee 100644
--- a/tests/Utils/Callback.check.phpt
+++ b/tests/Utils/Callback.check.phpt
@@ -13,11 +13,11 @@ require __DIR__ . '/../bootstrap.php';
Assert::same('trim', Callback::check('trim'));
-Assert::same('undefined', Callback::check('undefined', TRUE));
+Assert::same('undefined', Callback::check('undefined', true));
Assert::exception(function () {
- Callback::check(123, TRUE);
+ Callback::check(123, true);
}, Nette\InvalidArgumentException::class, 'Given value is not a callable type.');
diff --git a/tests/Utils/Callback.closure.phpt b/tests/Utils/Callback.closure.phpt
index 4e1308251..197173d95 100644
--- a/tests/Utils/Callback.closure.phpt
+++ b/tests/Utils/Callback.closure.phpt
@@ -13,47 +13,53 @@ require __DIR__ . '/../bootstrap.php';
class Test
{
- function __invoke($a)
+ public function __invoke($a)
{
return __METHOD__ . $a;
}
+
public function publicFun($a)
{
return __METHOD__ . $a;
}
+
private function privateFun($a)
{
return __METHOD__ . $a;
}
+
public static function publicStatic($a)
{
return __METHOD__ . $a;
}
+
private static function privateStatic($a)
{
return __METHOD__ . $a;
}
+
public function __call($nm, $args)
{
return __METHOD__ . " $nm $args[0]";
}
+
public static function __callStatic($nm, $args)
{
return __METHOD__ . " $nm $args[0]";
}
+
public function ref(&$a)
{
$a = __METHOD__;
return $a;
}
-
}
class TestChild extends Test
diff --git a/tests/Utils/Callback.invoke.phpt b/tests/Utils/Callback.invoke.phpt
index e3a5f3ecb..2cb87eec5 100644
--- a/tests/Utils/Callback.invoke.phpt
+++ b/tests/Utils/Callback.invoke.phpt
@@ -13,18 +13,17 @@ require __DIR__ . '/../bootstrap.php';
class Test
{
-
public function fun($a)
{
return __METHOD__ . $a;
}
+
public function ref(&$a)
{
$a = __METHOD__;
return $a;
}
-
}
diff --git a/tests/Utils/Callback.invokeSafe.phpt b/tests/Utils/Callback.invokeSafe.phpt
index 3d58b6f37..49589a99b 100644
--- a/tests/Utils/Callback.invokeSafe.phpt
+++ b/tests/Utils/Callback.invokeSafe.phpt
@@ -30,7 +30,7 @@ Assert::same('OK1', $res);
// ignored error
Callback::invokeSafe('preg_match', ['ab', 'foo'], function () {
- return FALSE;
+ return false;
});
Assert::same('preg_match(): Delimiter must not be alphanumeric or backslash', $res);
diff --git a/tests/Utils/DateTime.JSON.phpt b/tests/Utils/DateTime.JSON.phpt
index eb57b297f..4b0e0a9e5 100644
--- a/tests/Utils/DateTime.JSON.phpt
+++ b/tests/Utils/DateTime.JSON.phpt
@@ -4,8 +4,8 @@
* Test: Nette\Utils\DateTime & JSON.
*/
-use Tester\Assert;
use Nette\Utils\DateTime;
+use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
diff --git a/tests/Utils/DateTime.createFromFormat.phpt b/tests/Utils/DateTime.createFromFormat.phpt
index c1a165887..dd5b801f1 100644
--- a/tests/Utils/DateTime.createFromFormat.phpt
+++ b/tests/Utils/DateTime.createFromFormat.phpt
@@ -4,8 +4,8 @@
* Test: Nette\DateTime::createFromFormat().
*/
-use Tester\Assert;
use Nette\Utils\DateTime;
+use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
diff --git a/tests/Utils/DateTime.from.phpt b/tests/Utils/DateTime.from.phpt
index 0c806f6ea..881b803a5 100644
--- a/tests/Utils/DateTime.from.phpt
+++ b/tests/Utils/DateTime.from.phpt
@@ -4,8 +4,8 @@
* Test: Nette\Utils\DateTime::from().
*/
-use Tester\Assert;
use Nette\Utils\DateTime;
+use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
diff --git a/tests/Utils/DateTime.fromParts.phpt b/tests/Utils/DateTime.fromParts.phpt
index ffa40580a..0d3d71ffa 100644
--- a/tests/Utils/DateTime.fromParts.phpt
+++ b/tests/Utils/DateTime.fromParts.phpt
@@ -4,8 +4,8 @@
* Test: Nette\Utils\DateTime::fromParts().
*/
-use Tester\Assert;
use Nette\Utils\DateTime;
+use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
diff --git a/tests/Utils/DateTime.modifyClone.phpt b/tests/Utils/DateTime.modifyClone.phpt
index 076bdcdfa..90b4721da 100644
--- a/tests/Utils/DateTime.modifyClone.phpt
+++ b/tests/Utils/DateTime.modifyClone.phpt
@@ -4,8 +4,8 @@
* Test: Nette\DateTime::modifyClone().
*/
-use Tester\Assert;
use Nette\Utils\DateTime;
+use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
diff --git a/tests/Utils/FileSystem.phpt b/tests/Utils/FileSystem.phpt
index 68a69dbe9..d76e3ef74 100644
--- a/tests/Utils/FileSystem.phpt
+++ b/tests/Utils/FileSystem.phpt
@@ -16,7 +16,6 @@ test(function () { // createDir
Assert::true(is_dir(TEMP_DIR . '/1/b'));
FileSystem::createDir(TEMP_DIR . '/1/');
-
});
Assert::exception(function () {
@@ -53,12 +52,12 @@ test(function () { // copy
FileSystem::write(TEMP_DIR . '/5/newfile', 'World');
Assert::exception(function () {
- FileSystem::copy(TEMP_DIR . '/5/newfile', TEMP_DIR . '/3/x/file', FALSE);
+ FileSystem::copy(TEMP_DIR . '/5/newfile', TEMP_DIR . '/3/x/file', false);
}, Nette\InvalidStateException::class, "File or directory '%a%' already exists.");
Assert::same('Hello', FileSystem::read(TEMP_DIR . '/3/x/file'));
Assert::exception(function () {
- FileSystem::copy('remote://example.com', TEMP_DIR . '/3/x/file', FALSE);
+ FileSystem::copy('remote://example.com', TEMP_DIR . '/3/x/file', false);
}, Nette\InvalidStateException::class, "File or directory '%a%' already exists.");
Assert::same('Hello', FileSystem::read(TEMP_DIR . '/3/x/file'));
@@ -66,7 +65,7 @@ test(function () { // copy
Assert::same('World', FileSystem::read(TEMP_DIR . '/3/x/file'));
Assert::exception(function () {
- FileSystem::copy(TEMP_DIR . '/5', TEMP_DIR . '/3', FALSE);
+ FileSystem::copy(TEMP_DIR . '/5', TEMP_DIR . '/3', false);
}, Nette\InvalidStateException::class, "File or directory '%a%' already exists.");
Assert::true(is_dir(TEMP_DIR . '/3/x/y'));
Assert::false(file_exists(TEMP_DIR . '/3/newfile'));
@@ -100,7 +99,7 @@ test(function () { // rename
FileSystem::write(TEMP_DIR . '/8/newfile', 'World');
Assert::exception(function () {
- FileSystem::rename(TEMP_DIR . '/8/newfile', TEMP_DIR . '/9/x/file', FALSE);
+ FileSystem::rename(TEMP_DIR . '/8/newfile', TEMP_DIR . '/9/x/file', false);
}, Nette\InvalidStateException::class, "File or directory '%a%' already exists.");
Assert::same('Hello', FileSystem::read(TEMP_DIR . '/9/x/file'));
FileSystem::rename(TEMP_DIR . '/8/newfile', TEMP_DIR . '/9/x/file');
@@ -108,7 +107,7 @@ test(function () { // rename
FileSystem::createDir(TEMP_DIR . '/10/');
Assert::exception(function () {
- FileSystem::rename(TEMP_DIR . '/10', TEMP_DIR . '/9', FALSE);
+ FileSystem::rename(TEMP_DIR . '/10', TEMP_DIR . '/9', false);
}, Nette\InvalidStateException::class, "File or directory '%a%' already exists.");
Assert::same('World', FileSystem::read(TEMP_DIR . '/9/x/file'));
diff --git a/tests/Utils/Html.basic.phpt b/tests/Utils/Html.basic.phpt
index caf0cc76b..0161a7577 100644
--- a/tests/Utils/Html.basic.phpt
+++ b/tests/Utils/Html.basic.phpt
@@ -12,7 +12,7 @@ require __DIR__ . '/../bootstrap.php';
test(function () {
- Html::$xhtml = TRUE;
+ Html::$xhtml = true;
$el = Html::el('img')->src('image.gif')->alt('');
Assert::same('
', (string) $el);
Assert::same('
', $el->startTag());
@@ -21,7 +21,7 @@ test(function () {
test(function () {
- Html::$xhtml = TRUE;
+ Html::$xhtml = true;
$el = Html::el('img')->setAttribute('src', 'image.gif')->setAttribute('alt', '');
Assert::same('
', (string) $el);
Assert::same('
', $el->startTag());
@@ -30,12 +30,12 @@ test(function () {
test(function () {
- Html::$xhtml = TRUE;
- $el = Html::el('img')->accesskey(0, TRUE)->alt('alt', FALSE);
+ Html::$xhtml = true;
+ $el = Html::el('img')->accesskey(0, true)->alt('alt', false);
Assert::same('', (string) $el);
- Assert::same('
', (string) $el->accesskey(1, TRUE));
- Assert::same('
', (string) $el->accesskey(1, FALSE));
- Assert::same('
', (string) $el->accesskey(0, TRUE));
+ Assert::same('
', (string) $el->accesskey(1, true));
+ Assert::same('
', (string) $el->accesskey(1, false));
+ Assert::same('
', (string) $el->accesskey(0, true));
Assert::same('
', (string) $el->accesskey(0));
unset($el->accesskey);
@@ -44,11 +44,11 @@ test(function () {
test(function () {
- Html::$xhtml = TRUE;
- $el = Html::el('img')->appendAttribute('accesskey', 0)->setAttribute('alt', FALSE);
+ Html::$xhtml = true;
+ $el = Html::el('img')->appendAttribute('accesskey', 0)->setAttribute('alt', false);
Assert::same('
', (string) $el);
Assert::same('
', (string) $el->appendAttribute('accesskey', 1));
- Assert::same('
', (string) $el->appendAttribute('accesskey', 1, FALSE));
+ Assert::same('
', (string) $el->appendAttribute('accesskey', 1, false));
Assert::same('
', (string) $el->appendAttribute('accesskey', 0));
Assert::same('
', (string) $el->setAttribute('accesskey', 0));
Assert::same('
', (string) $el->removeAttribute('accesskey'));
@@ -56,18 +56,18 @@ test(function () {
test(function () {
- $el = Html::el('img')->src('image.gif')->alt('')->setText(NULL)->setText('any content');
+ $el = Html::el('img')->src('image.gif')->alt('')->setText(null)->setText('any content');
Assert::same('
', (string) $el);
Assert::same('
', $el->startTag());
Assert::same('', $el->endTag());
- Html::$xhtml = FALSE;
+ Html::$xhtml = false;
Assert::same('
', (string) $el);
});
test(function () {
- Html::$xhtml = FALSE;
+ Html::$xhtml = false;
$el = Html::el('img')->setSrc('image.gif')->setAlt('alt1')->setAlt('alt2');
Assert::same('
', (string) $el);
Assert::same('image.gif', $el->getSrc());
@@ -84,8 +84,8 @@ test(function () {
$el->class = 'three';
$el->lang = '';
$el->title = '0';
- $el->checked = TRUE;
- $el->selected = FALSE;
+ $el->checked = true;
+ $el->selected = false;
$el->name = 'testname';
$el->setName('span');
Assert::same('', (string) $el);
@@ -101,10 +101,10 @@ test(function () { // small & big numbers
test(function () { // attributes escaping
- Html::$xhtml = TRUE;
+ Html::$xhtml = true;
Assert::same('', (string) Html::el('a')->one('"')->two("'")->three('<>')->four('&'));
- Html::$xhtml = FALSE;
+ Html::$xhtml = false;
Assert::same('', (string) Html::el('a')->one('"')->two("'")->three('<>')->four('&'));
Assert::same('', (string) Html::el('a')->one('``xx')); // mXSS
});
@@ -138,7 +138,7 @@ test(function () { // isset
Assert::false(isset(Html::el('a')->id));
Assert::true(isset(Html::el('a')->id('')->id));
- Html::el('a')->id = NULL;
+ Html::el('a')->id = null;
Assert::false(isset(Html::el('a')->id));
});
@@ -147,5 +147,5 @@ test(function () { // isset
Assert::true(isset(Html::el('a')->setAttribute('id', '')->id));
Assert::false(isset(Html::el('a')->removeAttribute('id')->id));
Assert::true(isset(Html::el('a')->setAttribute('id', '')->id));
- Assert::false(isset(Html::el('a')->setAttribute('id', NULL)->id));
+ Assert::false(isset(Html::el('a')->setAttribute('id', null)->id));
});
diff --git a/tests/Utils/Html.children.phpt b/tests/Utils/Html.children.phpt
index 19f3163b5..17b16dd41 100644
--- a/tests/Utils/Html.children.phpt
+++ b/tests/Utils/Html.children.phpt
@@ -30,7 +30,7 @@ test(function () { // add
test(function () {
- $el = Html::el(NULL);
+ $el = Html::el(null);
$el->addHtml(Html::el('p')->setText('one'));
$el->addText('
two
'); $el->addHtml('three
'); diff --git a/tests/Utils/Html.data.phpt b/tests/Utils/Html.data.phpt index 7dafe2707..86ebe2807 100644 --- a/tests/Utils/Html.data.phpt +++ b/tests/Utils/Html.data.phpt @@ -14,8 +14,8 @@ require __DIR__ . '/../bootstrap.php'; test(function () { // deprecated $el = Html::el('div'); $el->data['a'] = 'one'; - $el->data['b'] = NULL; - $el->data['c'] = FALSE; + $el->data['b'] = null; + $el->data['c'] = false; $el->data['d'] = ''; $el->data['e'] = 'two'; $el->{'data-x'} = 'x'; @@ -49,9 +49,9 @@ test(function () { // function test(function () { // special values $el = Html::el('div'); - $el->data('top', NULL); - $el->data('t', TRUE); - $el->data('f', FALSE); + $el->data('top', null); + $el->data('t', true); + $el->data('f', false); $el->data('x', ''); Assert::same('', (string) $el); @@ -61,10 +61,10 @@ test(function () { // special values test(function () { // setter $el = Html::el('div'); $el->setAttribute('data-x', 'x'); - $el->setAttribute('data-list', [1,2,3]); + $el->setAttribute('data-list', [1, 2, 3]); $el->setAttribute('data-arr', ['a' => 1]); - $el->setAttribute('top', NULL); - $el->setAttribute('active', FALSE); + $el->setAttribute('top', null); + $el->setAttribute('active', false); Assert::same('', (string) $el); }); diff --git a/tests/Utils/Html.style.phpt b/tests/Utils/Html.style.phpt index 4da4fad49..d41bbc3f1 100644 --- a/tests/Utils/Html.style.phpt +++ b/tests/Utils/Html.style.phpt @@ -14,16 +14,16 @@ require __DIR__ . '/../bootstrap.php'; test(function () { $el = Html::el('div'); $el->style[] = 'text-align:right'; - $el->style[] = NULL; + $el->style[] = null; $el->style[] = 'background-color: blue'; $el->class[] = 'one'; - $el->class[] = NULL; + $el->class[] = null; $el->class[] = 'two'; Assert::same('', (string) $el); - $el->style = NULL; + $el->style = null; $el->style['text-align'] = 'left'; $el->style['background-color'] = 'green'; Assert::same('', (string) $el); @@ -33,16 +33,16 @@ test(function () { test(function () { $el = Html::el('div'); $el->appendAttribute('style', 'text-align:right'); - $el->appendAttribute('style', NULL); + $el->appendAttribute('style', null); $el->appendAttribute('style', 'background-color: blue'); $el->appendAttribute('class', 'one'); - $el->appendAttribute('class', NULL); + $el->appendAttribute('class', null); $el->appendAttribute('class', 'two'); Assert::same('', (string) $el); - $el->setAttribute('style', NULL); + $el->setAttribute('style', null); $el->appendAttribute('style', 'text-align', 'left'); $el->appendAttribute('style', 'background-color', 'green'); Assert::same('', (string) $el); @@ -70,10 +70,10 @@ test(function () { // append $el->appendAttribute('style', 'text-align', 'left'); $el->class = 'one'; - $el->class('', TRUE); - $el->class('two', TRUE); + $el->class('', true); + $el->class('two', true); - $el->id('my', TRUE); + $el->id('my', true); Assert::same('', (string) $el); }); @@ -81,23 +81,23 @@ test(function () { // append test(function () { // append II $el = Html::el('div'); $el->style[] = 'text-align:right'; - $el->style('', TRUE); - $el->style('background-color: blue', TRUE); - $el->appendAttribute('style', 'color: orange', TRUE); + $el->style('', true); + $el->style('background-color: blue', true); + $el->appendAttribute('style', 'color: orange', true); Assert::same('', (string) $el); }); test(function () { // append III $el = Html::el('div'); - $el->class('top', TRUE); - $el->class('active', TRUE); - $el->appendAttribute('class', 'pull-right', TRUE); + $el->class('top', true); + $el->class('active', true); + $el->appendAttribute('class', 'pull-right', true); Assert::same('', (string) $el); - $el->class('top', NULL); - $el->class('active', FALSE); - $el->appendAttribute('class', 'pull-right', FALSE); + $el->class('top', null); + $el->class('active', false); + $el->appendAttribute('class', 'pull-right', false); Assert::same('', (string) $el); }); diff --git a/tests/Utils/Image.resize.phpt b/tests/Utils/Image.resize.phpt index 546db49c7..709db32c1 100644 --- a/tests/Utils/Image.resize.phpt +++ b/tests/Utils/Image.resize.phpt @@ -32,7 +32,7 @@ test(function () use ($main) { // cropping... test(function () use ($main) { // resizing X $image = clone $main; - $image->resize(150, NULL); + $image->resize(150, null); Assert::same(150, $image->width); Assert::same(89, $image->height); }); @@ -40,7 +40,7 @@ test(function () use ($main) { // resizing X test(function () use ($main) { // resizing Y shrink $image = clone $main; - $image->resize(NULL, 150, Image::SHRINK_ONLY); + $image->resize(null, 150, Image::SHRINK_ONLY); Assert::same(176, $image->width); Assert::same(104, $image->height); }); @@ -80,7 +80,7 @@ test(function () use ($main) { // resizing X Y shrink stretch test(function () use ($main) { // resizing X% $image = clone $main; - $image->resize('110%', NULL); + $image->resize('110%', null); Assert::same(194, $image->width); Assert::same(115, $image->height); }); @@ -96,7 +96,7 @@ test(function () use ($main) { // resizing X% Y% test(function () use ($main) { // flipping X $image = clone $main; - $image->resize(-150, NULL); + $image->resize(-150, null); Assert::same(150, $image->width); Assert::same(89, $image->height); }); @@ -104,7 +104,7 @@ test(function () use ($main) { // flipping X test(function () use ($main) { // flipping Y shrink $image = clone $main; - $image->resize(NULL, -150, Image::SHRINK_ONLY); + $image->resize(null, -150, Image::SHRINK_ONLY); Assert::same(176, $image->width); Assert::same(104, $image->height); }); diff --git a/tests/Utils/Image.save.phpt b/tests/Utils/Image.save.phpt index ebda8ac54..f5dfc32b1 100644 --- a/tests/Utils/Image.save.phpt +++ b/tests/Utils/Image.save.phpt @@ -27,7 +27,7 @@ test(function () use ($main) { test(function () use ($main) { - $main->save(TEMP_DIR . '/foo.x', NULL, Image::PNG); + $main->save(TEMP_DIR . '/foo.x', null, Image::PNG); Assert::true(is_file(TEMP_DIR . '/foo.x')); Assert::same(IMAGETYPE_PNG, getimagesize(TEMP_DIR . '/foo.x')[2]); }); @@ -40,16 +40,16 @@ test(function () use ($main) { $main->save(TEMP_DIR . '/foo.webp'); Assert::true(is_file(TEMP_DIR . '/foo.webp')); - Assert::same('WEBP', file_get_contents(TEMP_DIR . '/foo.webp', FALSE, NULL, 8, 4)); + Assert::same('WEBP', file_get_contents(TEMP_DIR . '/foo.webp', false, null, 8, 4)); - $main->save(TEMP_DIR . '/foo.y', NULL, Image::WEBP); + $main->save(TEMP_DIR . '/foo.y', null, Image::WEBP); Assert::true(is_file(TEMP_DIR . '/foo.y')); - Assert::same('WEBP', file_get_contents(TEMP_DIR . '/foo.y', FALSE, NULL, 8, 4)); + Assert::same('WEBP', file_get_contents(TEMP_DIR . '/foo.y', false, null, 8, 4)); }); Assert::exception(function () use ($main) { // invalid image type - $main->save('foo', NULL, IMG_WBMP); + $main->save('foo', null, IMG_WBMP); }, Nette\InvalidArgumentException::class, sprintf('Unsupported image type \'%d\'.', IMG_WBMP)); diff --git a/tests/Utils/Json.decode().phpt b/tests/Utils/Json.decode().phpt index 514144cee..95fc2f435 100644 --- a/tests/Utils/Json.decode().phpt +++ b/tests/Utils/Json.decode().phpt @@ -43,7 +43,7 @@ Assert::exception(function () { Assert::exception(function () { Json::decode('{}}'); -}, Nette\Utils\JsonException::class, PHP_VERSION_ID < 70000 ? ($hasJsonC ? 'unexpected character' : 'State mismatch (invalid or malformed JSON)') : 'Syntax error'); +}, Nette\Utils\JsonException::class, PHP_VERSION_ID < 70000 ? ($hasJsonC ? 'unexpected character' : 'State mismatch (invalid or malformed JSON)') : 'Syntax error'); Assert::exception(function () { diff --git a/tests/Utils/Object.arrayProperty.phpt b/tests/Utils/Object.arrayProperty.phpt index 5e53b706a..133e5eca6 100644 --- a/tests/Utils/Object.arrayProperty.phpt +++ b/tests/Utils/Object.arrayProperty.phpt @@ -13,16 +13,17 @@ class TestClass extends Nette\Object { private $items = []; + public function &getItems() { return $this->items; } + public function setItems(array $value) { $this->items = $value; } - } diff --git a/tests/Utils/Object.closureProperty.phpt b/tests/Utils/Object.closureProperty.phpt index e091a307f..e6a99541f 100644 --- a/tests/Utils/Object.closureProperty.phpt +++ b/tests/Utils/Object.closureProperty.phpt @@ -16,11 +16,11 @@ class TestClass extends Nette\Object protected $protected; private $private; - function __construct($func) + + public function __construct($func) { $this->public = $this->onPublic = $this->protected = $this->private = $func; } - } @@ -38,7 +38,7 @@ test(function () { $obj = new TestClass(123); $obj->onPublic = function () {}; // accidentally forgotten [] $obj->onPublic(1, 2); - }, Nette\UnexpectedValueException::class, 'Property TestClass::$onPublic must be array or NULL, object given.'); + }, Nette\UnexpectedValueException::class, 'Property TestClass::$onPublic must be array or null, object given.'); Assert::exception(function () { diff --git a/tests/Utils/Object.events.phpt b/tests/Utils/Object.events.phpt index 7a347f4ef..c8c50f8bf 100644 --- a/tests/Utils/Object.events.phpt +++ b/tests/Utils/Object.events.phpt @@ -18,7 +18,6 @@ class TestClass extends Nette\Object protected $onProtected; private $onPrivate; - } @@ -30,7 +29,7 @@ function handler($obj) class Handler { - function __invoke($obj) + public function __invoke($obj) { $obj->counter++; } @@ -77,4 +76,4 @@ Assert::exception(function () use ($obj) { Assert::exception(function () use ($obj) { $obj->onPublic = 'string'; $obj->onPublic(); -}, Nette\UnexpectedValueException::class, 'Property TestClass::$onPublic must be array or NULL, string given.'); +}, Nette\UnexpectedValueException::class, 'Property TestClass::$onPublic must be array or null, string given.'); diff --git a/tests/Utils/Object.extensionMethod.phpt b/tests/Utils/Object.extensionMethod.phpt index 25fbc3659..982e747c7 100644 --- a/tests/Utils/Object.extensionMethod.phpt +++ b/tests/Utils/Object.extensionMethod.phpt @@ -11,7 +11,8 @@ require __DIR__ . '/../bootstrap.php'; class TestClass extends Nette\Object { - public $foo = 'Hello', $bar = 'World'; + public $foo = 'Hello'; + public $bar = 'World'; } diff --git a/tests/Utils/Object.extensionMethodViaInterface.phpt b/tests/Utils/Object.extensionMethodViaInterface.phpt index d03d3ae2b..153ddb50d 100644 --- a/tests/Utils/Object.extensionMethodViaInterface.phpt +++ b/tests/Utils/Object.extensionMethodViaInterface.phpt @@ -12,14 +12,17 @@ require __DIR__ . '/../bootstrap.php'; interface IFirst -{} +{ +} interface ISecond extends IFirst -{} +{ +} class TestClass extends Object implements ISecond { - public $foo = 'Hello', $bar = 'World'; + public $foo = 'Hello'; + public $bar = 'World'; } diff --git a/tests/Utils/Object.magicMethod.errors.phpt b/tests/Utils/Object.magicMethod.errors.phpt index 404c1f59a..3f66129ca 100644 --- a/tests/Utils/Object.magicMethod.errors.phpt +++ b/tests/Utils/Object.magicMethod.errors.phpt @@ -19,6 +19,7 @@ class TestClass extends Nette\Object { protected $items = []; + public function abc() { parent::abc(); diff --git a/tests/Utils/Object.magicMethod.types.phpt b/tests/Utils/Object.magicMethod.types.phpt index dea9a6bb2..793263581 100644 --- a/tests/Utils/Object.magicMethod.types.phpt +++ b/tests/Utils/Object.magicMethod.types.phpt @@ -40,7 +40,7 @@ Assert::same('123', $obj->name); $obj->setEnabled(1); -Assert::same(TRUE, $obj->enabled); +Assert::same(true, $obj->enabled); Assert::exception(function () use ($obj) { $obj->setEnabled(new stdClass); diff --git a/tests/Utils/Object.methodGetter.phpt b/tests/Utils/Object.methodGetter.phpt index d090123df..19afdae2e 100644 --- a/tests/Utils/Object.methodGetter.phpt +++ b/tests/Utils/Object.methodGetter.phpt @@ -13,33 +13,38 @@ class TestClass extends Nette\Object { private $id; - function __construct($id = NULL) + + public function __construct($id = null) { $this->id = $id; } + public function publicMethod($a, $b) { return "$this->id $a $b"; } + protected function protectedMethod() { } + private function privateMethod() { } - public function getWithoutParameters() - {} + public function getWithoutParameters() + { + } } $obj1 = new TestClass(1); $method = $obj1->publicMethod; -Assert::same("1 2 3", $method(2, 3)); +Assert::same('1 2 3', $method(2, 3)); $rm = new ReflectionFunction($method); Assert::same($obj1, $rm->getClosureThis()); diff --git a/tests/Utils/Object.property.phpt b/tests/Utils/Object.property.phpt index eed1bb283..aaf3ee3a3 100644 --- a/tests/Utils/Object.property.phpt +++ b/tests/Utils/Object.property.phpt @@ -11,46 +11,52 @@ require __DIR__ . '/../bootstrap.php'; class TestClass extends Nette\Object { - private $foo, $bar; - public $declared; + private $foo; + private $bar; + - function __construct($foo = NULL, $bar = NULL) + public function __construct($foo = null, $bar = null) { $this->foo = $foo; $this->bar = $bar; } + public function foo() { // method getter has lower priority than getter } + public function getFoo() { return $this->foo; } + public function setFoo($foo) { $this->foo = $foo; } + public function getBar() { return $this->bar; } + public function setBazz($value) { $this->bar = $value; } + public function gets() // or setupXyz, settle... { echo __METHOD__; return 'ERROR'; } - } diff --git a/tests/Utils/Object.referenceProperty.phpt b/tests/Utils/Object.referenceProperty.phpt index e64c5357c..2ec0866f7 100644 --- a/tests/Utils/Object.referenceProperty.phpt +++ b/tests/Utils/Object.referenceProperty.phpt @@ -13,16 +13,17 @@ class TestClass extends Nette\Object { private $foo; + public function getFoo() { return $this->foo; } + public function setFoo($foo) { $this->foo = $foo; } - } diff --git a/tests/Utils/Object.undeclaredMethod.phpt b/tests/Utils/Object.undeclaredMethod.phpt index 8470f1453..5f6d19ff3 100644 --- a/tests/Utils/Object.undeclaredMethod.phpt +++ b/tests/Utils/Object.undeclaredMethod.phpt @@ -15,15 +15,18 @@ class TestClass extends Nette\Object { } - function methodO2() + + public function methodO2() { } + private static function methodS() { } - static function methodS2() + + public static function methodS2() { } } diff --git a/tests/Utils/Object.unsetProperty.phpt b/tests/Utils/Object.unsetProperty.phpt index c125b0a3e..bb9bc01b3 100644 --- a/tests/Utils/Object.unsetProperty.phpt +++ b/tests/Utils/Object.unsetProperty.phpt @@ -29,8 +29,7 @@ test(function () { test(function () { // double unset $obj = new TestClass; - unset($obj->foo); - unset($obj->foo); + unset($obj->foo, $obj->foo); }); diff --git a/tests/Utils/ObjectMixin.checkType().phpt b/tests/Utils/ObjectMixin.checkType().phpt index 9b4ebf2cc..b8d38d29b 100644 --- a/tests/Utils/ObjectMixin.checkType().phpt +++ b/tests/Utils/ObjectMixin.checkType().phpt @@ -13,12 +13,13 @@ require __DIR__ . '/../bootstrap.php'; class StrClass { - function __toString() + public function __toString() { return '1'; } } + function assertAccepts($type, $vals) { foreach ($vals as $key => $val) { @@ -27,6 +28,7 @@ function assertAccepts($type, $vals) } } + function assertRejects($type, $vals) { foreach ($vals as $key => $val) { @@ -35,6 +37,7 @@ function assertRejects($type, $vals) } } + function assertConverts($type, $vals) { foreach ($vals as $val) { @@ -46,35 +49,35 @@ function assertConverts($type, $vals) $resource = fopen(__FILE__, 'r'); -assertAccepts('', [NULL, TRUE, FALSE, 0, 0.0, 0.1, 1, 12, '', 'true', 'false', '-123', '123x', '+1.2', '1.0', [], [1, 2], ['a', 'b'], new stdClass, new StrClass, $resource]); -assertAccepts('mixed', [NULL, TRUE, FALSE, 0, 0.0, 0.1, 1, 12, '', 'true', 'false', '-123', '123x', '+1.2', '1.0', [], [1, 2], ['a', 'b'], new stdClass, new StrClass, $resource]); +assertAccepts('', [null, true, false, 0, 0.0, 0.1, 1, 12, '', 'true', 'false', '-123', '123x', '+1.2', '1.0', [], [1, 2], ['a', 'b'], new stdClass, new StrClass, $resource]); +assertAccepts('mixed', [null, true, false, 0, 0.0, 0.1, 1, 12, '', 'true', 'false', '-123', '123x', '+1.2', '1.0', [], [1, 2], ['a', 'b'], new stdClass, new StrClass, $resource]); -assertAccepts('scalar', [TRUE, FALSE, 0, 0.0, 0.1, 1, 12, '', 'true', 'false', '-123', '123x', '+1.2', '1.0']); -assertRejects('scalar', [NULL, [], [1, 2], ['a', 'b'], new stdClass, new StrClass, $resource]); +assertAccepts('scalar', [true, false, 0, 0.0, 0.1, 1, 12, '', 'true', 'false', '-123', '123x', '+1.2', '1.0']); +assertRejects('scalar', [null, [], [1, 2], ['a', 'b'], new stdClass, new StrClass, $resource]); -assertAccepts('boolean', [TRUE, FALSE]); -assertAccepts('bool', [TRUE, FALSE]); +assertAccepts('boolean', [true, false]); +assertAccepts('bool', [true, false]); assertRejects('bool', [[], [1, 2], ['a', 'b'], new stdClass, new StrClass, $resource]); assertConverts('bool', [ - [NULL, FALSE], - [0, FALSE], - [0.0, FALSE], - [0.1, TRUE], - [1, TRUE], - [12, TRUE], - ['', FALSE], - ['0', FALSE], - ['false', TRUE], - ['-123', TRUE], - ['123x', TRUE], + [null, false], + [0, false], + [0.0, false], + [0.1, true], + [1, true], + [12, true], + ['', false], + ['0', false], + ['false', true], + ['-123', true], + ['123x', true], ]); assertAccepts('string', ['', 'true', 'false', '-123', '123x', '+1.2', '1.0']); assertRejects('string', [[], [1, 2], ['a', 'b'], new stdClass, $resource]); assertConverts('string', [ - [NULL, ''], - [TRUE, '1'], - [FALSE, ''], + [null, ''], + [true, '1'], + [false, ''], [0, '0'], [0.0, '0'], [0.1, '0.1'], @@ -87,9 +90,9 @@ assertAccepts('integer', [0, 1, 12]); assertAccepts('int', [0, 1, 12]); assertRejects('int', [0.1, '', 'true', 'false', '123x', '+1.2', [], [1, 2], ['a', 'b'], new stdClass, new StrClass, $resource]); assertConverts('int', [ - [NULL, 0], - [TRUE, 1], - [FALSE, 0], + [null, 0], + [true, 1], + [false, 0], [0.0, 0], ['-123', -123], ['1.0', 1], @@ -98,9 +101,9 @@ assertConverts('int', [ assertAccepts('float', [0.0, 0.1]); assertRejects('float', ['', 'true', 'false', '123x', [], [1, 2], ['a', 'b'], new stdClass, new StrClass, $resource]); assertConverts('float', [ - [NULL, 0.0], - [TRUE, 1.0], - [FALSE, 0.0], + [null, 0.0], + [true, 1.0], + [false, 0.0], [0, 0.0], [1, 1.0], [12, 12.0], @@ -110,26 +113,26 @@ assertConverts('float', [ ]); assertAccepts('array', [[], [1, 2], ['a', 'b']]); -assertRejects('array', [NULL, TRUE, FALSE, 0, 0.1, 12, '', '123x', new stdClass, new StrClass, $resource]); +assertRejects('array', [null, true, false, 0, 0.1, 12, '', '123x', new stdClass, new StrClass, $resource]); assertAccepts('object', [new stdClass, new StrClass]); -assertRejects('object', [NULL, TRUE, FALSE, 0, 0.1, 12, '', '123x', [], [1, 2], ['a', 'b'], $resource]); +assertRejects('object', [null, true, false, 0, 0.1, 12, '', '123x', [], [1, 2], ['a', 'b'], $resource]); assertAccepts('callable', [[new StrClass, '__toString']]); -assertRejects('callable', [NULL, TRUE, FALSE, 0, 0.1, 12, '', '123x', [], [1, 2], ['a', 'b'], new stdClass, new StrClass, $resource]); +assertRejects('callable', [null, true, false, 0, 0.1, 12, '', '123x', [], [1, 2], ['a', 'b'], new stdClass, new StrClass, $resource]); assertAccepts('resource', [$resource]); -assertRejects('resource', [NULL, TRUE, FALSE, 0, 0.1, 12, '', '123x', [], [1, 2], ['a', 'b'], new stdClass, new StrClass]); +assertRejects('resource', [null, true, false, 0, 0.1, 12, '', '123x', [], [1, 2], ['a', 'b'], new stdClass, new StrClass]); assertAccepts('stdClass', [new stdClass]); -assertRejects('stdClass', [NULL, TRUE, FALSE, 0, 0.1, 12, '', '123x', [], [1, 2], ['a', 'b'], new StrClass, $resource]); +assertRejects('stdClass', [null, true, false, 0, 0.1, 12, '', '123x', [], [1, 2], ['a', 'b'], new StrClass, $resource]); -assertAccepts('null', [NULL]); -assertAccepts('NULL', [NULL]); -assertRejects('NULL', [TRUE, FALSE, 0, 0.1, 12, '', '123x', [], [1, 2], ['a', 'b'], new stdClass, new StrClass, $resource]); +assertAccepts('null', [null]); +assertAccepts('NULL', [null]); +assertRejects('NULL', [true, false, 0, 0.1, 12, '', '123x', [], [1, 2], ['a', 'b'], new stdClass, new StrClass, $resource]); assertAccepts('int[]', [[], [1, 2]]); -assertRejects('int[]', [NULL, TRUE, FALSE, 0, 0.1, 12, '', '123x', ['a', 'b'], new stdClass, new StrClass, $resource]); +assertRejects('int[]', [null, true, false, 0, 0.1, 12, '', '123x', ['a', 'b'], new stdClass, new StrClass, $resource]); assertConverts('int[]', [ [['1'], [1]], ]); @@ -141,9 +144,9 @@ Assert::equal(['1', new stdClass], $val); // do not modify assertAccepts('array|string', ['', '123x', [], [1, 2], ['a', 'b']]); assertRejects('array|string', [new stdClass, $resource]); assertConverts('array|string', [ - [NULL, ''], - [TRUE, '1'], - [FALSE, ''], + [null, ''], + [true, '1'], + [false, ''], [0, '0'], [0.0, '0'], [0.1, '0.1'], @@ -153,9 +156,9 @@ assertConverts('array|string', [ ]); -assertAccepts('string|bool|NULL', [NULL, TRUE, FALSE, '', '123x']); -assertRejects('string|bool|NULL', [[], [1, 2], ['a', 'b'], new stdClass, $resource]); -assertConverts('string|bool|NULL', [ +assertAccepts('string|bool|null', [null, true, false, '', '123x']); +assertRejects('string|bool|null', [[], [1, 2], ['a', 'b'], new stdClass, $resource]); +assertConverts('string|bool|null', [ [0, '0'], [0.0, '0'], [0.1, '0.1'], diff --git a/tests/Utils/ObjectMixin.getMagicProperites().phpt b/tests/Utils/ObjectMixin.getMagicProperites().phpt index 05be56bbd..4f3ee97b5 100644 --- a/tests/Utils/ObjectMixin.getMagicProperites().phpt +++ b/tests/Utils/ObjectMixin.getMagicProperites().phpt @@ -30,54 +30,84 @@ require __DIR__ . '/../bootstrap.php'; */ class TestClass { - function getGetter() - {} + public function getGetter() + { + } - function &isGetter2() - {} - function setSetter() - {} + public function &isGetter2() + { + } - function getBoth() - {} - function setBoth() - {} + public function setSetter() + { + } - function getUpper() - {} - function getCase() - {} + public function getBoth() + { + } + + + public function setBoth() + { + } + + + public function getUpper() + { + } + + + public function getCase() + { + } + private function getPrivate() - {} + { + } + protected function getProtected() - {} + { + } - static function getStatic() - {} - function getRead() - {} + public static function getStatic() + { + } - function setRead() - {} - function getWrite() - {} + public function getRead() + { + } - function setWrite() - {} - function getInvalid() - {} + public function setRead() + { + } - function getInvalid2() - {} + public function getWrite() + { + } + + + public function setWrite() + { + } + + + public function getInvalid() + { + } + + + public function getInvalid2() + { + } } @@ -97,21 +127,23 @@ Assert::same([ /** -* @property int $bar -*/ + * @property int $bar + */ class ParentClass { - function getFoo() - {} + public function getFoo() + { + } } /** -* @property int $foo -*/ + * @property int $foo + */ class ChildClass extends ParentClass { - function getBar() - {} + public function getBar() + { + } } Assert::same([], ObjectMixin::getMagicProperties('ParentClass')); diff --git a/tests/Utils/ObjectMixin.getSuggestion().phpt b/tests/Utils/ObjectMixin.getSuggestion().phpt index c1e9987d7..ab5db03be 100644 --- a/tests/Utils/ObjectMixin.getSuggestion().phpt +++ b/tests/Utils/ObjectMixin.getSuggestion().phpt @@ -11,23 +11,23 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -Assert::same(NULL, ObjectMixin::getSuggestion([], '')); -Assert::same(NULL, ObjectMixin::getSuggestion([], 'a')); -Assert::same(NULL, ObjectMixin::getSuggestion(['a'], 'a')); +Assert::same(null, ObjectMixin::getSuggestion([], '')); +Assert::same(null, ObjectMixin::getSuggestion([], 'a')); +Assert::same(null, ObjectMixin::getSuggestion(['a'], 'a')); Assert::same('a', ObjectMixin::getSuggestion(['a', 'b'], '')); Assert::same('b', ObjectMixin::getSuggestion(['a', 'b'], 'a')); // ignore 100% match Assert::same('a1', ObjectMixin::getSuggestion(['a1', 'a2'], 'a')); // take first -Assert::same(NULL, ObjectMixin::getSuggestion(['aaa', 'bbb'], 'a')); -Assert::same(NULL, ObjectMixin::getSuggestion(['aaa', 'bbb'], 'ab')); -Assert::same(NULL, ObjectMixin::getSuggestion(['aaa', 'bbb'], 'abc')); +Assert::same(null, ObjectMixin::getSuggestion(['aaa', 'bbb'], 'a')); +Assert::same(null, ObjectMixin::getSuggestion(['aaa', 'bbb'], 'ab')); +Assert::same(null, ObjectMixin::getSuggestion(['aaa', 'bbb'], 'abc')); Assert::same('bar', ObjectMixin::getSuggestion(['foo', 'bar', 'baz'], 'baz')); Assert::same('abcd', ObjectMixin::getSuggestion(['abcd'], 'acbd')); Assert::same('abcd', ObjectMixin::getSuggestion(['abcd'], 'axbd')); -Assert::same(NULL, ObjectMixin::getSuggestion(['abcd'], 'axyd')); // 'tags' vs 'this' -Assert::same(NULL, ObjectMixin::getSuggestion(['setItem'], 'item')); +Assert::same(null, ObjectMixin::getSuggestion(['abcd'], 'axyd')); // 'tags' vs 'this' +Assert::same(null, ObjectMixin::getSuggestion(['setItem'], 'item')); Assert::same('setItem', ObjectMixin::getSuggestion(['setItem'], 'Item')); Assert::same('setItem', ObjectMixin::getSuggestion(['setItem'], 'addItem')); -Assert::same(NULL, ObjectMixin::getSuggestion(['addItem'], 'addItem')); +Assert::same(null, ObjectMixin::getSuggestion(['addItem'], 'addItem')); /* diff --git a/tests/Utils/ObjectMixin.strictness.phpt b/tests/Utils/ObjectMixin.strictness.phpt index ed7a9f859..7b9f0ba98 100644 --- a/tests/Utils/ObjectMixin.strictness.phpt +++ b/tests/Utils/ObjectMixin.strictness.phpt @@ -4,9 +4,9 @@ * Test: Nette\Utils\ObjectMixin: strictness */ -use Tester\Assert; -use Nette\Utils\ObjectMixin; use Nette\MemberAccessException; +use Nette\Utils\ObjectMixin; +use Tester\Assert; require __DIR__ . '/../bootstrap.php'; @@ -15,21 +15,29 @@ class TestClass { public $public; + public static $publicStatic; + protected $protected; - public static $publicStatic; public function publicMethod() - {} + { + } + public static function publicMethodStatic() - {} + { + } + protected function protectedMethod() - {} + { + } + protected static function protectedMethodS() - {} + { + } } class TestChild extends TestClass diff --git a/tests/Utils/Reflection.getParameterDefaultValue.phpt b/tests/Utils/Reflection.getParameterDefaultValue.phpt index 9a31fdcd4..d8106bec3 100644 --- a/tests/Utils/Reflection.getParameterDefaultValue.phpt +++ b/tests/Utils/Reflection.getParameterDefaultValue.phpt @@ -18,7 +18,8 @@ namespace NS { { const DEFINED = 'abc'; - function method( + + public function method( $a, $b = self::DEFINED, $c = Foo::DEFINED, @@ -34,7 +35,6 @@ namespace NS { } } - namespace { use Nette\Utils\Reflection; use Tester\Assert; diff --git a/tests/Utils/Reflection.getParameterType.php71.phpt b/tests/Utils/Reflection.getParameterType.php71.phpt index 6aacd312f..6566dc5e9 100644 --- a/tests/Utils/Reflection.getParameterType.php71.phpt +++ b/tests/Utils/Reflection.getParameterType.php71.phpt @@ -16,8 +16,9 @@ use Test\B; // for testing purposes class A { - function method(Undeclared $undeclared, B $b, array $array, callable $callable, $none, ?B $nullable) - {} + public function method(Undeclared $undeclared, B $b, array $array, callable $callable, $none, ?B $nullable) + { + } } $method = new \ReflectionMethod('A', 'method'); diff --git a/tests/Utils/Reflection.getParameterType.phpt b/tests/Utils/Reflection.getParameterType.phpt index 049c0ef83..fe584f69d 100644 --- a/tests/Utils/Reflection.getParameterType.phpt +++ b/tests/Utils/Reflection.getParameterType.phpt @@ -15,14 +15,16 @@ use Test\B; // for testing purposes class A { - function method(Undeclared $undeclared, B $b, array $array, callable $callable, self $self, $none) - {} + public function method(Undeclared $undeclared, B $b, array $array, callable $callable, self $self, $none) + { + } } class AExt extends A { - function methodExt(parent $parent) - {} + public function methodExt(parent $parent) + { + } } $method = new ReflectionMethod('A', 'method'); diff --git a/tests/Utils/Reflection.getReturnType.php7.phpt b/tests/Utils/Reflection.getReturnType.php7.phpt index b85ad423e..d805baf27 100644 --- a/tests/Utils/Reflection.getReturnType.php7.phpt +++ b/tests/Utils/Reflection.getReturnType.php7.phpt @@ -11,30 +11,39 @@ namespace NS class A { - function noType() - {} + public function noType() + { + } - function classType(): B - {} - function nativeType(): string - {} + public function classType(): B + { + } - function selfType(): self - {} - function parentType(): parent - {} + public function nativeType(): string + { + } + + + public function selfType(): self + { + } + + + public function parentType(): parent + { + } } class AExt extends A { - function parentTypeExt(): parent - {} + public function parentTypeExt(): parent + { + } } } - namespace { use Nette\Utils\Reflection; diff --git a/tests/Utils/Reflection.getReturnType.php71.phpt b/tests/Utils/Reflection.getReturnType.php71.phpt index e401be936..e5bedf13a 100644 --- a/tests/Utils/Reflection.getReturnType.php71.phpt +++ b/tests/Utils/Reflection.getReturnType.php71.phpt @@ -11,30 +11,42 @@ namespace NS class A { - function noType() - {} + public function noType() + { + } - function classType(): B - {} - function nativeType(): string - {} + public function classType(): B + { + } - function selfType(): self - {} - function nullableClassType(): ?B - {} + public function nativeType(): string + { + } - function nullableNativeType(): ?string - {} - function nullableSelfType(): ?self - {} + public function selfType(): self + { + } + + + public function nullableClassType(): ?B + { + } + + + public function nullableNativeType(): ?string + { + } + + + public function nullableSelfType(): ?self + { + } } } - namespace { use Nette\Utils\Reflection; diff --git a/tests/Utils/Reflection.toString.phpt b/tests/Utils/Reflection.toString.phpt index 0861df131..028b4462f 100644 --- a/tests/Utils/Reflection.toString.phpt +++ b/tests/Utils/Reflection.toString.phpt @@ -14,11 +14,13 @@ class Foo { public $var; - function method($param) + + public function method($param) { } } + function func($param) { } diff --git a/tests/Utils/SmartObject.arrayProperty.old.phpt b/tests/Utils/SmartObject.arrayProperty.old.phpt index 5db76a841..25526b953 100644 --- a/tests/Utils/SmartObject.arrayProperty.old.phpt +++ b/tests/Utils/SmartObject.arrayProperty.old.phpt @@ -15,16 +15,17 @@ class TestClass private $items = []; + public function &getItems() { return $this->items; } + public function setItems(array $value) { $this->items = $value; } - } diff --git a/tests/Utils/SmartObject.arrayProperty.phpt b/tests/Utils/SmartObject.arrayProperty.phpt index a9f0690b2..a3980cd95 100644 --- a/tests/Utils/SmartObject.arrayProperty.phpt +++ b/tests/Utils/SmartObject.arrayProperty.phpt @@ -18,16 +18,17 @@ class TestClass private $items = []; + public function &getItems() { return $this->items; } + public function setItems(array $value) { $this->items = $value; } - } diff --git a/tests/Utils/SmartObject.closureProperty.phpt b/tests/Utils/SmartObject.closureProperty.phpt index 3b60c3d2f..986090d0b 100644 --- a/tests/Utils/SmartObject.closureProperty.phpt +++ b/tests/Utils/SmartObject.closureProperty.phpt @@ -18,11 +18,11 @@ class TestClass protected $protected; private $private; - function __construct($func) + + public function __construct($func) { $this->public = $this->onPublic = $this->protected = $this->private = $func; } - } @@ -46,7 +46,7 @@ test(function () { $obj = new TestClass(123); $obj->onPublic = function () {}; // accidentally forgotten [] $obj->onPublic(1, 2); - }, Nette\UnexpectedValueException::class, 'Property TestClass::$onPublic must be array or NULL, object given.'); + }, Nette\UnexpectedValueException::class, 'Property TestClass::$onPublic must be array or null, object given.'); Assert::exception(function () { diff --git a/tests/Utils/SmartObject.events.phpt b/tests/Utils/SmartObject.events.phpt index dc20435d1..b108b78e0 100644 --- a/tests/Utils/SmartObject.events.phpt +++ b/tests/Utils/SmartObject.events.phpt @@ -20,7 +20,6 @@ class TestClass protected $onProtected; private $onPrivate; - } @@ -32,7 +31,7 @@ function handler($obj) class Handler { - function __invoke($obj) + public function __invoke($obj) { $obj->counter++; } @@ -79,4 +78,4 @@ Assert::exception(function () use ($obj) { Assert::exception(function () use ($obj) { $obj->onPublic = 'string'; $obj->onPublic(); -}, Nette\UnexpectedValueException::class, 'Property TestClass::$onPublic must be array or NULL, string given.'); +}, Nette\UnexpectedValueException::class, 'Property TestClass::$onPublic must be array or null, string given.'); diff --git a/tests/Utils/SmartObject.extensionMethod.phpt b/tests/Utils/SmartObject.extensionMethod.phpt index b2ab12f81..b4d7857f8 100644 --- a/tests/Utils/SmartObject.extensionMethod.phpt +++ b/tests/Utils/SmartObject.extensionMethod.phpt @@ -13,7 +13,8 @@ class TestClass { use Nette\SmartObject; - public $foo = 'Hello', $bar = 'World'; + public $foo = 'Hello'; + public $bar = 'World'; } diff --git a/tests/Utils/SmartObject.extensionMethodViaInterface.phpt b/tests/Utils/SmartObject.extensionMethodViaInterface.phpt index 9f7863768..b03ef4373 100644 --- a/tests/Utils/SmartObject.extensionMethodViaInterface.phpt +++ b/tests/Utils/SmartObject.extensionMethodViaInterface.phpt @@ -12,16 +12,19 @@ require __DIR__ . '/../bootstrap.php'; interface IFirst -{} +{ +} interface ISecond extends IFirst -{} +{ +} class TestClass implements ISecond { use SmartObject; - public $foo = 'Hello', $bar = 'World'; + public $foo = 'Hello'; + public $bar = 'World'; } diff --git a/tests/Utils/SmartObject.magicMethod.errors.phpt b/tests/Utils/SmartObject.magicMethod.errors.phpt index b12a9f229..9e5de6b85 100644 --- a/tests/Utils/SmartObject.magicMethod.errors.phpt +++ b/tests/Utils/SmartObject.magicMethod.errors.phpt @@ -24,6 +24,7 @@ class TestClass extends ParentClass { protected $items = []; + public function abc() { parent::abc(); diff --git a/tests/Utils/SmartObject.magicMethod.types.phpt b/tests/Utils/SmartObject.magicMethod.types.phpt index 643fbdf17..666fc858f 100644 --- a/tests/Utils/SmartObject.magicMethod.types.phpt +++ b/tests/Utils/SmartObject.magicMethod.types.phpt @@ -42,7 +42,7 @@ Assert::same('123', @$obj->name); @$obj->setEnabled(1); -Assert::same(TRUE, @$obj->enabled); +Assert::same(true, @$obj->enabled); Assert::exception(function () use ($obj) { @$obj->setEnabled(new stdClass); diff --git a/tests/Utils/SmartObject.methodGetter.phpt b/tests/Utils/SmartObject.methodGetter.phpt index e49781efa..82cee888c 100644 --- a/tests/Utils/SmartObject.methodGetter.phpt +++ b/tests/Utils/SmartObject.methodGetter.phpt @@ -15,27 +15,32 @@ class TestClass private $id; - function __construct($id = NULL) + + public function __construct($id = null) { $this->id = $id; } + public function publicMethod($a, $b) { return "$this->id $a $b"; } + protected function protectedMethod() { } + private function privateMethod() { } - public function getWithoutParameters() - {} + public function getWithoutParameters() + { + } } @@ -48,7 +53,7 @@ Assert::error(function () { $obj1 = new TestClass(1); $method = @$obj1->publicMethod; -Assert::same("1 2 3", $method(2, 3)); +Assert::same('1 2 3', $method(2, 3)); $rm = new ReflectionFunction($method); Assert::same($obj1, $rm->getClosureThis()); diff --git a/tests/Utils/SmartObject.property.old.phpt b/tests/Utils/SmartObject.property.old.phpt index 436f009d9..5e6eb5124 100644 --- a/tests/Utils/SmartObject.property.old.phpt +++ b/tests/Utils/SmartObject.property.old.phpt @@ -13,46 +13,53 @@ class TestClass { use Nette\SmartObject; - private $foo, $bar; - public $declared; - function __construct($foo = NULL, $bar = NULL) + private $foo; + private $bar; + + + public function __construct($foo = null, $bar = null) { $this->foo = $foo; $this->bar = $bar; } + public function foo() { // method getter has lower priority than getter } + public function getFoo() { return $this->foo; } + public function setFoo($foo) { $this->foo = $foo; } + public function getBar() { return $this->bar; } + public function setBazz($value) { $this->bar = $value; } + public function gets() // or setupXyz, settle... { echo __METHOD__; return 'ERROR'; } - } diff --git a/tests/Utils/SmartObject.property.phpt b/tests/Utils/SmartObject.property.phpt index c0ab3aa21..a5303cbb5 100644 --- a/tests/Utils/SmartObject.property.phpt +++ b/tests/Utils/SmartObject.property.phpt @@ -19,46 +19,53 @@ class TestClass { use Nette\SmartObject; - private $foo, $bar; - public $declared; - function __construct($foo = NULL, $bar = NULL) + private $foo; + private $bar; + + + public function __construct($foo = null, $bar = null) { $this->foo = $foo; $this->bar = $bar; } + public function foo() { // method getter has lower priority than getter } + public function getFoo() { return $this->foo; } + public function setFoo($foo) { $this->foo = $foo; } + protected function getBar() { return $this->bar; } + public function setBazz($value) { $this->bar = $value; } + public function gets() // or setupXyz, settle... { echo __METHOD__; return 'ERROR'; } - } diff --git a/tests/Utils/SmartObject.referenceProperty.old.phpt b/tests/Utils/SmartObject.referenceProperty.old.phpt index ec30775fa..2d1b8bcc6 100644 --- a/tests/Utils/SmartObject.referenceProperty.old.phpt +++ b/tests/Utils/SmartObject.referenceProperty.old.phpt @@ -15,16 +15,17 @@ class TestClass private $foo; + public function getFoo() { return $this->foo; } + public function setFoo($foo) { $this->foo = $foo; } - } diff --git a/tests/Utils/SmartObject.referenceProperty.phpt b/tests/Utils/SmartObject.referenceProperty.phpt index cc987c4a1..8033fd858 100644 --- a/tests/Utils/SmartObject.referenceProperty.phpt +++ b/tests/Utils/SmartObject.referenceProperty.phpt @@ -18,16 +18,17 @@ class TestClass private $foo; + public function getFoo() { return $this->foo; } + public function setFoo($foo) { $this->foo = $foo; } - } diff --git a/tests/Utils/SmartObject.reflection.phpt b/tests/Utils/SmartObject.reflection.phpt index e8b607c84..9efd2a4ed 100644 --- a/tests/Utils/SmartObject.reflection.phpt +++ b/tests/Utils/SmartObject.reflection.phpt @@ -12,7 +12,6 @@ require __DIR__ . '/../bootstrap.php'; class TestClass { use Nette\SmartObject; - } diff --git a/tests/Utils/SmartObject.undeclaredMethod.annotation.phpt b/tests/Utils/SmartObject.undeclaredMethod.annotation.phpt index 5c3b5a545..fc980cbec 100644 --- a/tests/Utils/SmartObject.undeclaredMethod.annotation.phpt +++ b/tests/Utils/SmartObject.undeclaredMethod.annotation.phpt @@ -13,13 +13,15 @@ require __DIR__ . '/../bootstrap.php'; * @method traitA() */ trait TraitA -{} +{ +} /** * @method traitB() */ trait TraitB -{} +{ +} /** * @method traitC() diff --git a/tests/Utils/SmartObject.undeclaredMethod.phpt b/tests/Utils/SmartObject.undeclaredMethod.phpt index d63961187..6d8630c64 100644 --- a/tests/Utils/SmartObject.undeclaredMethod.phpt +++ b/tests/Utils/SmartObject.undeclaredMethod.phpt @@ -17,15 +17,18 @@ class TestClass { } - function methodO2() + + public function methodO2() { } + private static function methodS() { } - static function methodS2() + + public static function methodS2() { } } diff --git a/tests/Utils/SmartObject.unsetProperty.phpt b/tests/Utils/SmartObject.unsetProperty.phpt index d27ab3e99..3533107f0 100644 --- a/tests/Utils/SmartObject.unsetProperty.phpt +++ b/tests/Utils/SmartObject.unsetProperty.phpt @@ -31,8 +31,7 @@ test(function () { test(function () { // double unset $obj = new TestClass; - unset($obj->foo); - unset($obj->foo); + unset($obj->foo, $obj->foo); }); diff --git a/tests/Utils/StaticClass.phpt b/tests/Utils/StaticClass.phpt index 094d20368..fecffe30f 100644 --- a/tests/Utils/StaticClass.phpt +++ b/tests/Utils/StaticClass.phpt @@ -14,8 +14,8 @@ class TestClass use Nette\StaticClass; public static function method() - {} - + { + } } Assert::exception(function () { diff --git a/tests/Utils/Strings.Regexp.errors.backtrack.phpt b/tests/Utils/Strings.Regexp.errors.backtrack.phpt index d20e1272e..7eb9e5ca2 100644 --- a/tests/Utils/Strings.Regexp.errors.backtrack.phpt +++ b/tests/Utils/Strings.Regexp.errors.backtrack.phpt @@ -30,10 +30,13 @@ Assert::exception(function () { Strings::replace('0123456789', '#.*\d\d#', 'x'); }, Nette\Utils\RegexpException::class, 'Backtrack limit was exhausted (pattern: #.*\d\d#)'); -function cb() { + +function cb() +{ return 'x'; } + Assert::exception(function () { Strings::replace('0123456789', '#.*\d\d#', Nette\Utils\Callback::closure('cb')); }, Nette\Utils\RegexpException::class, 'Backtrack limit was exhausted (pattern: #.*\d\d#)'); diff --git a/tests/Utils/Strings.Regexp.errors.compilation.phpt b/tests/Utils/Strings.Regexp.errors.compilation.phpt index c59ddd562..600bfc7b6 100644 --- a/tests/Utils/Strings.Regexp.errors.compilation.phpt +++ b/tests/Utils/Strings.Regexp.errors.compilation.phpt @@ -31,10 +31,13 @@ Assert::exception(function () { Strings::replace('0123456789', ['##', '#*#'], 'x'); }, Nette\Utils\RegexpException::class, 'Compilation failed: nothing to repeat at offset 0 in pattern: ## or #*#'); -function cb() { + +function cb() +{ return 'x'; } + Assert::exception(function () { Strings::replace('0123456789', '#*#', Nette\Utils\Callback::closure('cb')); }, Nette\Utils\RegexpException::class, 'Compilation failed: nothing to repeat at offset 0 in pattern: #*#'); diff --git a/tests/Utils/Strings.Regexp.errors.utf8.phpt b/tests/Utils/Strings.Regexp.errors.utf8.phpt index 795185841..13cb4dc55 100644 --- a/tests/Utils/Strings.Regexp.errors.utf8.phpt +++ b/tests/Utils/Strings.Regexp.errors.utf8.phpt @@ -27,10 +27,13 @@ Assert::exception(function () { Strings::replace("0123456789\xFF", '#\d#u', 'x'); }, Nette\Utils\RegexpException::class, 'Malformed UTF-8 data (pattern: #\d#u)'); -function cb() { + +function cb() +{ return 'x'; } + Assert::exception(function () { Strings::replace("0123456789\xFF", '#\d#u', Nette\Utils\Callback::closure('cb')); }, Nette\Utils\RegexpException::class, 'Malformed UTF-8 data (pattern: #\d#u)'); diff --git a/tests/Utils/Strings.endsWith().phpt b/tests/Utils/Strings.endsWith().phpt index a2fc4c2ab..235d2fb23 100644 --- a/tests/Utils/Strings.endsWith().phpt +++ b/tests/Utils/Strings.endsWith().phpt @@ -11,7 +11,7 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -Assert::true(Strings::endsWith('123', NULL), "endsWith('123', NULL)"); +Assert::true(Strings::endsWith('123', null), "endsWith('123', null)"); 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.indent().phpt b/tests/Utils/Strings.indent().phpt index 6843d075e..67aa34a25 100644 --- a/tests/Utils/Strings.indent().phpt +++ b/tests/Utils/Strings.indent().phpt @@ -11,12 +11,12 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -Assert::same("", Strings::indent("")); -Assert::same("\n", Strings::indent("\n")); -Assert::same("\tword", Strings::indent("word")); -Assert::same("\n\tword", Strings::indent("\nword")); -Assert::same("\n\tword", Strings::indent("\nword")); -Assert::same("\n\tword\n", Strings::indent("\nword\n")); -Assert::same("\r\n\tword\r\n", Strings::indent("\r\nword\r\n")); -Assert::same("\r\n\t\tword\r\n", Strings::indent("\r\nword\r\n", 2)); -Assert::same("\r\n word\r\n", Strings::indent("\r\nword\r\n", 2, ' ')); +Assert::same('', Strings::indent('')); +Assert::same("\n", Strings::indent("\n")); +Assert::same("\tword", Strings::indent('word')); +Assert::same("\n\tword", Strings::indent("\nword")); +Assert::same("\n\tword", Strings::indent("\nword")); +Assert::same("\n\tword\n", Strings::indent("\nword\n")); +Assert::same("\r\n\tword\r\n", Strings::indent("\r\nword\r\n")); +Assert::same("\r\n\t\tword\r\n", Strings::indent("\r\nword\r\n", 2)); +Assert::same("\r\n word\r\n", Strings::indent("\r\nword\r\n", 2, ' ')); diff --git a/tests/Utils/Strings.normalize().phpt b/tests/Utils/Strings.normalize().phpt index da298039e..e9801afee 100644 --- a/tests/Utils/Strings.normalize().phpt +++ b/tests/Utils/Strings.normalize().phpt @@ -11,13 +11,13 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -Assert::same("Hello\n World", Strings::normalize("\r\nHello \r World \n\n")); +Assert::same("Hello\n World", Strings::normalize("\r\nHello \r World \n\n")); -Assert::same('Hello World', Strings::normalize("Hello \x00 World")); -Assert::same('Hello World', Strings::normalize("Hello \x0B World")); -Assert::same('Hello World', Strings::normalize("Hello \x1F World")); -Assert::same("Hello \x7E World", Strings::normalize("Hello \x7E World")); -Assert::same('Hello World', Strings::normalize("Hello \x7F World")); -Assert::same('Hello World', Strings::normalize("Hello \xC2\x80 World")); -Assert::same('Hello World', Strings::normalize("Hello \xC2\x9F World")); -Assert::same("Hello \xC2\xA0 World", Strings::normalize("Hello \xC2\xA0 World")); +Assert::same('Hello World', Strings::normalize("Hello \x00 World")); +Assert::same('Hello World', Strings::normalize("Hello \x0B World")); +Assert::same('Hello World', Strings::normalize("Hello \x1F World")); +Assert::same("Hello \x7E World", Strings::normalize("Hello \x7E World")); +Assert::same('Hello World', Strings::normalize("Hello \x7F World")); +Assert::same('Hello World', Strings::normalize("Hello \xC2\x80 World")); +Assert::same('Hello World', Strings::normalize("Hello \xC2\x9F World")); +Assert::same("Hello \xC2\xA0 World", Strings::normalize("Hello \xC2\xA0 World")); diff --git a/tests/Utils/Strings.normalizeNewLines().phpt b/tests/Utils/Strings.normalizeNewLines().phpt index 67565fbaa..f4230df42 100644 --- a/tests/Utils/Strings.normalizeNewLines().phpt +++ b/tests/Utils/Strings.normalizeNewLines().phpt @@ -11,5 +11,5 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -Assert::same("\n \n \n\n", Strings::normalizeNewLines("\r\n \r \n\n")); -Assert::same("\n\n", Strings::normalizeNewLines("\n\r")); +Assert::same("\n \n \n\n", Strings::normalizeNewLines("\r\n \r \n\n")); +Assert::same("\n\n", Strings::normalizeNewLines("\n\r")); diff --git a/tests/Utils/Strings.replace().phpt b/tests/Utils/Strings.replace().phpt index 6a09dcf4e..fa1172729 100644 --- a/tests/Utils/Strings.replace().phpt +++ b/tests/Utils/Strings.replace().phpt @@ -13,7 +13,7 @@ require __DIR__ . '/../bootstrap.php'; class Test { - static function cb() + public static function cb() { return '@'; } diff --git a/tests/Utils/Strings.startsWith().phpt b/tests/Utils/Strings.startsWith().phpt index b6f6559bf..b9d64cbeb 100644 --- a/tests/Utils/Strings.startsWith().phpt +++ b/tests/Utils/Strings.startsWith().phpt @@ -11,7 +11,7 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -Assert::true(Strings::startsWith('123', NULL), "startsWith('123', NULL)"); +Assert::true(Strings::startsWith('123', null), "startsWith('123', null)"); 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.trim().phpt b/tests/Utils/Strings.trim().phpt index c71974733..521c0bf25 100644 --- a/tests/Utils/Strings.trim().phpt +++ b/tests/Utils/Strings.trim().phpt @@ -11,11 +11,11 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -Assert::same('x', Strings::trim(" \t\n\r\x00\x0B\xC2\xA0x")); -Assert::same('a b', Strings::trim(' a b ')); -Assert::same(' a b ', Strings::trim(' a b ', '')); -Assert::same('e', Strings::trim("\xc5\x98e-", "\xc5\x98-")); // Ře- +Assert::same('x', Strings::trim(" \t\n\r\x00\x0B\xC2\xA0x")); +Assert::same('a b', Strings::trim(' a b ')); +Assert::same(' a b ', Strings::trim(' a b ', '')); +Assert::same('e', Strings::trim("\xc5\x98e-", "\xc5\x98-")); // Ře- Assert::exception(function () { Strings::trim("\xC2x\xA0"); -}, Nette\Utils\RegexpException::class, NULL); +}, Nette\Utils\RegexpException::class, null); diff --git a/tests/Utils/Strings.webalize().phpt b/tests/Utils/Strings.webalize().phpt index dfc516448..5bb682652 100644 --- a/tests/Utils/Strings.webalize().phpt +++ b/tests/Utils/Strings.webalize().phpt @@ -12,6 +12,6 @@ require __DIR__ . '/../bootstrap.php'; Assert::same('zlutoucky-kun-oooo', Strings::webalize("&\xc5\xbdLU\xc5\xa4OU\xc4\x8cK\xc3\x9d K\xc5\xae\xc5\x87 \xc3\xb6\xc5\x91\xc3\xb4o!")); // &ŽLUŤOUČKÝ KŮŇ öőôo! -Assert::same('ZLUTOUCKY-KUN-oooo', Strings::webalize("&\xc5\xbdLU\xc5\xa4OU\xc4\x8cK\xc3\x9d K\xc5\xae\xc5\x87 \xc3\xb6\xc5\x91\xc3\xb4o!", NULL, FALSE)); // &ŽLUŤOUČKÝ KŮŇ öőôo! -Assert::same('1-4-!', Strings::webalize("\xc2\xBC !", '!')); +Assert::same('ZLUTOUCKY-KUN-oooo', Strings::webalize("&\xc5\xbdLU\xc5\xa4OU\xc4\x8cK\xc3\x9d K\xc5\xae\xc5\x87 \xc3\xb6\xc5\x91\xc3\xb4o!", null, false)); // &ŽLUŤOUČKÝ KŮŇ öőôo! +Assert::same('1-4-!', Strings::webalize("\xc2\xBC !", '!')); Assert::same('a-b', Strings::webalize("a\xC2\xA0b")); // non-breaking space diff --git a/tests/Utils/Validators.assert().phpt b/tests/Utils/Validators.assert().phpt index bd647b11c..ab40392c0 100644 --- a/tests/Utils/Validators.assert().phpt +++ b/tests/Utils/Validators.assert().phpt @@ -12,7 +12,7 @@ require __DIR__ . '/../bootstrap.php'; Assert::exception(function () { - Validators::assert(TRUE, 'int'); + Validators::assert(true, 'int'); }, Nette\Utils\AssertionException::class, 'The variable expects to be int, boolean given.'); Assert::exception(function () { diff --git a/tests/Utils/Validators.assertField().phpt b/tests/Utils/Validators.assertField().phpt index 9e5729fdf..c44541d1e 100644 --- a/tests/Utils/Validators.assertField().phpt +++ b/tests/Utils/Validators.assertField().phpt @@ -11,10 +11,10 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -$arr = ['first' => TRUE]; +$arr = ['first' => true]; Assert::exception(function () use ($arr) { - Validators::assertField(NULL, 'foo', 'foo'); + Validators::assertField(null, 'foo', 'foo'); }, Nette\Utils\AssertionException::class, 'The first argument expects to be array, NULL given.'); Assert::exception(function () use ($arr) { diff --git a/tests/Utils/Validators.everyIs().phpt b/tests/Utils/Validators.everyIs().phpt index 43a60b429..9fbac0268 100644 --- a/tests/Utils/Validators.everyIs().phpt +++ b/tests/Utils/Validators.everyIs().phpt @@ -12,7 +12,9 @@ require __DIR__ . '/../bootstrap.php'; test(function () { - class Abc {} + class Abc + { + } Assert::true(Validators::everyIs([], 'int')); Assert::true(Validators::everyIs(new ArrayIterator([]), 'int')); diff --git a/tests/Utils/Validators.is().phpt b/tests/Utils/Validators.is().phpt index 4ac43950a..0c2a58953 100644 --- a/tests/Utils/Validators.is().phpt +++ b/tests/Utils/Validators.is().phpt @@ -12,7 +12,7 @@ require __DIR__ . '/../bootstrap.php'; test(function () { - Assert::false(Validators::is(TRUE, 'int')); + Assert::false(Validators::is(true, 'int')); Assert::false(Validators::is('1', 'int')); Assert::true(Validators::is(1, 'integer')); Assert::true(Validators::is(1, 'int')); @@ -32,7 +32,7 @@ test(function () { test(function () { - Assert::false(Validators::is(TRUE, 'float')); + Assert::false(Validators::is(true, 'float')); Assert::false(Validators::is('1', 'float')); Assert::false(Validators::is(1, 'float')); Assert::true(Validators::is(1.0, 'float')); @@ -40,7 +40,7 @@ test(function () { test(function () { - Assert::false(Validators::is(TRUE, 'number')); + Assert::false(Validators::is(true, 'number')); Assert::false(Validators::is('1', 'number')); Assert::true(Validators::is(1, 'number')); Assert::true(Validators::is(1.0, 'number')); @@ -48,7 +48,7 @@ test(function () { test(function () { - Assert::false(Validators::is(TRUE, 'numeric')); + Assert::false(Validators::is(true, 'numeric')); Assert::true(Validators::is('1', 'numeric')); Assert::true(Validators::is('-1', 'numeric')); Assert::true(Validators::is('-1.5', 'numeric')); @@ -60,7 +60,7 @@ test(function () { test(function () { - Assert::false(Validators::is(TRUE, 'numericint')); + Assert::false(Validators::is(true, 'numericint')); Assert::true(Validators::is('1', 'numericint')); Assert::true(Validators::is('-1', 'numericint')); Assert::false(Validators::is('-1.5', 'numericint')); @@ -73,14 +73,14 @@ test(function () { test(function () { Assert::false(Validators::is(1, 'bool')); - Assert::true(Validators::is(TRUE, 'bool')); - Assert::true(Validators::is(FALSE, 'bool')); - Assert::true(Validators::is(TRUE, 'boolean')); - Assert::true(Validators::is(TRUE, 'bool:1')); - Assert::false(Validators::is(TRUE, 'bool:0')); - Assert::false(Validators::is(FALSE, 'bool:1')); - Assert::true(Validators::is(FALSE, 'bool:0')); - Assert::true(Validators::is(FALSE, 'bool:0..1')); + Assert::true(Validators::is(true, 'bool')); + Assert::true(Validators::is(false, 'bool')); + Assert::true(Validators::is(true, 'boolean')); + Assert::true(Validators::is(true, 'bool:1')); + Assert::false(Validators::is(true, 'bool:0')); + Assert::false(Validators::is(false, 'bool:1')); + Assert::true(Validators::is(false, 'bool:0')); + Assert::true(Validators::is(false, 'bool:0..1')); }); @@ -108,7 +108,7 @@ test(function () { test(function () { - Assert::false(Validators::is(NULL, 'array')); + Assert::false(Validators::is(null, 'array')); Assert::true(Validators::is([], 'array')); Assert::true(Validators::is([], 'array:0')); Assert::true(Validators::is([1], 'array:1')); @@ -118,7 +118,7 @@ test(function () { test(function () { - Assert::false(Validators::is(NULL, 'list')); + Assert::false(Validators::is(null, 'list')); Assert::true(Validators::is([], 'list')); Assert::true(Validators::is([1], 'list')); Assert::true(Validators::is(['a', 'b', 'c'], 'list')); @@ -133,20 +133,20 @@ test(function () { test(function () { - Assert::false(Validators::is(NULL, 'object')); + Assert::false(Validators::is(null, 'object')); Assert::true(Validators::is(new stdClass, 'object')); }); test(function () { - Assert::false(Validators::is(NULL, 'scalar')); + Assert::false(Validators::is(null, 'scalar')); Assert::false(Validators::is([], 'scalar')); Assert::true(Validators::is(1, 'scalar')); }); test(function () { - Assert::false(Validators::is(NULL, 'callable')); + Assert::false(Validators::is(null, 'callable')); Assert::false(Validators::is([], 'callable')); Assert::false(Validators::is(1, 'callable')); Assert::false(Validators::is('', 'callable')); @@ -158,7 +158,7 @@ test(function () { test(function () { Assert::false(Validators::is(0, 'null')); - Assert::true(Validators::is(NULL, 'null')); + Assert::true(Validators::is(null, 'null')); }); @@ -222,8 +222,8 @@ test(function () { test(function () { Assert::true(Validators::is(0, 'none')); Assert::true(Validators::is('', 'none')); - Assert::true(Validators::is(NULL, 'none')); - Assert::true(Validators::is(FALSE, 'none')); + Assert::true(Validators::is(null, 'none')); + Assert::true(Validators::is(false, 'none')); Assert::false(Validators::is('0', 'none')); Assert::true(Validators::is([], 'none')); }); @@ -297,8 +297,12 @@ test(function () { test(function () { - class rimmer {} - interface kryton { } + class rimmer + { + } + interface kryton + { + } Assert::true(Validators::is('rimmer', 'type')); Assert::true(Validators::is('kryton', 'type')); @@ -333,7 +337,9 @@ test(function () { test(function () { - class Abc {} + class Abc + { + } Assert::true(Validators::is([], 'int[]')); Assert::true(Validators::is(new ArrayIterator([]), 'int[]')); diff --git a/tests/Utils/Validators.isInRange().phpt b/tests/Utils/Validators.isInRange().phpt index 662a4b7c8..74c901e00 100644 --- a/tests/Utils/Validators.isInRange().phpt +++ b/tests/Utils/Validators.isInRange().phpt @@ -22,18 +22,18 @@ Assert::false(Validators::isInRange(2.5, [-1, 1])); Assert::true(Validators::isInRange('a', ['a', 'z'])); Assert::false(Validators::isInRange('A', ['a', 'z'])); -Assert::true(Validators::isInRange(-1, [NULL, 2])); +Assert::true(Validators::isInRange(-1, [null, 2])); Assert::true(Validators::isInRange(-1, ['', 2])); -Assert::true(Validators::isInRange(1, [-1, NULL])); +Assert::true(Validators::isInRange(1, [-1, null])); Assert::false(Validators::isInRange(1, [-1, ''])); -Assert::false(Validators::isInRange(0, [NULL, NULL])); -Assert::false(Validators::isInRange('', [NULL, NULL])); -Assert::false(Validators::isInRange(10, [NULL, NULL])); +Assert::false(Validators::isInRange(0, [null, null])); +Assert::false(Validators::isInRange('', [null, null])); +Assert::false(Validators::isInRange(10, [null, null])); -Assert::false(Validators::isInRange(NULL, [0, 1])); -Assert::false(Validators::isInRange(NULL, ['0', 'b'])); +Assert::false(Validators::isInRange(null, [0, 1])); +Assert::false(Validators::isInRange(null, ['0', 'b'])); Assert::true(Validators::isInRange('', ['', ''])); Assert::true(Validators::isInRange('', ['', 'b'])); @@ -41,13 +41,13 @@ Assert::false(Validators::isInRange('', ['a', 'b'])); Assert::false(Validators::isInRange('', [0, 1])); Assert::false(Validators::isInRange('', [0, 1])); -Assert::false(Validators::isInRange('a', [1, NULL])); -Assert::false(Validators::isInRange('a', [NULL, 9])); -Assert::true(Validators::isInRange('1', [NULL, 9])); -Assert::false(Validators::isInRange(10, ['a', NULL])); -Assert::true(Validators::isInRange(10, [NULL, 'a'])); +Assert::false(Validators::isInRange('a', [1, null])); +Assert::false(Validators::isInRange('a', [null, 9])); +Assert::true(Validators::isInRange('1', [null, 9])); +Assert::false(Validators::isInRange(10, ['a', null])); +Assert::true(Validators::isInRange(10, [null, 'a'])); Assert::false(Validators::isInRange(new DateTimeImmutable('2017-04-26'), [new DateTime('2017-04-20'), new DateTime('2017-04-23')])); Assert::true(Validators::isInRange(new DateTimeImmutable('2017-04-26'), [new DateTime('2017-04-20'), new DateTime('2017-04-30')])); -Assert::false(Validators::isInRange(new DateTimeImmutable('2017-04-26'), [10, NULL])); -Assert::false(Validators::isInRange(new DateTimeImmutable('2017-04-26'), [NULL, 10])); +Assert::false(Validators::isInRange(new DateTimeImmutable('2017-04-26'), [10, null])); +Assert::false(Validators::isInRange(new DateTimeImmutable('2017-04-26'), [null, 10])); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 315682a6e..773372c34 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -28,8 +28,16 @@ function test(\Closure $function) class RemoteStream /* extends \streamWrapper */ { - public function stream_open() { return TRUE; } - public function url_stat() { return FALSE; } + public function stream_open() + { + return true; + } + + + public function url_stat() + { + return false; + } } stream_wrapper_register('remote', RemoteStream::class, STREAM_IS_URL);