Skip to content

Commit

Permalink
feat: add compatibility for PHP 8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer committed Dec 3, 2024
1 parent 7946006 commit 813d6bf
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/Generation/GapicClientV2Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ private function resourceMethods(): Vector
return Vector::new();
}
$formattedName = AST::param(ResolvedType::string(), AST::var('formattedName'));
$template = AST::param(ResolvedType::string(), AST::var('template'), AST::NULL);
$template = AST::param(ResolvedType::string(true), AST::var('template'), AST::NULL);

return $this->serviceDetails->resourceParts
->map(fn ($x) => $x->getFormatMethod()
Expand Down
23 changes: 10 additions & 13 deletions src/Utils/ResolvedType.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ class ResolvedType
*
* @return ResolvedType
*/
public static function array(): ResolvedType
public static function array(bool $optional = false): ResolvedType
{
return new ResolvedType(Type::array(), fn () => 'array');
return new ResolvedType(Type::array(), fn () => 'array', $optional);
}

/**
* The 'string' built-in type.
*
* @return ResolvedType
*/
public static function string(): ResolvedType
public static function string(bool $optional = false): ResolvedType
{
return new ResolvedType(Type::string(), fn () => 'string');
return new ResolvedType(Type::string(), fn () => 'string', $optional);
}

/**
Expand Down Expand Up @@ -69,19 +69,16 @@ public static function self(): ResolvedType
*
* @param string $typeName The resolved name of the type.
*/
public function __construct(Type $type, \Closure $fnToCode)
public function __construct(
/** @var Type *Readonly* The type of this resolved-type. */
public ReadOnly Type $type,
private \Closure $fnToCode,
private bool $optional = false)
{
$this->type = $type;
$this->fnToCode = $fnToCode;
}

/** @var Type *Readonly* The type of this resolved-type. */
public Type $type;

private \Closure $fnToCode;

public function toCode(): string
{
return ($this->fnToCode)();
return ($this->optional ? '?' : '') . ($this->fnToCode)();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,14 @@ public static function repositoryName(string $project, string $location, string
* listed, then parseName will check each of the supported templates, and return
* the first match.
*
* @param string $formattedName The formatted name string
* @param string $template Optional name of template to match
* @param string $formattedName The formatted name string
* @param ?string $template Optional name of template to match
*
* @return array An associative array from name component IDs to component values.
*
* @throws ValidationException If $formattedName could not be matched.
*/
public static function parseName(string $formattedName, string $template = null): array
public static function parseName(string $formattedName, ?string $template = null): array
{
return self::parseFormattedName($formattedName, $template);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,14 @@ public static function locationName(string $project, string $location): string
* listed, then parseName will check each of the supported templates, and return
* the first match.
*
* @param string $formattedName The formatted name string
* @param string $template Optional name of template to match
* @param string $formattedName The formatted name string
* @param ?string $template Optional name of template to match
*
* @return array An associative array from name component IDs to component values.
*
* @throws ValidationException If $formattedName could not be matched.
*/
public static function parseName(string $formattedName, string $template = null): array
public static function parseName(string $formattedName, ?string $template = null): array
{
return self::parseFormattedName($formattedName, $template);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1233,14 +1233,14 @@ public static function topicName(string $project, string $topic): string
* listed, then parseName will check each of the supported templates, and return
* the first match.
*
* @param string $formattedName The formatted name string
* @param string $template Optional name of template to match
* @param string $formattedName The formatted name string
* @param ?string $template Optional name of template to match
*
* @return array An associative array from name component IDs to component values.
*
* @throws ValidationException If $formattedName could not be matched.
*/
public static function parseName(string $formattedName, string $template = null): array
public static function parseName(string $formattedName, ?string $template = null): array
{
return self::parseFormattedName($formattedName, $template);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,14 @@ public static function instanceName(string $project, string $instance): string
* listed, then parseName will check each of the supported templates, and return
* the first match.
*
* @param string $formattedName The formatted name string
* @param string $template Optional name of template to match
* @param string $formattedName The formatted name string
* @param ?string $template Optional name of template to match
*
* @return array An associative array from name component IDs to component values.
*
* @throws ValidationException If $formattedName could not be matched.
*/
public static function parseName(string $formattedName, string $template = null): array
public static function parseName(string $formattedName, ?string $template = null): array
{
return self::parseFormattedName($formattedName, $template);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,14 +421,14 @@ public static function wildcardMultiPatternName(string $item1Id): string
* listed, then parseName will check each of the supported templates, and return
* the first match.
*
* @param string $formattedName The formatted name string
* @param string $template Optional name of template to match
* @param string $formattedName The formatted name string
* @param ?string $template Optional name of template to match
*
* @return array An associative array from name component IDs to component values.
*
* @throws ValidationException If $formattedName could not be matched.
*/
public static function parseName(string $formattedName, string $template = null): array
public static function parseName(string $formattedName, ?string $template = null): array
{
return self::parseFormattedName($formattedName, $template);
}
Expand Down

0 comments on commit 813d6bf

Please sign in to comment.