Skip to content

Commit

Permalink
Misc smaller changes
Browse files Browse the repository at this point in the history
A few random bits which fell between the cracks with the shish/safe merge
  • Loading branch information
shish authored and staabm committed Dec 3, 2024
1 parent 40474de commit d3a05e4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 24 deletions.
6 changes: 1 addition & 5 deletions generator/src/Parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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?
}

Expand Down
6 changes: 2 additions & 4 deletions generator/src/PhpStanFunctions/PhpStanFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@

class PhpStanFunction
{
/**
* @var PhpStanType
*/
private $returnType;
private readonly PhpStanType $returnType;

/**
* @var PhpStanParameter[]
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions generator/src/PhpStanFunctions/PhpStanParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
19 changes: 6 additions & 13 deletions generator/src/WritePhpFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down

0 comments on commit d3a05e4

Please sign in to comment.