Skip to content

Commit

Permalink
used PHP 7.1 features
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Aug 5, 2019
1 parent 904b1d7 commit 86fa4d8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 19 deletions.
8 changes: 3 additions & 5 deletions src/Iterators/Filter.php
Expand Up @@ -9,8 +9,6 @@


namespace Nette\Iterators; namespace Nette\Iterators;


use Nette;



/** /**
* CallbackFilterIterator for PHP < 5.4. * CallbackFilterIterator for PHP < 5.4.
Expand All @@ -22,16 +20,16 @@ class Filter extends \FilterIterator
protected $callback; protected $callback;




public function __construct(\Iterator $iterator, $callback) public function __construct(\Iterator $iterator, callable $callback)
{ {
trigger_error(__CLASS__ . ' is deprecated, use CallbackFilterIterator.', E_USER_WARNING); trigger_error(__CLASS__ . ' is deprecated, use CallbackFilterIterator.', E_USER_WARNING);
parent::__construct($iterator); parent::__construct($iterator);
$this->callback = Nette\Utils\Callback::check($callback); $this->callback = $callback;
} }




public function accept() public function accept()
{ {
return call_user_func($this->callback, $this->current(), $this->key(), $this); return ($this->callback)($this->current(), $this->key(), $this);
} }
} }
2 changes: 1 addition & 1 deletion src/Iterators/RecursiveFilter.php
Expand Up @@ -16,7 +16,7 @@
*/ */
class RecursiveFilter extends Filter implements \RecursiveIterator class RecursiveFilter extends Filter implements \RecursiveIterator
{ {
public function __construct(\RecursiveIterator $iterator, $callback) public function __construct(\RecursiveIterator $iterator, callable $callback)
{ {
trigger_error(__CLASS__ . ' is deprecated, use RecursiveCallbackFilterIterator.', E_USER_WARNING); trigger_error(__CLASS__ . ' is deprecated, use RecursiveCallbackFilterIterator.', E_USER_WARNING);
parent::__construct($iterator, $callback); parent::__construct($iterator, $callback);
Expand Down
8 changes: 2 additions & 6 deletions src/Loaders/NetteLoader.php
Expand Up @@ -39,21 +39,17 @@ public static function getInstance()


/** /**
* Register autoloader. * Register autoloader.
* @param bool prepend autoloader?
* @return void
*/ */
public function register($prepend = false) public function register(bool $prepend = false): void
{ {
spl_autoload_register([$this, 'tryLoad'], true, (bool) $prepend); spl_autoload_register([$this, 'tryLoad'], true, (bool) $prepend);
} }




/** /**
* Handles autoloading of classes or interfaces. * Handles autoloading of classes or interfaces.
* @param string
* @return void
*/ */
public function tryLoad($type) public function tryLoad(string $type): void
{ {
$type = ltrim($type, '\\'); $type = ltrim($type, '\\');
if (isset($this->list[$type])) { if (isset($this->list[$type])) {
Expand Down
9 changes: 2 additions & 7 deletions src/Utils/MimeTypeDetector.php
Expand Up @@ -19,7 +19,6 @@
*/ */
class MimeTypeDetector class MimeTypeDetector
{ {

/** /**
* Static class - cannot be instantiated. * Static class - cannot be instantiated.
*/ */
Expand All @@ -31,10 +30,8 @@ final public function __construct()


/** /**
* Returns the MIME content type of file. * Returns the MIME content type of file.
* @param string
* @return string
*/ */
public static function fromFile($file) public static function fromFile(string $file): string
{ {
trigger_error(__METHOD__ . '() is deprecated; use finfo_file() instead.', E_USER_DEPRECATED); trigger_error(__METHOD__ . '() is deprecated; use finfo_file() instead.', E_USER_DEPRECATED);
if (!is_file($file)) { if (!is_file($file)) {
Expand All @@ -47,10 +44,8 @@ public static function fromFile($file)


/** /**
* Returns the MIME content type of file. * Returns the MIME content type of file.
* @param string
* @return string
*/ */
public static function fromString($data) public static function fromString(string $data): string
{ {
trigger_error(__METHOD__ . '() is deprecated; use finfo_buffer() instead.', E_USER_DEPRECATED); trigger_error(__METHOD__ . '() is deprecated; use finfo_buffer() instead.', E_USER_DEPRECATED);
$type = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $data); $type = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $data);
Expand Down

0 comments on commit 86fa4d8

Please sign in to comment.