8000 minor #51068 Add types to private and internal properties (nicolas-gr… · symfony/symfony@0bac246 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0bac246

Browse files
minor #51068 Add types to private and internal properties (nicolas-grekas)
This PR was merged into the 6.4 branch. Discussion ---------- Add types to private and internal properties | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Commits ------- 6353f5e Add types to private and internal properties
2 parents 86c41bb + 6353f5e commit 0bac246

File tree

139 files changed

+484
-739
lines changed

Some content is hidden

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

139 files changed

+484
-739
lines changed

src/Symfony/Bridge/Doctrine/Messenger/AbstractDoctrineMiddleware.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
*/
2626
abstract class AbstractDoctrineMiddleware implements MiddlewareInterface
2727
{
28-
protected $managerRegistry;
29-
protected $entityManagerName;
28+
protected ManagerRegistry $managerRegistry;
29+
protected ?string $entityManagerName;
3030

3131
public function __construct(ManagerRegistry $managerRegistry, string $entityManagerName = null)
3232
{

src/Symfony/Bridge/Doctrine/Messenger/DoctrineOpenTransactionLoggerMiddleware.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Doctrine\ORM\EntityManagerInterface;
1515
use Doctrine\Persistence\ManagerRegistry;
1616
use Psr\Log\LoggerInterface;
17-
use Psr\Log\NullLogger;
1817
use Symfony\Component\Messenger\Envelope;
1918
use Symfony\Component\Messenger\Middleware\StackInterface;
2019

@@ -25,13 +24,13 @@
2524
*/
2625
class DoctrineOpenTransactionLoggerMiddleware extends AbstractDoctrineMiddleware
2726
{
28-
private $logger;
27+
private ?LoggerInterface $logger;
2928

3029
public function __construct(ManagerRegistry $managerRegistry, string $entityManagerName = null, LoggerInterface $logger = null)
3130
{
3231
parent::__construct($managerRegistry, $entityManagerName);
3332

34-
$this->logger = $logger ?? new NullLogger();
33+
$this->logger = $logger;
3534
}
3635

3736
protected function handleForManager(EntityManagerInterface $entityManager, Envelope $envelope, StackInterface $stack): Envelope
@@ -40,7 +39,7 @@ protected function handleForManager(EntityManagerInterface $entityManager, Envel
4039
return $stack->next()->handle($envelope, $stack);
4140
} finally {
4241
if ($entityManager->getConnection()->isTransactionActive()) {
43-
$this->logger->error('A handler opened a transaction but did not close it.', [
42+
$this->logger?->error('A handler opened a transaction but did not close it.', [
4443
'message' => $envelope->getMessage(),
4544
]);
4645
}

src/Symfony/Bundle/DebugBundle/Command/ServerDumpPlaceholderCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#[AsCommand(name: 'server:dump', description: 'Start a dump server that collects and displays dumps in a single place')]
3030
class ServerDumpPlaceholderCommand extends Command
3131
{
32-
private $replacedCommand;
32+
private ServerDumpCommand $replacedCommand;
3333

3434
public function __construct(DumpServer $server = null, array $descriptors = [])
3535
{

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@
3333
*/
3434
abstract class Descriptor implements DescriptorInterface
3535
{
36-
/**
37-
* @var OutputInterface
38-
*/
39-
protected $output;
36+
protected OutputInterface $output;
4037

4138
public function describe(OutputInterface $output, mixed $object, array $options = []): void
4239
{

src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionPanelController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
*/
2626
class ExceptionPanelController
2727
{
28-
private $errorRenderer;
29-
private $profiler;
28+
private HtmlErrorRenderer $errorRenderer;
29+
private ?Profiler $profiler;
3030

3131
public function __construct(HtmlErrorRenderer $errorRenderer, Profiler $profiler = null)
3232
{

src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
*/
3333
class ProfilerController
3434
{
35-
private $templateManager;
36-
private $generator;
37-
private $profiler;
38-
private $twig;
39-
private $templates;
40-
private $cspHandler;
41-
private $baseDir;
35+
private TemplateManager $templateManager;
36+
private UrlGeneratorInterface $generator;
37+
private ?Profiler $profiler;
38+
private Environment $twig;
39+
private array $templates;
40+
private ?ContentSecurityPolicyHandler $cspHandler;
41+
private ?string $baseDir;
4242

4343
public function __construct(UrlGeneratorInterface $generator, Profiler $profiler = null, Environment $twig, array $templates, ContentSecurityPolicyHandler $cspHandler = null, string $baseDir = null)
4444
{
@@ -174,7 +174,6 @@ public function searchBarAction(Request $request): Response
174174

175175
$this->cspHandler?->disableCsp();
176176

177-
178177
$session = null;
179178
if ($request->attributes->getBoolean('_stateless') && $request->hasSession()) {
180179
$session = $request->getSession();

src/Symfony/Bundle/WebProfilerBundle/Controller/RouterController.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@
3030
*/
3131
class RouterController
3232
{
33-
private $profiler;
34-
private $twig;
35-
private $matcher;
36-
private $routes;
33+
private ?Profiler $profiler;
34+
private Environment $twig;
35+
private ?UrlMatcherInterface $matcher;
36+
private ?RouteCollection $routes;
3737

3838
/**
3939
* @var ExpressionFunctionProviderInterface[]
4040
*/
41-
private $expressionLanguageProviders = [];
41+
private iterable $expressionLanguageProviders;
4242

4343
public function __construct(Profiler $profiler = null, Environment $twig, UrlMatcherInterface $matcher = null, RouteCollection $routes = null, iterable $expressionLanguageProviders = [])
4444
{

src/Symfony/Bundle/WebProfilerBundle/Csp/ContentSecurityPolicyHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
*/
2424
class ContentSecurityPolicyHandler
2525
{
26-
private $nonceGenerator;
27-
private $cspDisabled = false;
26+
private NonceGenerator $nonceGenerator;
27+
private bool $cspDisabled = false;
2828

2929
public function __construct(NonceGenerator $nonceGenerator)
3030
{

src/Symfony/Bundle/WebProfilerBundle/Profiler/TemplateManager.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
*/
2525
class TemplateManager
2626
{
27-
protected $twig;
28-
protected $templates;
29-
protected $profiler;
27+
protected Environment $twig;
28+
protected array $templates;
29+
protected Profiler $profiler;
3030

3131
public function __construct(Profiler $profiler, Environment $twig, array $templates)
3232
{

src/Symfony/Bundle/WebProfilerBundle/Twig/WebProfilerExtension.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,14 @@
2727
*/
2828
class WebProfilerExtension extends ProfilerExtension
2929
{
30-
/**
31-
* @var HtmlDumper
32-
*/
33-
private $dumper;
30+
private HtmlDumper $dumper;
3431

3532
/**
3633
* @var resource
3734
*/
3835
private $output;
3936

40-
/**
41-
* @var int
42-
*/
43-
private $stackLevel = 0;
37+
private int $stackLevel = 0;
4438

4539
public function __construct(HtmlDumper $dumper = null)
4640
{

src/Symfony/Component/Asset/Exception/AssetNotFoundException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
class AssetNotFoundException extends RuntimeException
1818
{
19-
private $alternatives;
19+
private array $alternatives;
2020

2121
/**
2222
* @param string $message Exception message to throw

src/Symfony/Component/AssetMapper/Compiler/CssAssetUrlCompiler.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Component\AssetMapper\Compiler;
1313

1414
use Psr\Log\LoggerInterface;
15-
use Psr\Log\NullLogger;
1615
use Symfony\Component\AssetMapper\AssetDependency;
1716
use Symfony\Component\AssetMapper\AssetMapperInterface;
1817
use Symfony\Component\AssetMapper\Exception\RuntimeException;
@@ -29,16 +28,13 @@ final class CssAssetUrlCompiler implements AssetCompilerInterface
2928
{
3029
use AssetCompilerPathResolverTrait;
3130

32-
private readonly LoggerInterface $logger;
33-
3431
// https://regex101.com/r/BOJ3vG/1
3532
public const ASSET_URL_PATTERN = '/url\(\s*["\']?(?!(?:\/|\#|%23|data|http|\/\/))([^"\'\s?#)]+)([#?][^"\')]+)?\s*["\']?\)/';
3633

3734
public function __construct(
3835
private readonly string $missingImportMode = self::MISSING_IMPORT_WARN,
39-
LoggerInterface $logger = null,
36+
private readonly ?LoggerInterface $logger = null,
4037
) {
41-
$this->logger = $logger ?? new NullLogger();
4238
}
4339

4440
public function compile(string $content, MappedAsset $asset, AssetMapperInterface $assetMapper): string
@@ -76,7 +72,7 @@ private function handleMissingImport(string $message, \Throwable $e = null): voi
7672
{
7773
match ($this->missingImportMode) {
7874
AssetCompilerInterface::MISSING_IMPORT_IGNORE => null,
79-
AssetCompilerInterface::MISSING_IMPORT_WARN => $this->logger->warning($message),
75+
AssetCompilerInterface::MISSING_IMPORT_WARN => $this->logger?->warning($message),
8076
AssetCompilerInterface::MISSING_IMPORT_STRICT => throw new RuntimeException($message, 0, $e),
8177
};
8278
}

src/Symfony/Component/AssetMapper/Compiler/JavaScriptImportPathCompiler.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Component\AssetMapper\Compiler;
1313

1414
use Psr\Log\LoggerInterface;
15-
use Psr\Log\NullLogger;
1615
use Symfony\Component\AssetMapper\AssetDependency;
1716
use Symfony\Component\AssetMapper\AssetMapperInterface;
1817
use Symfony\Component\AssetMapper\Exception\RuntimeException;
@@ -29,16 +28,13 @@ final class JavaScriptImportPathCompiler implements AssetCompilerInterface
2928
{
3029
use AssetCompilerPathResolverTrait;
3130

32-
private readonly LoggerInterface $logger;
33-
3431
// https://regex101.com/r/VFdR4H/1
3532
private const IMPORT_PATTERN = '/(?:import\s+(?:(?:\*\s+as\s+\w+|[\w\s{},*]+)\s+from\s+)?|\bimport\()\s*[\'"`](\.\/[^\'"`]+|(\.\.\/)+[^\'"`]+)[\'"`]\s*[;\)]?/m';
3633

3734
public function __construct(
3835
private readonly string $missingImportMode = self::MISSING_IMPORT_WARN,
39-
LoggerInterface $logger = null,
36+
private readonly ?LoggerInterface $logger = null,
4037
) {
41-
$this->logger = $logger ?? new NullLogger();
4238
}
4339

4440
public function compile(string $content, MappedAsset $asset, AssetMapperInterface $assetMapper): string
@@ -101,7 +97,7 @@ private function handleMissingImport(string $message, \Throwable $e = null): voi
10197
{
10298
match ($this->missingImportMode) {
10399
AssetCompilerInterface::MISSING_IMPORT_IGNORE => null,
104-
AssetCompilerInterface::MISSING_IMPORT_WARN => $this->logger->warning($message),
100+
AssetCompilerInterface::MISSING_IMPORT_WARN => $this->logger?->warning($message),
105101
AssetCompilerInterface::MISSING_IMPORT_STRICT => throw new RuntimeException($message, 0, $e),
106102
};
107103
}

src/Symfony/Component/BrowserKit/AbstractBrowser.php

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,7 @@ public function getCookieJar(): CookieJar
204204
*/
205205
public function getCrawler(): Crawler
206206
{
207-
if (null === $this->crawler) {
208-
throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
209-
}
210-
211-
return $this->crawler;
207+
return $this->crawler ?? throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
212208
}
213209

214210
/**
@@ -228,11 +224,7 @@ public function useHtml5Parser(bool $useHtml5Parser): static
228224
*/
229225
public function getInternalResponse(): Response
230226
{
231-
if (null === $this->internalResponse) {
232-
throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
233-
}
234-
235-
return $this->internalResponse;
227+
return $this->internalResponse ?? throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
236228
}
237229

238230
/**
@@ -245,23 +237,15 @@ public function getInternalResponse(): Response
245237
*/
246238
public function getResponse(): object
247239
{
248-
if (null === $this->response) {
249-
throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
250-
}
251-
252-
return $this->response;
240+
return $this->response ?? throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
253241
}
254242

255243
/**
256244
* Returns the current BrowserKit Request instance.
257245
*/
258246
public function getInternalRequest(): Request
259247
{
260-
if (null === $this->internalRequest) {
261-
throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
262-
}
263-
264-
return $this->internalRequest;
248+
return $this->internalRequest ?? throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
265249
}
266250

267251
/**
@@ -274,11 +258,7 @@ public function getInternalRequest(): Request
274258
*/
275259
public function getRequest(): object
276260
{
277-
if (null === $this->request) {
278-
throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
279-
}
280-
281-
return $this->request;
261+
return $this->request ?? throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
282262
}
283263

284264
/**
@@ -300,11 +280,9 @@ public function click(Link $link): Crawler
300280
*/
301281
public function clickLink(string $linkText): Crawler
302282
{
303-
if (null === $this->crawler) {
304-
throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
305-
}
283+
$crawler = $this->crawler ?? throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
306284

307-
return $this->click($this->crawler->selectLink($linkText)->link());
285+
return $this->click($crawler->selectLink($linkText)->link());
308286
}
309287

310288
/**
@@ -331,11 +309,8 @@ public function submit(Form $form, array $values = [], array $serverParameters =
331309
*/
332310
public function submitForm(string $button, array $fieldValues = [], string $method = 'POST', array $serverParameters = []): Crawler
333311
{
334-
if (null === $this->crawler) {
335-
throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
336-
}
337-
338-
$buttonNode = $this->crawler->selectButton($button);
312+
$crawler = $this->crawler ?? throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
313+
$buttonNode = $crawler->selectButton($button);
339314

340315
if (0 === $buttonNode->count()) {
341316
throw new InvalidArgumentException(sprintf('There is no button with "%s" as its content, id, value or name.', $button));

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ abstract class AbstractAdapter implements AdapterInterface, CacheInterface, Logg
3333
*/
3434
protected const NS_SEPARATOR = ':';
3535

36-
private static $apcuSupported;
37-
private static $phpFilesSupported;
36+
private static bool $apcuSupported;
3837

3938
protected function __construct(string $namespace = '', int $defaultLifetime = 0)
4039
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121
class NullAdapter implements AdapterInterface, CacheInterface
2222
{
23-
private static $createCacheItem;
23+
private static \Closure $createCacheItem;
2424

2525
public function __construct()
2626
{

src/Symfony/Component/Cache/LockRegistry.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@
2626
*/
2727
final class LockRegistry
2828
{
29-
private static $openedFiles = [];
30-
private static $lockedFiles;
31-
private static $signalingException;
32-
private static $signalingCallback;
29+
private static array $openedFiles = [];
30+
private static ?array $lockedFiles = null;
31+
private static \Exception $signalingException;
32+
private static \Closure $signalingCallback;
3333

3434
/**
3535
* The number of items in this list controls the max number of concurrent processes.
3636
*/
37-
private static $files = [
37+
private static array $files = [
3838
__DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'AbstractAdapter.php',
3939
__DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'AbstractTagAwareAdapter.php',
4040
__DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'AdapterInterface.php',

src/Symfony/Component/Config/Definition/Builder/TreeBuilder.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,7 @@ public function getRootNode(): NodeDefinition|ArrayNodeDefinition
4444
*/
4545
public function buildTree(): NodeInterface
4646
{
47-
if (null !== $this->tree) {
48-
return $this->tree;
49-
}
50-
51-
return $this->tree = $this->root->getNode(true);
47+
return $this->tree ??= $this->root->getNode(true);
5248
}
5349

5450
/**

0 commit comments

Comments
 (0)
0