Skip to content

Commit 653e215

Browse files
committed
Merge branch '4.4' into 5.3
* 4.4: [DependencyInjection] only allow `ReflectionNamedType` for `ServiceSubscriberTrait` Fix CS
2 parents b11c84c + 0d4a2f0 commit 653e215

File tree

18 files changed

+70
-27
lines changed

18 files changed

+70
-27
lines changed

src/Symfony/Component/Console/Input/ArgvInput.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ private function parseLongOption(string $token)
134134
$name = substr($token, 2);
135135

136136
if (false !== $pos = strpos($name, '=')) {
137-
if (0 === \strlen($value = substr($name, $pos + 1))) {
137+
if ('' === $value = substr($name, $pos + 1)) {
138138
array_unshift($this->parsed, $value);
139139
}
140140
$this->addLongOption(substr($name, 0, $pos), $value);

src/Symfony/Component/Console/Output/TrimmedBufferOutput.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ class TrimmedBufferOutput extends Output
2424
private $maxLength;
2525
private $buffer = '';
2626

27-
public function __construct(int $maxLength, ?int $verbosity = self::VERBOSITY_NORMAL, bool $decorated = false, OutputFormatterInterface $formatter = null) {
27+
public function __construct(int $maxLength, ?int $verbosity = self::VERBOSITY_NORMAL, bool $decorated = false, OutputFormatterInterface $formatter = null)
28+
{
2829
if ($maxLength <= 0) {
2930
throw new InvalidArgumentException(sprintf('"%s()" expects a strictly positive maxLength. Got %d.', __METHOD__, $maxLength));
3031
}

src/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function mapViolation(ConstraintViolation $violation, FormInterface $form
5757
$match = false;
5858

5959
// Don't create a ViolationPath instance for empty property paths
60-
if (\strlen($violation->getPropertyPath()) > 0) {
60+
if ('' !== $violation->getPropertyPath()) {
6161
$violationPath = new ViolationPath($violation->getPropertyPath());
6262
$relativePath = $this->reconstructPath($violationPath, $form);
6363
}

src/Symfony/Component/HttpClient/CurlHttpClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function __construct(array $defaultOptions = [], int $maxHostConnections
9393
}
9494

9595
// HTTP/2 push crashes before curl 7.61
96-
if (!\defined('CURLMOPT_PUSHFUNCTION') || 0x073d00 > self::$curlVersion['version_number'] || !(\CURL_VERSION_HTTP2 & self::$curlVersion['features'])) {
96+
if (!\defined('CURLMOPT_PUSHFUNCTION') || 0x073D00 > self::$curlVersion['version_number'] || !(\CURL_VERSION_HTTP2 & self::$curlVersion['features'])) {
9797
return;
9898
}
9999

@@ -188,7 +188,7 @@ public function request(string $method, string $url, array $options = []): Respo
188188
$this->multi->dnsCache->evictions = [];
189189
$port = parse_url($authority, \PHP_URL_PORT) ?: ('http:' === $scheme ? 80 : 443);
190190

191-
if ($resolve && 0x072a00 > self::$curlVersion['version_number']) {
191+
if ($resolve && 0x072A00 > self::$curlVersion['version_number']) {
192192
// DNS cache removals require curl 7.42 or higher
193193
// On lower versions, we have to create a new multi handle
194194
curl_multi_close($this->multi->handle);

src/Symfony/Component/HttpFoundation/IpUtils.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public static function checkIp6(?string $requestIp, string $ip)
146146
for ($i = 1, $ceil = ceil($netmask / 16); $i <= $ceil; ++$i) {
147147
$left = $netmask - 16 * ($i - 1);
148148
$left = ($left <= 16) ? $left : 16;
149-
$mask = ~(0xffff >> $left) & 0xffff;
149+
$mask = ~(0xFFFF >> $left) & 0xFFFF;
150150
if (($bytesAddr[$i] & $mask) != ($bytesTest[$i] & $mask)) {
151151
return self::$checkedIps[$cacheKey] = false;
152152
}

src/Symfony/Component/HttpFoundation/Tests/ParameterBagTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,12 @@ public function testFilter()
168168

169169
$this->assertFalse($bag->filter('dec', '', \FILTER_VALIDATE_INT, [
170170
'flags' => \FILTER_FLAG_ALLOW_HEX,
171-
'options' => ['min_range' => 1, 'max_range' => 0xff],
171+
'options' => ['min_range' => 1, 'max_range' => 0xFF],
172172
]), '->filter() gets a value of parameter as integer between boundaries');
173173

174174
$this->assertFalse($bag->filter('hex', '', \FILTER_VALIDATE_INT, [
175175
'flags' => \FILTER_FLAG_ALLOW_HEX,
176-
'options' => ['min_range' => 1, 'max_range' => 0xff],
176+
'options' => ['min_range' => 1, 'max_range' => 0xFF],
177177
]), '->filter() gets a value of parameter as integer between boundaries');
178178

179179
$this->assertEquals(['bang'], $bag->filter('array', ''), '->filter() gets a value of parameter as an array');

src/Symfony/Component/Intl/Data/Util/RingBuffer.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ public function offsetGet($key)
6464

6565
/**
6666
* {@inheritdoc}
67-
*
68-
* @return void
6967
*/
7068
public function offsetSet($key, $value): void
7169
{
@@ -81,8 +79,6 @@ public function offsetSet($key, $value): void
8179

8280
/**
8381
* {@inheritdoc}
84-
*
85-
* @return void
8682
*/
8783
public function offsetUnset($key): void
8884
{

src/Symfony/Component/Ldap/Adapter/ExtLdap/ConnectionOptions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ final class ConnectionOptions
5252
public const X_TLS_RANDOM_FILE = 0x6009;
5353
public const X_TLS_CRLFILE = 0x6010;
5454
public const X_TLS_PACKAGE = 0x6011;
55-
public const X_TLS_CRLCHECK = 0x600b;
56-
public const X_TLS_DHFILE = 0x600e;
55+
public const X_TLS_CRLCHECK = 0x600B;
56+
public const X_TLS_DHFILE = 0x600E;
5757
public const X_SASL_MECH = 0x6100;
5858
public const X_SASL_REALM = 0x6101;
5959
public const X_SASL_AUTHCID = 0x6102;

src/Symfony/Component/Mime/Encoder/Rfc2231Encoder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function encodeString(string $string, ?string $charset = 'utf-8', int $fi
3737

3838
while (null !== $char = $charStream->read(4)) {
3939
$encodedChar = rawurlencode($char);
40-
if (0 !== \strlen($currentLine) && \strlen($currentLine.$encodedChar) > $thisLineLength) {
40+
if ('' !== $currentLine && \strlen($currentLine.$encodedChar) > $thisLineLength) {
4141
$lines[] = '';
4242
$currentLine = &$lines[$lineCount++];
4343
$thisLineLength = $maxLineLength;

src/Symfony/Component/Mime/Header/AbstractHeader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ private function tokensToString(array $tokens): string
262262
// Line longer than specified maximum or token was just a new line
263263
if (("\r\n" === $token) ||
264264
($i > 0 && \strlen($currentLine.$token) > $this->lineLength)
265-
&& 0 < \strlen($currentLine)) {
265+
&& '' !== $currentLine) {
266266
$headerLines[] = '';
267267
$currentLine = &$headerLines[$lineCount++];
268268
}

src/Symfony/Component/Process/Tests/PipeStdinInStdoutStdErrStreamSelect.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
exit(ERR_TIMEOUT);
3535
}
3636

37-
if (in_array(\STDOUT, $w) && strlen($out) > 0) {
37+
if (in_array(\STDOUT, $w) && '' !== $out) {
3838
$written = fwrite(\STDOUT, (string) $out, 32768);
3939
if (false === $written) {
4040
exit(ERR_WRITE_FAILED);
@@ -45,7 +45,7 @@
4545
$write = array_diff($write, [\STDOUT]);
4646
}
4747

48-
if (in_array(\STDERR, $w) && strlen($err) > 0) {
48+
if (in_array(\STDERR, $w) && '' !== $err) {
4949
$written = fwrite(\STDERR, (string) $err, 32768);
5050
if (false === $written) {
5151
exit(ERR_WRITE_FAILED);

src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function (\SplFileInfo $current) {
5454
});
5555

5656
foreach ($files as $file) {
57-
if (!$file->isFile() || !str_ends_with($file->getFilename(), '.php')) {
57+
if (!$file->isFile() || !str_ends_with($file->getFilename(), '.php')) {
5858
continue;
5959
}
6060

src/Symfony/Component/Routing/RouteCompiler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ private static function compilePattern(Route $route, string $pattern, bool $isHo
155155

156156
if ($isSeparator && $precedingText !== $precedingChar) {
157157
$tokens[] = ['text', substr($precedingText, 0, -\strlen($precedingChar))];
158-
} elseif (!$isSeparator && \strlen($precedingText) > 0) {
158+
} elseif (!$isSeparator && '' !== $precedingText) {
159159
$tokens[] = ['text', $precedingText];
160160
}
161161

src/Symfony/Component/Security/Http/Firewall/ContextListener.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ private function safelyUnserialize(string $serializedToken)
293293
$prevUnserializeHandler = ini_set('unserialize_callback_func', __CLASS__.'::handleUnserializeCallback');
294294
$prevErrorHandler = set_error_handler(function ($type, $msg, $file, $line, $context = []) use (&$prevErrorHandler) {
295295
if (__FILE__ === $file) {
296-
throw new \ErrorException($msg, 0x37313bc, $type, $file, $line);
296+
throw new \ErrorException($msg, 0x37313BC, $type, $file, $line);
297297
}
298298

299299
return $prevErrorHandler ? $prevErrorHandler($type, $msg, $file, $line, $context) : false;
@@ -306,7 +306,7 @@ private function safelyUnserialize(string $serializedToken)
306306
restore_error_handler();
307307
ini_set('unserialize_callback_func', $prevUnserializeHandler);
308308
if ($e) {
309-
if (!$e instanceof \ErrorException || 0x37313bc !== $e->getCode()) {
309+
if (!$e instanceof \ErrorException || 0x37313BC !== $e->getCode()) {
310310
throw $e;
311311
}
312312
if ($this->logger) {
@@ -322,7 +322,7 @@ private function safelyUnserialize(string $serializedToken)
322322
*/
323323
public static function handleUnserializeCallback(string $class)
324324
{
325-
throw new \ErrorException('Class not found: '.$class, 0x37313bc);
325+
throw new \ErrorException('Class not found: '.$class, 0x37313BC);
326326
}
327327

328328
public function setRememberMeServices(RememberMeServicesInterface $rememberMeServices)

src/Symfony/Component/Translation/Loader/MoFileLoader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ class MoFileLoader extends FileLoader
2222
* Magic used for validating the format of an MO file as well as
2323
* detecting if the machine used to create that file was little endian.
2424
*/
25-
public const MO_LITTLE_ENDIAN_MAGIC = 0x950412de;
25+
public const MO_LITTLE_ENDIAN_MAGIC = 0x950412DE;
2626

2727
/**
2828
* Magic used for validating the format of an MO file as well as
2929
* detecting if the machine used to create that file was big endian.
3030
*/
31-
public const MO_BIG_ENDIAN_MAGIC = 0xde120495;
31+
public const MO_BIG_ENDIAN_MAGIC = 0xDE120495;
3232

3333
/**
3434
* The size of the header of an MO file in bytes.

src/Symfony/Contracts/Service/ServiceSubscriberTrait.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,19 @@ public static function getSubscribedServices(): array
4242
continue;
4343
}
4444

45-
if (self::class === $method->getDeclaringClass()->name && ($returnType = $method->getReturnType()) && !$returnType->isBuiltin()) {
46-
$services[self::class.'::'.$method->name] = '?'.($returnType instanceof \ReflectionNamedType ? $returnType->getName() : $returnType);
45+
if (self::class !== $method->getDeclaringClass()->name) {
46+
continue;
47+
}
48+
49+
if (!($returnType = $method->getReturnType()) instanceof \ReflectionNamedType) {
50+
continue;
4751
}
52+
53+
if ($returnType->isBuiltin()) {
54+
continue;
55+
}
56+
57+
$services[self::class.'::'.$method->name] = '?'.$returnType->getName();
4858
}
4959

5060
return $services;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Symfony\Contracts\Tests\Fixtures;
4+
5+
use Symfony\Contracts\Service\ServiceSubscriberTrait;
6+
7+
class TestServiceSubscriberUnion
8+
{
9+
use ServiceSubscriberTrait;
10+
11+
private function method1(): Service1
12+
{
13+
return $this->container->get(__METHOD__);
14+
}
15+
16+
private function method2(): Service1|Service2
17+
{
18+
return $this->container->get(__METHOD__);
19+
}
20+
21+
private function method3(): Service1|Service2|null
22+
{
23+
return $this->container->get(__METHOD__);
24+
}
25+
}

src/Symfony/Contracts/Tests/Service/ServiceSubscriberTraitTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Contracts\Service\ServiceLocatorTrait;
1717
use Symfony\Contracts\Service\ServiceSubscriberInterface;
1818
use Symfony\Contracts\Service\ServiceSubscriberTrait;
19+
use Symfony\Contracts\Tests\Fixtures\TestServiceSubscriberUnion;
1920

2021
class ServiceSubscriberTraitTest extends TestCase
2122
{
@@ -34,6 +35,16 @@ public function testSetContainerIsCalledOnParent()
3435

3536
$this->assertSame($container, (new TestService())->setContainer($container));
3637
}
38+
39+
/**
40+
* @requires PHP 8
41+
*/
42+
public function testMethodsWithUnionReturnTypesAreIgnored()
43+
{
44+
$expected = [TestServiceSubscriberUnion::class.'::method1' => '?Symfony\Contracts\Tests\Fixtures\Service1'];
45+
46+
$this->assertEquals($expected, TestServiceSubscriberUnion::getSubscribedServices());
47+
}
3748
}
3849

3950
class ParentTestService

0 commit comments

Comments
 (0)