Browse Source

Use first-class callable syntax

Corey Taylor 3 years ago
parent
commit
30171aa3cf

+ 1 - 1
src/Console/ConsoleOutput.php

@@ -222,7 +222,7 @@ class ConsoleOutput
 
         return preg_replace_callback(
             '/<(?P<tag>[a-z0-9-_]+)>(?P<text>.*?)<\/(\1)>/ims',
-            [$this, '_replaceTags'],
+            $this->_replaceTags(...),
             $text
         );
     }

+ 1 - 1
src/Database/IdentifierQuoter.php

@@ -64,7 +64,7 @@ class IdentifierQuoter
             $this->_quoteParts($query);
         }
 
-        $query->traverseExpressions([$this, 'quoteExpression']);
+        $query->traverseExpressions($this->quoteExpression(...));
         $query->setValueBinder($binder);
 
         return $query;

+ 1 - 1
src/Error/ErrorTrap.php

@@ -90,7 +90,7 @@ class ErrorTrap
     {
         $level = $this->_config['errorLevel'] ?? -1;
         error_reporting($level);
-        set_error_handler([$this, 'handleError'], $level);
+        set_error_handler($this->handleError(...), $level);
     }
 
     /**

+ 2 - 2
src/Error/ExceptionTrap.php

@@ -174,8 +174,8 @@ class ExceptionTrap
      */
     public function register(): void
     {
-        set_exception_handler([$this, 'handleException']);
-        register_shutdown_function([$this, 'handleShutdown']);
+        set_exception_handler($this->handleException(...));
+        register_shutdown_function($this->handleShutdown(...));
         static::$registeredTrap = $this;
     }
 

+ 2 - 2
src/Http/Client/Auth/Oauth.php

@@ -153,7 +153,7 @@ class Oauth
             $values['oauth_realm'] = $credentials['realm'];
         }
         $key = [$credentials['consumerSecret'], $credentials['tokenSecret']];
-        $key = array_map([$this, '_encode'], $key);
+        $key = array_map($this->_encode(...), $key);
         $key = implode('&', $key);
 
         $values['oauth_signature'] = base64_encode(
@@ -251,7 +251,7 @@ class Oauth
             $this->_normalizedUrl($request->getUri()),
             $this->_normalizedParams($request, $oauthValues),
         ];
-        $parts = array_map([$this, '_encode'], $parts);
+        $parts = array_map($this->_encode(...), $parts);
 
         return implode('&', $parts);
     }

+ 1 - 1
src/Http/Response.php

@@ -763,7 +763,7 @@ class Response implements ResponseInterface, Stringable
     public function mapType(array|string $ctype): array|string|null
     {
         if (is_array($ctype)) {
-            return array_map([$this, 'mapType'], $ctype);
+            return array_map($this->mapType(...), $ctype);
         }
 
         foreach ($this->_mimeTypes as $alias => $types) {

+ 1 - 1
src/Network/Socket.php

@@ -144,7 +144,7 @@ class Socket
         }
 
         /** @psalm-suppress InvalidArgument */
-        set_error_handler([$this, '_connectionErrorHandler']);
+        set_error_handler($this->_connectionErrorHandler(...));
         $remoteSocketTarget = $scheme . $this->_config['host'];
         $port = (int)$this->_config['port'];
         if ($port > 0) {

+ 1 - 1
src/ORM/Association/BelongsTo.php

@@ -207,7 +207,7 @@ class BelongsTo extends Association
             'bindingKey' => $this->getBindingKey(),
             'strategy' => $this->getStrategy(),
             'associationType' => $this->type(),
-            'finder' => [$this, 'find'],
+            'finder' => $this->find(...),
         ]);
 
         return $loader->buildEagerLoader($options);

+ 1 - 1
src/ORM/Association/HasMany.php

@@ -662,7 +662,7 @@ class HasMany extends Association
             'strategy' => $this->getStrategy(),
             'associationType' => $this->type(),
             'sort' => $this->getSort(),
-            'finder' => [$this, 'find'],
+            'finder' => $this->find(...),
         ]);
 
         return $loader->buildEagerLoader($options);

+ 1 - 1
src/ORM/Association/HasOne.php

@@ -150,7 +150,7 @@ class HasOne extends Association
             'bindingKey' => $this->getBindingKey(),
             'strategy' => $this->getStrategy(),
             'associationType' => $this->type(),
-            'finder' => [$this, 'find'],
+            'finder' => $this->find(...),
         ]);
 
         return $loader->buildEagerLoader($options);

+ 1 - 1
src/TestSuite/ContainerStubTrait.php

@@ -92,7 +92,7 @@ trait ContainerStubTrait
 
         $app = new $appClass(...$appArgs);
         if (!empty($this->containerServices) && $app instanceof EventDispatcherInterface) {
-            $app->getEventManager()->on('Application.buildContainer', [$this, 'modifyContainer']);
+            $app->getEventManager()->on('Application.buildContainer', $this->modifyContainer(...));
         }
 
         return $app;

