From 82d19c6a6b7933b5df4bbc2a5d701565ab623cd6 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 8 Aug 2024 16:42:59 +0200 Subject: [PATCH] Turn Regex classes immutable where possible --- src/Type/Regex/RegexAlternation.php | 2 +- src/Type/Regex/RegexCapturingGroup.php | 14 +++++++------- src/Type/Regex/RegexNonCapturingGroup.php | 10 +++++----- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Type/Regex/RegexAlternation.php b/src/Type/Regex/RegexAlternation.php index ecf6d0fb39..70ba5a41ea 100644 --- a/src/Type/Regex/RegexAlternation.php +++ b/src/Type/Regex/RegexAlternation.php @@ -10,7 +10,7 @@ final class RegexAlternation /** @var array> */ private array $groupCombinations = []; - public function __construct(private int $alternationId) + public function __construct(private readonly int $alternationId) { } diff --git a/src/Type/Regex/RegexCapturingGroup.php b/src/Type/Regex/RegexCapturingGroup.php index 983a823bef..83fafbdd41 100644 --- a/src/Type/Regex/RegexCapturingGroup.php +++ b/src/Type/Regex/RegexCapturingGroup.php @@ -4,18 +4,18 @@ use PHPStan\Type\Type; -class RegexCapturingGroup +final class RegexCapturingGroup { private bool $forceNonOptional = false; public function __construct( - private int $id, - private ?string $name, - private ?RegexAlternation $alternation, - private bool $inOptionalQuantification, - private RegexCapturingGroup|RegexNonCapturingGroup|null $parent, - private Type $type, + private readonly int $id, + private readonly ?string $name, + private readonly ?RegexAlternation $alternation, + private readonly bool $inOptionalQuantification, + private readonly RegexCapturingGroup|RegexNonCapturingGroup|null $parent, + private readonly Type $type, ) { } diff --git a/src/Type/Regex/RegexNonCapturingGroup.php b/src/Type/Regex/RegexNonCapturingGroup.php index 13bc6dabf6..79b4d8bc08 100644 --- a/src/Type/Regex/RegexNonCapturingGroup.php +++ b/src/Type/Regex/RegexNonCapturingGroup.php @@ -2,14 +2,14 @@ namespace PHPStan\Type\Regex; -class RegexNonCapturingGroup +final class RegexNonCapturingGroup { public function __construct( - private ?RegexAlternation $alternation, - private bool $inOptionalQuantification, - private RegexCapturingGroup|RegexNonCapturingGroup|null $parent, - private bool $resetGroupCounter, + private readonly ?RegexAlternation $alternation, + private readonly bool $inOptionalQuantification, + private readonly RegexCapturingGroup|RegexNonCapturingGroup|null $parent, + private readonly bool $resetGroupCounter, ) { }