Skip to content

Commit 8ba25f0

Browse files
committed
added PHP 7.1 type hints
1 parent 8bff562 commit 8ba25f0

File tree

13 files changed

+49
-92
lines changed

13 files changed

+49
-92
lines changed

src/Iterators/CachingIterator.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,8 @@ public function count(): int
125125

126126
/**
127127
* Forwards to the next element.
128-
* @return void
129128
*/
130-
public function next()
129+
public function next(): void
131130
{
132131
parent::next();
133132
if (parent::valid()) {
@@ -138,9 +137,8 @@ public function next()
138137

139138
/**
140139
* Rewinds the Iterator.
141-
* @return void
142140
*/
143-
public function rewind()
141+
public function rewind(): void
144142
{
145143
parent::rewind();
146144
$this->counter = parent::valid() ? 1 : 0;

src/Utils/ArrayHash.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ public function count(): int
5555

5656
/**
5757
* Replaces or appends a item.
58-
* @return void
5958
*/
60-
public function offsetSet($key, $value)
59+
public function offsetSet($key, $value): void
6160
{
6261
if (!is_scalar($key)) { // prevents null
6362
throw new Nette\InvalidArgumentException(sprintf('Key must be either a string or an integer, %s given.', gettype($key)));
@@ -87,9 +86,8 @@ public function offsetExists($key): bool
8786

8887
/**
8988
* Removes the element from this list.
90-
* @return void
9189
*/
92-
public function offsetUnset($key)
90+
public function offsetUnset($key): void
9391
{
9492
unset($this->$key);
9593
}

src/Utils/ArrayList.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@ public function count(): int
4343
/**
4444
* Replaces or appends a item.
4545
* @param int|null
46-
* @return void
4746
* @throws Nette\OutOfRangeException
4847
*/
49-
public function offsetSet($index, $value)
48+
public function offsetSet($index, $value): void
5049
{
5150
if ($index === null) {
5251
$this->list[] = $value;
@@ -88,10 +87,9 @@ public function offsetExists($index): bool
8887
/**
8988
* Removes the element at the specified position in this list.
9089
* @param int
91-
* @return void
9290
* @throws Nette\OutOfRangeException
9391
*/
94-
public function offsetUnset($index)
92+
public function offsetUnset($index): void
9593
{
9694
if (!is_int($index) || $index < 0 || $index >= count($this->list)) {
9795
throw new Nette\OutOfRangeException('Offset invalid or out of range');
@@ -102,9 +100,8 @@ public function offsetUnset($index)
102100

103101
/**
104102
* Prepends a item.
105-
* @return void
106103
*/
107-
public function prepend($value)
104+
public function prepend($value): void
108105
{
109106
$first = array_slice($this->list, 0, 1);
110107
$this->offsetSet(0, $value);

src/Utils/Arrays.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public static function mergeTree(array $arr1, array $arr2): array
8080
* Searches the array for a given key and returns the offset if successful.
8181
* @return int|null offset if it is found, null otherwise
8282
*/
83-
public static function searchKey(array $arr, $key)
83+
public static function searchKey(array $arr, $key): ?int
8484
{
8585
$foo = [$key => null];
8686
return ($tmp = array_search(key($foo), array_keys($arr), true)) === false ? null : $tmp;
@@ -89,9 +89,8 @@ public static function searchKey(array $arr, $key)
8989

9090
/**
9191
* Inserts new array before item specified by key.
92-
* @return void
9392
*/
94-
public static function insertBefore(array &$arr, $key, array $inserted)
93+
public static function insertBefore(array &$arr, $key, array $inserted): void
9594
{
9695
$offset = (int) self::searchKey($arr, $key);
9796
$arr = array_slice($arr, 0, $offset, true) + $inserted + array_slice($arr, $offset, count($arr), true);
@@ -100,9 +99,8 @@ public static function insertBefore(array &$arr, $key, array $inserted)
10099

101100
/**
102101
* Inserts new array after item specified by key.
103-
* @return void
104102
*/
105-
public static function insertAfter(array &$arr, $key, array $inserted)
103+
public static function insertAfter(array &$arr, $key, array $inserted): void
106104
{
107105
$offset = self::searchKey($arr, $key);
108106
$offset = $offset === null ? count($arr) : $offset + 1;
@@ -112,9 +110,8 @@ public static function insertAfter(array &$arr, $key, array $inserted)
112110

113111
/**
114112
* Renames key in array.
115-
* @return void
116113
*/
117-
public static function renameKey(array &$arr, $oldKey, $newKey)
114+
public static function renameKey(array &$arr, $oldKey, $newKey): void
118115
{
119116
$offset = self::searchKey($arr, $oldKey);
120117
if ($offset !== null) {

src/Utils/FileSystem.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ final class FileSystem
2121

2222
/**
2323
* Creates a directory.
24-
* @return void
2524
* @throws Nette\IOException
2625
*/
27-
public static function createDir(string $dir, int $mode = 0777)
26+
public static function createDir(string $dir, int $mode = 0777): void
2827
{
2928
if (!is_dir($dir) && !@mkdir($dir, $mode, true) && !is_dir($dir)) { // @ - dir may already exist
3029
throw new Nette\IOException("Unable to create directory '$dir'. " . error_get_last()['message']);
@@ -34,10 +33,9 @@ public static function createDir(string $dir, int $mode = 0777)
3433

3534
/**
3635
* Copies a file or directory.
37-
* @return void
3836
* @throws Nette\IOException
3937
*/
40-
public static function copy(string $source, string $dest, bool $overwrite = true)
38+
public static function copy(string $source, string $dest, bool $overwrite = true): void
4139
{
4240
if (stream_is_local($source) && !file_exists($source)) {
4341
throw new Nette\IOException("File or directory '$source' not found.");
@@ -69,10 +67,9 @@ public static function copy(string $source, string $dest, bool $overwrite = true
6967

7068
/**
7169
* Deletes a file or directory.
72-
* @return void
7370
* @throws Nette\IOException
7471
*/
75-
public static function delete(string $path)
72+
public static function delete(string $path): void
7673
{
7774
if (is_file($path) || is_link($path)) {
7875
$func = DIRECTORY_SEPARATOR === '\\' && is_dir($path) ? 'rmdir' : 'unlink';
@@ -93,11 +90,10 @@ public static function delete(string $path)
9390

9491
/**
9592
* Renames a file or directory.
96-
* @return void
9793
* @throws Nette\IOException
9894
* @throws Nette\InvalidStateException if the target file or directory already exist
9995
*/
100-
public static function rename(string $name, string $newName, bool $overwrite = true)
96+
public static function rename(string $name, string $newName, bool $overwrite = true): void
10197
{
10298
if (!$overwrite && file_exists($newName)) {
10399
throw new Nette\InvalidStateException("File or directory '$newName' already exists.");
@@ -131,11 +127,9 @@ public static function read(string $file): string
131127

132128
/**
133129
* Writes a string to a file.
134-
* @param int|null $mode
135-
* @return void
136130
* @throws Nette\IOException
137131
*/
138-
public static function write(string $file, string $content, $mode = 0666)
132+
public static function write(string $file, string $content, ?int $mode = 0666): void
139133
{
140134
static::createDir(dirname($file));
141135
if (@file_put_contents($file, $content) === false) { // @ is escalated to exception

src/Utils/Html.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,8 @@ public function removeAttribute(string $name)
178178

179179
/**
180180
* Overloaded setter for element's attribute.
181-
* @return void
182181
*/
183-
final public function __set(string $name, $value)
182+
final public function __set(string $name, $value): void
184183
{
185184
$this->attrs[$name] = $value;
186185
}
@@ -207,9 +206,8 @@ final public function __isset(string $name): bool
207206

208207
/**
209208
* Overloaded unsetter for element's attribute.
210-
* @return void
211209
*/
212-
final public function __unset(string $name)
210+
final public function __unset(string $name): void
213211
{
214212
unset($this->attrs[$name]);
215213
}
@@ -394,9 +392,8 @@ public function insert(int $index = null, $child, bool $replace = false)
394392
* Inserts (replaces) child node (\ArrayAccess implementation).
395393
* @param int|null position or null for appending
396394
* @param Html|string Html node or raw HTML string
397-
* @return void
398395
*/
399-
final public function offsetSet($index, $child)
396+
final public function offsetSet($index, $child): void
400397
{
401398
$this->insert($index, $child, true);
402399
}
@@ -426,9 +423,8 @@ final public function offsetExists($index): bool
426423
/**
427424
* Removes child node (\ArrayAccess implementation).
428425
* @param int
429-
* @return void
430426
*/
431-
public function offsetUnset($index)
427+
public function offsetUnset($index): void
432428
{
433429
if (isset($this->children[$index])) {
434430
array_splice($this->children, (int) $index, 1);
@@ -447,9 +443,8 @@ final public function count(): int
447443

448444
/**
449445
* Removes all children.
450-
* @return void
451446
*/
452-
public function removeChildren()
447+
public function removeChildren(): void
453448
{
454449
$this->children = [];
455450
}

src/Utils/Image.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,10 +481,9 @@ public function place(self $image, $left = 0, $top = 0, int $opacity = 100)
481481

482482
/**
483483
* Saves image to the file. Quality is 0..100 for JPEG and WEBP, 0..9 for PNG.
484-
* @return void
485484
* @throws ImageException
486485
*/
487-
public function save(string $file = null, int $quality = null, int $type = null)
486+
public function save(string $file = null, int $quality = null, int $type = null): void
488487
{
489488
if ($type === null) {
490489
$extensions = array_flip(self::$formats) + ['jpg' => self::JPEG];
@@ -553,10 +552,9 @@ public function __toString(): string
553552

554553
/**
555554
* Outputs image to browser. Quality is 0..100 for JPEG and WEBP, 0..9 for PNG.
556-
* @return void
557555
* @throws ImageException
558556
*/
559-
public function send(int $type = self::JPEG, int $quality = null)
557+
public function send(int $type = self::JPEG, int $quality = null): void
560558
{
561559
if (!isset(self::$formats[$type])) {
562560
throw new Nette\InvalidArgumentException("Unsupported image type '$type'.");

src/Utils/ObjectHelpers.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ final class ObjectHelpers
2323
/**
2424
* @throws MemberAccessException
2525
*/
26-
public static function strictGet(string $class, string $name)
26+
public static function strictGet(string $class, string $name): void
2727
{
2828
$rc = new \ReflectionClass($class);
2929
$hint = self::getSuggestion(array_merge(
@@ -37,7 +37,7 @@ public static function strictGet(string $class, string $name)
3737
/**
3838
* @throws MemberAccessException
3939
*/
40-
public static function strictSet(string $class, string $name)
40+
public static function strictSet(string $class, string $name): void
4141
{
4242
$rc = new \ReflectionClass($class);
4343
$hint = self::getSuggestion(array_merge(
@@ -51,7 +51,7 @@ public static function strictSet(string $class, string $name)
5151
/**
5252
* @throws MemberAccessException
5353
*/
54-
public static function strictCall(string $class, string $method, array $additionalMethods = [])
54+
public static function strictCall(string $class, string $method, array $additionalMethods = []): void
5555
{
5656
$hint = self::getSuggestion(array_merge(
5757
get_class_methods($class),
@@ -69,7 +69,7 @@ public static function strictCall(string $class, string $method, array $addition
6969
/**
7070
* @throws MemberAccessException
7171
*/
72-
public static function strictStaticCall(string $class, string $method)
72+
public static function strictStaticCall(string $class, string $method): void
7373
{
7474
$hint = self::getSuggestion(
7575
array_filter((new \ReflectionClass($class))->getMethods(\ReflectionMethod::IS_PUBLIC), function ($m) { return $m->isStatic(); }),
@@ -126,10 +126,9 @@ public static function getMagicProperties(string $class): array
126126

127127
/**
128128
* Finds the best suggestion (for 8-bit encoding).
129-
* @return string|null
130129
* @internal
131130
*/
132-
public static function getSuggestion(array $possibilities, string $value)
131+
public static function getSuggestion(array $possibilities, string $value): ?string
133132
{
134133
$norm = preg_replace($re = '#^(get|set|has|is|add)(?=[A-Z])#', '', $value);
135134
$best = null;

src/Utils/ObjectMixin.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,9 @@ public static function &get($_this, string $name)
135135
/**
136136
* __set() implementation.
137137
* @param object
138-
* @return void
139138
* @throws MemberAccessException if the property is not defined or is read-only
140139
*/
141-
public static function set($_this, string $name, $value)
140+
public static function set($_this, string $name, $value): void
142141
{
143142
$class = get_class($_this);
144143
$uname = ucfirst($name);
@@ -165,10 +164,9 @@ public static function set($_this, string $name, $value)
165164
/**
166165
* __unset() implementation.
167166
* @param object
168-
* @return void
169167
* @throws MemberAccessException
170168
*/
171-
public static function remove($_this, string $name)
169+
public static function remove($_this, string $name): void
172170
{
173171
$class = get_class($_this);
174172
if (!ObjectHelpers::hasProperty($class, $name)) {
@@ -301,9 +299,8 @@ public static function checkType(&$val, string $type): bool
301299

302300
/**
303301
* Adds a method to class.
304-
* @return void
305302
*/
306-
public static function setExtensionMethod(string $class, string $name, /*callable*/ $callback)
303+
public static function setExtensionMethod(string $class, string $name, /*callable*/ $callback): void
307304
{
308305
$name = strtolower($name);
309306
self::$extMethods[$name][$class] = Callback::check($callback);
@@ -379,10 +376,7 @@ private static function getSource()
379376
/********************* moved to ObjectHelpers ****************d*g**/
380377

381378

382-
/**
383-
* @return string|null
384-
*/
385-
public static function getSuggestion(array $possibilities, string $value)
379+
public static function getSuggestion(array $possibilities, string $value): ?string
386380
{
387381
return ObjectHelpers::getSuggestion($possibilities, $value);
388382
}
@@ -391,7 +385,7 @@ public static function getSuggestion(array $possibilities, string $value)
391385
/**
392386
* @deprecated use ObjectHelpers::strictGet()
393387
*/
394-
public static function strictGet(string $class, string $name)
388+
public static function strictGet(string $class, string $name): void
395389
{
396390
ObjectHelpers::strictGet($class, $name);
397391
}
@@ -400,7 +394,7 @@ public static function strictGet(string $class, string $name)
400394
/**
401395
* @deprecated use ObjectHelpers::strictSet()
402396
*/
403-
public static function strictSet(string $class, string $name)
397+
public static function strictSet(string $class, string $name): void
404398
{
405399
ObjectHelpers::strictSet($class, $name);
406400
}
@@ -409,7 +403,7 @@ public static function strictSet(string $class, string $name)
409403
/**
410404
* @deprecated use ObjectHelpers::strictCall()
411405
*/
412-
public static function strictCall(string $class, string $method, array $additionalMethods = [])
406+
public static function strictCall(string $class, string $method, array $additionalMethods = []): void
413407
{
414408
ObjectHelpers::strictCall($class, $method, $additionalMethods);
415409
}
@@ -418,7 +412,7 @@ public static function strictCall(string $class, string $method, array $addition
418412
/**
419413
* @deprecated use ObjectHelpers::strictStaticCall()
420414
*/
421-
public static function strictStaticCall(string $class, string $method)
415+
public static function strictStaticCall(string $class, string $method): void
422416
{
423417
ObjectHelpers::strictStaticCall($class, $method);
424418
}

0 commit comments

Comments
 (0)