+ 1 - 1
src/TestSuite/IntegrationTestTrait.php

@@ -501,7 +501,7 @@ trait IntegrationTestTrait
      */
     protected function _makeDispatcher(): MiddlewareDispatcher
     {
-        EventManager::instance()->on('Controller.initialize', [$this, 'controllerSpy']);
+        EventManager::instance()->on('Controller.initialize', $this->controllerSpy(...));
         /** @var \Cake\Core\HttpApplicationInterface $app */
         $app = $this->createApp();
 

+ 1 - 1
src/View/ViewBuilder.php

@@ -622,7 +622,7 @@ class ViewBuilder implements JsonSerializable
             $array[$property] = $this->{$property};
         }
 
-        array_walk_recursive($array['_vars'], [$this, '_checkViewVars']);
+        array_walk_recursive($array['_vars'], $this->_checkViewVars(...));
 
         return array_filter($array, function ($i) {
             return !is_array($i) && strlen((string)$i) || !empty($i);

+ 1 - 1
tests/TestCase/Event/EventManagerTest.php

@@ -518,7 +518,7 @@ class EventManagerTest extends TestCase
      */
     public function testDispatchLocalHandledByGlobal(): void
     {
-        $callback = [$this, 'onMyEvent'];
+        $callback = $this->onMyEvent(...);
         EventManager::instance()->on('my_event', $callback);
         $manager = new EventManager();
         $event = new Event('my_event', $manager);

+ 1 - 1
tests/TestCase/TestSuite/ConsoleIntegrationTestTraitTest.php

@@ -217,7 +217,7 @@ class ConsoleIntegrationTestTraitTest extends TestCase
 
         $this->exec($command);
 
-        call_user_func_array([$this, $assertion], $rest);
+        call_user_func_array($this->$assertion(...), $rest);
     }
 
     /**

+ 1 - 1
tests/TestCase/TestSuite/EmailTraitTest.php

@@ -190,7 +190,7 @@ class EmailTraitTest extends TestCase
         $this->expectException(AssertionFailedError::class);
         $this->expectExceptionMessage($expectedMessage);
 
-        call_user_func_array([$this, $assertion], $params);
+        call_user_func_array($this->$assertion(...), $params);
     }
 
     /**

+ 2 - 2
tests/TestCase/TestSuite/IntegrationTestTraitTest.php

@@ -1457,7 +1457,7 @@ class IntegrationTestTraitTest extends TestCase
 
         $this->get($url);
 
-        call_user_func_array([$this, $assertion], $rest);
+        call_user_func_array($this->$assertion(...), $rest);
     }
 
     /**
@@ -1612,7 +1612,7 @@ class IntegrationTestTraitTest extends TestCase
         $this->expectExceptionMessage('Possibly related to OutOfBoundsException: "oh no!"');
         $this->get('/posts/throw_exception');
         $this->_requestSession = new Session();
-        call_user_func_array([$this, $assertMethod], $rest);
+        call_user_func_array($this->$assertMethod(...), $rest);
     }
 
     /**

+ 2 - 2
tests/TestCase/Utility/HashTest.php

@@ -2506,7 +2506,7 @@ class HashTest extends TestCase
     {
         $data = static::articleData();
 
-        $result = Hash::map($data, '{n}.Article.id', [$this, 'mapCallback']);
+        $result = Hash::map($data, '{n}.Article.id', $this->mapCallback(...));
         $expected = [2, 4, 6, 8, 10];
         $this->assertSame($expected, $result);
     }
@@ -2529,7 +2529,7 @@ class HashTest extends TestCase
     {
         $data = static::articleData();
 
-        $result = Hash::reduce($data, '{n}.Article.id', [$this, 'reduceCallback']);
+        $result = Hash::reduce($data, '{n}.Article.id', $this->reduceCallback(...));
         $this->assertSame(15, $result);
     }
 

+ 1 - 1
tests/TestCase/Validation/ValidationRuleTest.php

@@ -81,7 +81,7 @@ class ValidationRuleTest extends TestCase
         $providers = ['default' => ''];
 
         $rule = new ValidationRule([
-            'rule' => [$this, 'willFail'],
+            'rule' => $this->willFail(...),
         ]);
         $this->assertFalse($rule->process($data, $providers, $context));
     }

+ 1 - 1
tests/test_app/TestApp/Mailer/Transport/SmtpTestTransport.php

@@ -37,6 +37,6 @@ class SmtpTestTransport extends SmtpTransport
     {
         $method = '_' . $method;
 
-        return call_user_func_array([$this, $method], $args);
+        return call_user_func_array($this->$method(...), $args);
     }
 }