From 6343b3e5eaeba2be4de30ea3f71b38bfe9b93d1b Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 2 Dec 2024 15:07:19 +0000 Subject: [PATCH] Constructor property promotions (Pulling changes from shish/safe into smaller chunks for easier reviews) --- generator/src/DocPage.php | 12 +----------- generator/src/Parameter.php | 7 +------ generator/src/Scanner.php | 8 +------- generator/src/ScannerResponse.php | 26 ++++++++++---------------- generator/src/WritePhpFunction.php | 8 +------- 5 files changed, 14 insertions(+), 47 deletions(-) diff --git a/generator/src/DocPage.php b/generator/src/DocPage.php index f0253307..47cd0fdc 100644 --- a/generator/src/DocPage.php +++ b/generator/src/DocPage.php @@ -7,18 +7,8 @@ class DocPage { - /** - * @var string - */ - private $path; - - /* - * @return string - * @parameter string - */ - public function __construct(string $_path) + public function __construct(private readonly string $path) { - $this->path = $_path; } // Ignore function if it was removed before PHP 7.1 diff --git a/generator/src/Parameter.php b/generator/src/Parameter.php index 27f86bf4..90d5b7e5 100644 --- a/generator/src/Parameter.php +++ b/generator/src/Parameter.php @@ -7,18 +7,13 @@ class Parameter { - /** - * @var \SimpleXMLElement - */ - private $parameter; /** * @var PhpStanType */ private $type; - public function __construct(\SimpleXMLElement $parameter, ?PhpStanFunction $phpStanFunction, int $position) + public function __construct(private \SimpleXMLElement $parameter, ?PhpStanFunction $phpStanFunction, int $position) { - $this->parameter = $parameter; $phpStanParam = $phpStanFunction ? $phpStanFunction->getParameter($this->getParameterName(), $position) : null; $this->type = $phpStanParam ? $phpStanParam->getType() : new PhpStanType($this->parameter->type->__toString()); //todo: is this if useful? diff --git a/generator/src/Scanner.php b/generator/src/Scanner.php index de86fa71..a0e17f73 100644 --- a/generator/src/Scanner.php +++ b/generator/src/Scanner.php @@ -10,11 +10,6 @@ class Scanner { - /** - * @var string - */ - private $path; - /** * @var string[] */ @@ -25,9 +20,8 @@ class Scanner */ private $ignoredModules; - public function __construct(string $path) + public function __construct(private readonly string $path) { - $this->path = $path; } /** diff --git a/generator/src/ScannerResponse.php b/generator/src/ScannerResponse.php index 647db147..775d4c67 100644 --- a/generator/src/ScannerResponse.php +++ b/generator/src/ScannerResponse.php @@ -4,25 +4,19 @@ class ScannerResponse { - /** - * @readonly - * @var Method[] - */ - public array $methods; - - /** - * @readonly - * @var string[] - */ - public array $overloadedFunctions; - /** * @param Method[] $methods * @param string[] $overloadedFunctions */ - public function __construct(array $methods, array $overloadedFunctions) - { - $this->methods = $methods; - $this->overloadedFunctions = $overloadedFunctions; + public function __construct( + /** + * @readonly + */ + public array $methods, + /** + * @readonly + */ + public array $overloadedFunctions + ) { } } diff --git a/generator/src/WritePhpFunction.php b/generator/src/WritePhpFunction.php index f552aae3..cd164869 100644 --- a/generator/src/WritePhpFunction.php +++ b/generator/src/WritePhpFunction.php @@ -4,14 +4,8 @@ class WritePhpFunction { - /** - * @var Method - */ - private $method; - - public function __construct(Method $method) + public function __construct(private Method $method) { - $this->method = $method; } /*