10000 minor #51096 Use more "First class callable syntax" + Normalize set_e… · symfony/symfony@73e65dc · GitHub
[go: up one dir, main page]

Skip to content

Commit 73e65dc

Browse files
minor #51096 Use more "First class callable syntax" + Normalize set_error_handler/set_exception_handler calls (lyrixx)
This PR was merged into the 6.4 branch. Discussion ---------- Use more "First class callable syntax" + Normalize set_error_handler/set_exception_handler calls | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | | License | MIT | Doc PR | Commits ------- be1bbbc Use more "First class callable syntax" + Normalize set_error_handler/set_exception_handler calls
2 parents 56f01c4 + be1bbbc commit 73e65dc

File tree

11 files changed

+14
-18
lines changed

11 files changed

+14
-18
lines changed

src/Symfony/Bridge/Monolog/Handler/ServerLogHandler.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private function doHandle(array|LogRecord $record): bool
8888
return false;
8989
}
9090

91-
set_error_handler(self::class.'::nullErrorHandler');
91+
set_error_handler(static fn () => null);
9292

9393
try {
9494
if (!$this->socket = $this->socket ?: $this->createSocket()) {
@@ -105,7 +105,7 @@ private function doWrite(array|LogRecord $record): void
105105
{
106106
$recordFormatted = $this->formatRecord($record);
107107

108-
set_error_handler(self::class.'::nullErrorHandler');
108+
set_error_handler(static fn () => null);
109109

110110
try {
111111
if (-1 === stream_socket_sendto($this->socket, $recordFormatted)) {
@@ -126,10 +126,6 @@ protected function getDefaultFormatter(): FormatterInterface
126126
return new VarDumperFormatter();
127127
}
128128

129-
private static function nullErrorHandler(): void
130-
{
131-
}
132-
133129
/**
134130
* @return resource
135131
*/

src/Symfony/Bridge/Twig/Extension/HttpKernelExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function getFunctions(): array
2828
new TwigFunction('render', [HttpKernelRuntime::class, 'renderFragment'], ['is_safe' => ['html']]),
2929
new TwigFunction('render_*', [HttpKernelRuntime::class, 'renderFragmentStrategy'], ['is_safe' => ['html']]),
3030
new TwigFunction('fragment_uri', [HttpKernelRuntime::class, 'generateFragmentUri']),
31-
new TwigFunction('controller', static::class.'::controller'),
31+
new TwigFunction('controller', [self::class, 'controller']),
3232
];
3333
}
3434

src/Symfony/Component/Cache/LockRegistry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ private static function open(int $key)
154154
if (null !== $h = self::$openedFiles[$key] ?? null) {
155155
return $h;
156156
}
157-
set_error_handler(function () {});
157+
set_error_handler(static fn () => null);
158158
try {
159159
$h = fopen(self::$files[$key], 'r+');
160160
} finally {

src/Symfony/Component/Cache/Tests/Marshaller/DefaultMarshallerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function testNativeUnserializeInvalid()
8282
$this->expectException(\DomainException::class);
8383
$this->expectExceptionMessage('unserialize(): Error at offset 0 of 3 bytes');
8484
$marshaller = new DefaultMarshaller();
85-
set_error_handler(fn () => false);
85+
set_error_handler(static fn () => false);
8686
try {
8787
@$marshaller->unmarshall(':::');
8888
} finally {
@@ -102,7 +102,7 @@ public function testIgbinaryUnserializeInvalid()
102102
$this->expectException(\DomainException::class);
103103
$this->expectExceptionMessage('igbinary_unserialize_zval: unknown type \'61\', position 5');
104104
$marshaller = new DefaultMarshaller();
105-
set_error_handler(fn () => false);
105+
set_error_handler(static fn () => false);
106106
try {
107107
@$marshaller->unmarshall(rawurldecode('%00%00%00%02abc'));
108108
} finally {

src/Symfony/Component/Cache/Traits/FilesystemCommonTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ protected function doUnlink(string $file)
8787

8888
private function write(string $file, string $data, int $expiresAt = null): bool
8989
{
90-
set_error_handler(__CLASS__.'::throwError');
90+
set_error_handler(self::throwError(...));
9191
try {
9292
$tmp = $this->directory.$this->tmpSuffix ??= str_replace('/', '-', base64_encode(random_bytes(6)));
9393
try {

src/Symfony/Component/ErrorHandler/ErrorHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public static function register(self $handler = null, bool $replace = true): sel
112112
{
113113
if (null === self::$reservedMemory) {
114114
self::$reservedMemory = str_repeat('x', 32768);
115-
register_shutdown_function(__CLASS__.'::handleFatalError');
115+
register_shutdown_function(self::handleFatalError(...));
116116
}
117117

118118
if ($handlerIsNew = null === $handler) {

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ private static function box(string $func, mixed ...$args): mixed
749749
self::assertFunctionExists($func);
750750

751751
self::$lastError = null;
752-
set_error_handler(__CLASS__.'::handleError');
752+
set_error_handler(self::handleError(...));
753753
try {
754754
return $func(...$args);
755755
} finally {

src/Symfony/Component/HttpKernel/EventListener/DebugHandlersListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function configure(object $event = null): void
8585
}
8686
}
8787
if ($this->exceptionHandler) {
88-
$handler = set_exception_handler('is_int');
88+
$handler = set_exception_handler(static fn () => null);
8989
$handler = \is_array($handler) ? $handler[0] : null;
9090
restore_exception_handler();
9191

src/Symfony/Component/HttpKernel/Tests/EventListener/DebugHandlersListenerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class DebugHandlersListenerTest extends TestCase
3434
{
3535
public function testConfigure()
3636
{
37-
$userHandler = function () {};
37+
$userHandler = static fn () => null;
3838
$listener = new DebugHandlersListener($userHandler);
3939
$eHandler = new ErrorHandler();
4040

src/Symfony/Component/Routing/Matcher/Dumper/StaticPrefixCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ private function getCommonPrefix(string $prefix, string $anotherPrefix): array
147147
$baseLength = \strlen($this->prefix);
148148
$end = min(\strlen($prefix), \strlen($anotherPrefix));
149149
$staticLength = null;
150-
set_error_handler([__CLASS__, 'handleError']);
150+
set_error_handler(self::handleError(...));
151151

152152
try {
153153
for ($i = $baseLength; $i < $end && $prefix[$i] === $anotherPrefix[$i]; ++$i) {

src/Symfony/Component/VarDumper/Server/Connection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function write(Data $data): bool
6262
$context = array_filter($context);
6363
$encodedPayload = base64_encode(serialize([$data, $context]))."\n";
6464

65-
set_error_handler(fn () => true);
65+
set_error_handler(static fn () => null);
6666
try {
6767
if (-1 !== stream_socket_sendto($this->socket, $encodedPayload)) {
6868
return true;
@@ -87,7 +87,7 @@ public function write(Data $data): bool
8787
*/
8888
private function createSocket()
8989
{
90-
set_error_handler(fn () => true);
90+
set_error_handler(static fn () => null);
9191
try {
9292
return stream_socket_client($this->host, $errno, $errstr, 3) ?: null;
9393
} finally {

0 commit comments

Comments
 (0)
0