From 5a041bab8f16c88cb7f4767f2fc32434c67d1dc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Mon, 19 Jun 2017 01:41:02 +0200 Subject: [PATCH] Use callable typehint where possible + Removed dead code (#996) * Removed dead code * Use callable typehint where possible * Removed PHP5.3 workaround --- src/Monolog/Handler/ProcessableHandlerTrait.php | 3 --- src/Monolog/Handler/TestHandler.php | 6 +----- tests/Monolog/Handler/RotatingFileHandlerTest.php | 14 +++----------- 3 files changed, 4 insertions(+), 19 deletions(-) diff --git a/src/Monolog/Handler/ProcessableHandlerTrait.php b/src/Monolog/Handler/ProcessableHandlerTrait.php index d28d46bb..bba940e8 100644 --- a/src/Monolog/Handler/ProcessableHandlerTrait.php +++ b/src/Monolog/Handler/ProcessableHandlerTrait.php @@ -28,9 +28,6 @@ trait ProcessableHandlerTrait */ public function pushProcessor(callable $callback): HandlerInterface { - if (!is_callable($callback)) { - throw new \InvalidArgumentException('Processors must be valid callables (callback or object with an __invoke method), '.var_export($callback, true).' given'); - } array_unshift($this->processors, $callback); return $this; diff --git a/src/Monolog/Handler/TestHandler.php b/src/Monolog/Handler/TestHandler.php index 34bfba41..3df7b6da 100644 --- a/src/Monolog/Handler/TestHandler.php +++ b/src/Monolog/Handler/TestHandler.php @@ -109,12 +109,8 @@ class TestHandler extends AbstractProcessingHandler }, $level); } - public function hasRecordThatPasses($predicate, $level) + public function hasRecordThatPasses(callable $predicate, $level) { - if (!is_callable($predicate)) { - throw new \InvalidArgumentException("Expected a callable for hasRecordThatPasses"); - } - if (!isset($this->recordsByLevel[$level])) { return false; } diff --git a/tests/Monolog/Handler/RotatingFileHandlerTest.php b/tests/Monolog/Handler/RotatingFileHandlerTest.php index 1eb64139..be36eff6 100644 --- a/tests/Monolog/Handler/RotatingFileHandlerTest.php +++ b/tests/Monolog/Handler/RotatingFileHandlerTest.php @@ -19,13 +19,7 @@ use Monolog\Test\TestCase; */ class RotatingFileHandlerTest extends TestCase { - /** - * This var should be private but then the anonymous function - * in the `setUp` method won't be able to set it. `$this` cant't - * be used in the anonymous function in `setUp` because PHP 5.3 - * does not support it. - */ - public $lastError; + private $lastError; public function setUp() { @@ -35,10 +29,8 @@ class RotatingFileHandlerTest extends TestCase $this->markTestSkipped($dir.' must be writable to test the RotatingFileHandler.'); } $this->lastError = null; - $self = $this; - // workaround with &$self used for PHP 5.3 - set_error_handler(function ($code, $message) use (&$self) { - $self->lastError = [ + set_error_handler(function ($code, $message) { + $this->lastError = [ 'code' => $code, 'message' => $message, ];