Skip to content

Commit 650b39a

Browse files
More short closures + isset instead of null checks + etc.
1 parent fd641de commit 650b39a

File tree

68 files changed

+345
-377
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+345
-377
lines changed

.github/expected-missing-return-types.diff

Lines changed: 163 additions & 163 deletions
Large diffs are not rendered by default.

src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
use Symfony\Component\WebLink\EventListener\AddLinkHeaderListener;
4545
use Symfony\Component\WebLink\GenericLinkProvider;
4646
use Symfony\Component\WebLink\HttpHeaderSerializer;
47-
use Symfony\Component\WebLink\Link;
4847
use Symfony\Contracts\Service\Attribute\Required;
4948
use Symfony\Contracts\Service\ServiceSubscriberInterface;
5049
use Twig\Environment;
@@ -64,7 +63,7 @@ abstract class AbstractController implements ServiceSubscriberInterface
6463
#[Required]
6564
public function setContainer(ContainerInterface $container): ?ContainerInterface
6665
{
67-
$previous = $this->container;
66+
$previous = $this->container ?? null;
6867
$this->container = $container;
6968

7069
return $previous;

src/Symfony/Bundle/FrameworkBundle/Routing/Router.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function __construct(ContainerInterface $container, mixed $resource, arra
6161

6262
public function getRouteCollection(): RouteCollection
6363
{
64-
if (null === $this->collection) {
64+
if (!isset($this->collection)) {
6565
$this->collection = $this->container->get('routing.loader')->load($this->resource, $this->options['resource_type']);
6666
$this->resolveParameters($this->collection);
6767
$this->collection->addResource(new ContainerParametersResource($this->collectedParameters));

src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AccessTokenFactory.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,19 @@ public function addConfiguration(NodeDefinition $node): void
6868

6969
->beforeNormalization()
7070
->ifString()
71-
->then(static function (string $v): array { return ['id' => $v]; })
71+
->then(static fn ($v) => ['id' => $v])
7272
->end()
7373

7474
->beforeNormalization()
75-
->ifTrue(static function ($v) { return \is_array($v) && 1 < \count($v); })
76-
->then(static function () { throw new InvalidConfigurationException('You cannot configure multiple token handlers.'); })
75+
->ifTrue(static fn ($v) => \is_array($v) && 1 < \count($v))
76+
->then(static fn () => throw new InvalidConfigurationException('You cannot configure multiple token handlers.'))
7777
->end()
7878

7979
// "isRequired" must be set otherwise the following custom validation is not called
8080
->isRequired()
8181
->beforeNormalization()
82-
->ifTrue(static function ($v) { return \is_array($v) && !$v; })
83-
->then(static function () { throw new InvalidConfigurationException('You must set a token handler.'); })
82+
->ifTrue(static fn ($v) => \is_array($v) && !$v)
83+
->then(static fn () => throw new InvalidConfigurationException('You must set a token handler.'))
8484
->end()
8585

8686
->children()

src/Symfony/Component/BrowserKit/Cookie.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ class Cookie
6161
public function __construct(string $name, ?string $value, string $expires = null, string $path = null, string $domain = '', bool $secure = false, bool $httponly = true, bool $encodedValue = false, string $samesite = null)
6262
{
6363
if ($encodedValue) {
64-
$this->value = urldecode($value);
65-
$this->rawValue = $value;
64+
$this->rawValue = $value ?? '';
65+
$this->value = urldecode($this->rawValue);
6666
} else {
67-
$this->value = $value;
68-
$this->rawValue = rawurlencode($value ?? '');
67+
$this->value = $value ?? '';
68+
$this->rawValue = rawurlencode($this->value);
6969
}
7070
$this->name = $name;
7171
$this->path = empty($path) ? '/' : $path;

src/Symfony/Component/Cache/Adapter/CouchbaseBucketAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static function createConnection(#[\SensitiveParameter] array|string $ser
6464
throw new CacheException('Couchbase >= 2.6.0 < 3.0.0 is required.');
6565
}
6666

67-
set_error_handler(function ($type, $msg, $file, $line) { throw new \ErrorException($msg, 0, $type, $file, $line); });
67+
set_error_handler(static fn ($type, $msg, $file, $line) => throw new \ErrorException($msg, 0, $type, $file, $line));
6868

6969
$dsnPattern = '/^(?<protocol>couchbase(?:s)?)\:\/\/(?:(?<username>[^\:]+)\:(?<password>[^\@]{6,})@)?'
7070
.'(?<host>[^\:]+(?:\:\d+)?)(?:\/(?<bucketName>[^\?]+))(?:\?(?<options>.*))?$/i';

src/Symfony/Component/Cache/Adapter/CouchbaseCollectionAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static function createConnection(#[\SensitiveParameter] array|string $dsn
5757
throw new CacheException('Couchbase >= 3.0.0 < 4.0.0 is required.');
5858
}
5959

60-
set_error_handler(function ($type, $msg, $file, $line): bool { throw new \ErrorException($msg, 0, $type, $file, $line); });
60+
set_error_handler(static fn ($type, $msg, $file, $line) => throw new \ErrorException($msg, 0, $type, $file, $line));
6161

6262
$dsnPattern = '/^(?<protocol>couchbase(?:s)?)\:\/\/(?:(?<username>[^\:]+)\:(?<password>[^\@]{6,})@)?'
6363
.'(?<host>[^\:]+(?:\:\d+)?)(?:\/(?<bucketName>[^\/\?]+))(?:(?:\/(?<scopeName>[^\/]+))'

src/Symfony/Component/Cache/Adapter/DoctrineDbalAdapter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
class DoctrineDbalAdapter extends AbstractAdapter implements PruneableInterface
3131
{
32-
protected $maxIdLength = 255;
32+
private const MAX_KEY_LENGTH = 255;
3333

3434
private MarshallerInterface $marshaller;
3535
private Connection $conn;
@@ -94,6 +94,7 @@ public function __construct(Connection|string $connOrDsn, string $namespace = ''
9494
$this->conn = DriverManager::getConnection($params, $config);
9595
}
9696

97+
$this->maxIdLength = self::MAX_KEY_LENGTH;
9798
$this->table = $options['db_table'] ?? $this->table;
9899
$this->idCol = $options['db_id_col'] ?? $this->idCol;
99100
$this->dataCol = $options['db_data_col'] ?? $this->dataCol;

src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ class MemcachedAdapter extends AbstractAdapter
2929
*/
3030
private const RESERVED_MEMCACHED = " \n\r\t\v\f\0";
3131
private const RESERVED_PSR6 = '@()\{}/';
32-
33-
protected $maxIdLength = 250;
32+
private const MAX_KEY_LENGTH = 250;
3433

3534
private MarshallerInterface $marshaller;
3635
private \Memcached $client;
@@ -51,6 +50,8 @@ public function __construct(\Memcached $client, string $namespace = '', int $def
5150
if (!static::isSupported()) {
5251
throw new CacheException('Memcached > 3.1.5 is required.');
5352
}
53+
$this->maxIdLength = self::MAX_KEY_LENGTH;
54+
5455
if ('Memcached' === $client::class) {
5556
$opt = $client->getOption(\Memcached::OPT_SERIALIZER);
5657
if (\Memcached::SERIALIZER_PHP !== $opt && \Memcached::SERIALIZER_IGBINARY !== $opt) {
@@ -96,7 +97,7 @@ public static function createConnection(#[\SensitiveParameter] array|string $ser
9697
if (!static::isSupported()) {
9798
throw new CacheException('Memcached > 3.1.5 is required.');
9899
}
99-
set_error_handler(function ($type, $msg, $file, $line) { throw new \ErrorException($msg, 0, $type, $file, $line); });
100+
set_error_handler(static fn ($type, $msg, $file, $line) => throw new \ErrorException($msg, 0, $type, $file, $line));
100101
try {
101102
$client = new \Memcached($options['persistent_id'] ?? null);
102103
$username = $options['username'] ?? null;

src/Symfony/Component/Cache/Adapter/PdoAdapter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
class PdoAdapter extends AbstractAdapter implements PruneableInterface
2121
{
22-
protected $maxIdLength = 255;
22+
private const MAX_KEY_LENGTH = 255;
2323

2424
private MarshallerInterface $marshaller;
2525
private \PDO|Connection $conn;
@@ -75,6 +75,7 @@ public function __construct(#[\SensitiveParameter] \PDO|string $connOrDsn, strin
7575
$this->dsn = $connOrDsn;
7676
}
7777

78+
$this->maxIdLength = self::MAX_KEY_LENGTH;
7879
$this->table = $options['db_table'] ?? $this->table;
7980
$this->idCol = $options['db_id_col'] ?? $this->idCol;
8081
$this->dataCol = $options['db_data_col'] ?? $this->dataCol;

0 commit comments

Comments
 (0)