diff --git a/generator/src/Parameter.php b/generator/src/Parameter.php index 5b89f78e..5caae117 100644 --- a/generator/src/Parameter.php +++ b/generator/src/Parameter.php @@ -10,15 +10,11 @@ class Parameter { - /** - * @var PhpStanType - */ - private $type; + private readonly PhpStanType $type; public function __construct(private \SimpleXMLElement $parameter, ?PhpStanFunction $phpStanFunction, int $position) { $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/PhpStanFunctions/PhpStanFunction.php b/generator/src/PhpStanFunctions/PhpStanFunction.php index 720240a6..47c8ead3 100644 --- a/generator/src/PhpStanFunctions/PhpStanFunction.php +++ b/generator/src/PhpStanFunctions/PhpStanFunction.php @@ -6,10 +6,7 @@ class PhpStanFunction { - /** - * @var PhpStanType - */ - private $returnType; + private readonly PhpStanType $returnType; /** * @var PhpStanParameter[] @@ -24,6 +21,7 @@ public function __construct(array $signature) if (count($signature) < 1) { throw new \RuntimeException('Invalid signatures'); } + $this->returnType = new PhpStanType(\array_shift($signature)); foreach ($signature as $name => $type) { $param = new PhpStanParameter($name, $type); diff --git a/generator/src/PhpStanFunctions/PhpStanParameter.php b/generator/src/PhpStanFunctions/PhpStanParameter.php index 26af3b77..a10c0c2c 100644 --- a/generator/src/PhpStanFunctions/PhpStanParameter.php +++ b/generator/src/PhpStanFunctions/PhpStanParameter.php @@ -8,8 +8,8 @@ class PhpStanParameter { - private string $name; - private PhpStanType $type; + private readonly string $name; + private readonly PhpStanType $type; public function __construct(string $name, string $type) { diff --git a/generator/src/WritePhpFunction.php b/generator/src/WritePhpFunction.php index ca892539..b8c59009 100644 --- a/generator/src/WritePhpFunction.php +++ b/generator/src/WritePhpFunction.php @@ -93,19 +93,12 @@ private function writePhpFunction(): string private function generateExceptionCode(string $moduleName, Method $method) : string { - switch ($method->getErrorType()) { - case Method::FALSY_TYPE: - $errorValue = 'false'; - break; - case Method::NULLSY_TYPE: - $errorValue = 'null'; - break; - case Method::EMPTY_TYPE: - $errorValue = "''"; - break; - default: - throw new \LogicException("Method doesn't have an error type"); - } + $errorValue = match ($method->getErrorType()) { + Method::FALSY_TYPE => 'false', + Method::NULLSY_TYPE => 'null', + Method::EMPTY_TYPE => "''", + default => throw new \LogicException("Method doesn't have an error type"), + }; // Special case for CURL: we need the first argument of the method if this is a resource. if ($moduleName === 'Curl') {