8000 Add types to private and internal properties by nicolas-grekas · Pull Request #51068 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Add types to private and internal properties #51068

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
*/
abstract class AbstractDoctrineMiddleware implements MiddlewareInterface
{
protected $managerRegistry;
protected $entityManagerName;
protected ManagerRegistry $managerRegistry;
protected ?string $entityManagerName;

public function __construct(ManagerRegistry $managerRegistry, string $entityManagerName = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ManagerRegistry;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Middleware\StackInterface;

Expand All @@ -25,13 +24,13 @@
*/
class DoctrineOpenTransactionLoggerMiddleware extends AbstractDoctrineMiddleware
{
private $logger;
private ?LoggerInterface $logger;

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

$this->logger = $logger ?? new NullLogger();
$this->logger = $logger;
}

protected function handleForManager(EntityManagerInterface $entityManager, Envelope $envelope, StackInterface $stack): Envelope
Expand All @@ -40,7 +39,7 @@ protected function handleForManager(EntityManagerInterface $entityManager, Envel
return $stack->next()->handle($envelope, $stack);
} finally {
if ($entityManager->getConnection()->isTransactionActive()) {
$this->logger->error('A handler opened a transaction but did not close it.', [
$this->logger?->error('A handler opened a transaction but did not close it.', [
'message' => $envelope->getMessage(),
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#[AsCommand(name: 'server:dump', description: 'Start a dump server that collects and displays dumps in a single place')]
class ServerDumpPlaceholderCommand extends Command
{
private $replacedCommand;
private ServerDumpCommand $replacedCommand;

public function __construct(DumpServer $server = null, array $descriptors = [])
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@
*/
abstract class Descriptor implements DescriptorInterface
{
/**
* @var OutputInterface
*/
protected $output;
protected OutputInterface $output;

public function describe(OutputInterface $output, mixed $object, array $options = []): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
*/
class ExceptionPanelController
{
private $errorRenderer;
private $profiler;
private HtmlErrorRenderer $errorRenderer;
private ?Profiler $profiler;

public function __construct(HtmlErrorRenderer $errorRenderer, Profiler $profiler = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
*/
class ProfilerController
{
private $templateManager;
private $generator;
private $profiler;
private $twig;
private $templates;
private $cspHandler;
private $baseDir;
private TemplateManager $templateManager;
private UrlGeneratorInterface $generator;
private ?Profiler $profiler;
private Environment $twig;
private array $templates;
private ?ContentSecurityPolicyHandler $cspHandler;
private ?string $baseDir;

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

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


$session = null;
if ($request->attributes->getBoolean('_stateless') && $request->hasSession()) {
$session = $request->getSession();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
*/
class RouterController
{
private $profiler;
private $twig;
private $matcher;
private $routes;
private ?Profiler $profiler;
private Environment $twig;
private ?UrlMatcherInterface $matcher;
private ?RouteCollection $routes;

/**
* @var ExpressionFunctionProviderInterface[]
*/
private $expressionLanguageProviders = [];
private iterable $expressionLanguageProviders;

public function __construct(Profiler $profiler = null, Environment $twig, UrlMatcherInterface $matcher = null, RouteCollection $routes = null, iterable $expressionLanguageProviders = [])
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
*/
class ContentSecurityPolicyHandler
{
private $nonceGenerator;
private $cspDisabled = false;
private NonceGenerator $nonceGenerator;
private bool $cspDisabled = false;

public function __construct(NonceGenerator $nonceGenerator)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
*/
class TemplateManager
{
protected $twig;
protected $templates;
protected $profiler;
protected Environment $twig;
protected array $templates;
protected Profiler $profiler;

public function __construct(Profiler $profiler, Environment $twig, array $templates)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,14 @@
*/
class WebProfilerExtension extends ProfilerExtension
{
/**
* @var HtmlDumper
*/
private $dumper;
private HtmlDumper $dumper;

/**
* @var resource
*/
private $output;

/**
* @var int
*/
private $stackLevel = 0;
private int $stackLevel = 0;

public function __construct(HtmlDumper $dumper = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
class AssetNotFoundException extends RuntimeException
{
private $alternatives;
private array $alternatives;

/**
* @param string $message Exception message to throw
Expand Down
F438
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Component\AssetMapper\Compiler;

use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Symfony\Component\AssetMapper\AssetDependency;
use Symfony\Component\AssetMapper\AssetMapperInterface;
use Symfony\Component\AssetMapper\Exception\RuntimeException;
Expand All @@ -29,16 +28,13 @@ final class CssAssetUrlCompiler implements AssetCompilerInterface
{
use AssetCompilerPathResolverTrait;

private readonly LoggerInterface $logger;

// https://regex101.com/r/BOJ3vG/1
public const ASSET_URL_PATTERN = '/url\(\s*["\']?(?!(?:\/|\#|%23|data|http|\/\/))([^"\'\s?#)]+)([#?][^"\')]+)?\s*["\']?\)/';

public function __construct(
private readonly string $missingImportMode = self::MISSING_IMPORT_WARN,
LoggerInterface $logger = null,
private readonly ?LoggerInterface $logger = null,
) {
$this->logger = $logger ?? new NullLogger();
}

public function compile(string $content, MappedAsset $asset, AssetMapperInterface $assetMapper): string
Expand Down Expand Up @@ -76,7 +72,7 @@ private function handleMissingImport(string $message, \Throwable $e = null): voi
{
match ($this->missingImportMode) {
AssetCompilerInterface::MISSING_IMPORT_IGNORE => null,
AssetCompilerInterface::MISSING_IMPORT_WARN => $this->logger->warning($message),
AssetCompilerInterface::MISSING_IMPORT_WARN => $this->logger?->warning($message),
AssetCompilerInterface::MISSING_IMPORT_STRICT => throw new RuntimeException($message, 0, $e),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Component\AssetMapper\Compiler;

use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Symfony\Component\AssetMapper\AssetDependency;
use Symfony\Component\AssetMapper\AssetMapperInterface;
use Symfony\Component\AssetMapper\Exception\RuntimeException;
Expand All @@ -29,16 +28,13 @@ final class JavaScriptImportPathCompiler implements AssetCompilerInterface
{
use AssetCompilerPathResolverTrait;

private readonly LoggerInterface $logger;

// https://regex101.com/r/VFdR4H/1
private const IMPORT_PATTERN = '/(?:import\s+(?:(?:\*\s+as\s+\w+|[\w\s{},*]+)\s+from\s+)?|\bimport\()\s*[\'"`](\.\/[^\'"`]+|(\.\.\/)+[^\'"`]+)[\'"`]\s*[;\)]?/m';

public function __construct(
private readonly string $missingImportMode = self::MISSING_IMPORT_WARN,
LoggerInterface $logger = null,
private readonly ?LoggerInterface $logger = null,
) {
$this->logger = $logger ?? new NullLogger();
}

public function compile(string $content, MappedAsset $asset, AssetMapperInterface $assetMapper): string
Expand Down Expand Up @@ -101,7 +97,7 @@ private function handleMissingImport(string $message, \Throwable $e = null): voi
{
match ($this->missingImportMode) {
AssetCompilerInterface::MISSING_IMPORT_IGNORE => null,
AssetCompilerInterface::MISSING_IMPORT_WARN => $this->logger->warning($message),
AssetCompilerInterface::MISSING_IMPORT_WARN => $this->logger?->warning($message),
AssetCompilerInterface::MISSING_IMPORT_STRICT => throw new RuntimeException($message, 0, $e),
};
}
Expand Down
43 changes: 9 additions & 34 deletions src/Symfony/Component/BrowserKit/AbstractBrowser.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,7 @@ public function getCookieJar(): CookieJar
*/
public function getCrawler(): Crawler
{
if (null === $this->crawler) {
throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
}

return $this->crawler;
return $this->crawler ?? throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
}

/**
Expand All @@ -228,11 +224,7 @@ public function useHtml5Parser(bool $useHtml5Parser): static
*/
public function getInternalResponse(): Response
{
if (null === $this->internalResponse) {
throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
}

return $this->internalResponse;
return $this->internalResponse ?? throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
}

/**
Expand All @@ -245,23 +237,15 @@ public function getInternalResponse(): Response
*/
public function getResponse(): object
{
if (null === $this->response) {
throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
}

return $this->response;
return $this->response ?? throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
}

/**
* Returns the current BrowserKit Request instance.
*/
public function getInternalRequest(): Request
{
if (null === $this->internalRequest) {
throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
}

return $this->internalRequest;
return $this->internalRequest ?? throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
}

/**
Expand All @@ -274,11 +258,7 @@ public function getInternalRequest(): Request
*/
public function getRequest(): object
{
if (null === $this->request) {
throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
}

return $this->request;
return $this->request ?? throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
}

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

return $this->click($this->crawler->selectLink($linkText)->link());
return $this->click($crawler->selectLink($linkText)->link());
}

/**
Expand All @@ -331,11 +309,8 @@ public function submit(Form $form, array $values = [], array $serverParameters =
*/
public function submitForm(string $button, array $fieldValues = [], string $method = 'POST', array $serverParameters = []): Crawler
{
if (null === $this->crawler) {
throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
}

$buttonNode = $this->crawler->selectButton($button);
$crawler = $this->crawler ?? throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
$buttonNode = $crawler->selectButton($button);

if (0 === $buttonNode->count()) {
throw new InvalidArgumentException(sprintf('There is no button with "%s" as its content, id, value or name.', $button));
Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/Component/Cache/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ abstract class AbstractAdapter implements AdapterInterface, CacheInterface, Logg
*/
protected const NS_SEPARATOR = ':';

private static $apcuSupported;
private static $phpFilesSupported;
private static bool $apcuSupported;

protected function __construct(string $namespace = '', int $defaultLifetime = 0)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Adapter/NullAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class NullAdapter implements AdapterInterface, CacheInterface
{
private static $createCacheItem;
private static \Closure $createCacheItem;

public function __construct()
{
Expand Down
10 changes: 5 additions & 5 deletions src/Symfony/Component/Cache/LockRegistry.php
< D40F td class="blob-num blob-num-deletion empty-cell">
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
*/
final class LockRegistry
{
private static $openedFiles = [];
private static $lockedFiles;
private static $signalingException;
private static $signalingCallback;
private static array $openedFiles = [];
private static ?array $lockedFiles = null;
private static \Exception $signalingException;
private static \Closure $signalingCallback;

/**
* The number of items in this list controls the max number of concurrent processes.
*/
private static $files = [
private static array $files = [
__DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'AbstractAdapter.php',
__DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'AbstractTagAwareAdapter.php',
__DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'AdapterInterface.php',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ public function getRootNode(): NodeDefinition|ArrayNodeDefinition
*/
public function buildTree(): NodeInterface
{
if (null !== $this->tree) {
return $this->tree;
}

return $this->tree = $this->root->getNode(true);
return $this->tree ??= $this->root->getNode(true);
}

/**
Expand Down
Loading
0