Skip to content

Commit

Permalink
Fix typed properties used before initialization and return type for s…
Browse files Browse the repository at this point in the history
…tatic[]
  • Loading branch information
pjcdawkins committed Nov 25, 2024
1 parent e1e88af commit c859372
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 55 deletions.
4 changes: 2 additions & 2 deletions src/Connection/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ class Connector implements ConnectorInterface
{
protected array $config = [];

protected ?ClientInterface $client;
protected ?ClientInterface $client = null;

protected $oauthMiddleware;

protected ?AbstractProvider $provider;
protected ?AbstractProvider $provider = null;

protected SessionInterface $session;

Expand Down
2 changes: 1 addition & 1 deletion src/Model/ActivityLog/LogItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static function singleFromJson(string $str): self|false
* @return static[]
*@deprecated use LogItem::multipleFromJsonStreamWithSeal() instead
*/
public static function multipleFromJsonStream(string $str): static
public static function multipleFromJsonStream(string $str): array
{
$items = [];
foreach (explode("\n", trim($str, "\n")) as $line) {
Expand Down
4 changes: 2 additions & 2 deletions src/Model/ApiResourceBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ abstract class ApiResourceBase implements \ArrayAccess

protected bool $isFull = false;

protected ?Collection $parentCollection;
protected ?Collection $parentCollection = null;

/**
* @param array $data The raw data for the resource
Expand Down Expand Up @@ -230,7 +230,7 @@ public static function getRequired(): array
*
* @return static[]
*/
public static function getCollection(string $url, int $limit, array $options, ClientInterface $client): static
public static function getCollection(string $url, int $limit, array $options, ClientInterface $client): array
{
$items = static::getCollectionWithParent($url, $client, $options)['items'];

Expand Down
4 changes: 2 additions & 2 deletions src/Model/Backups/RestoreOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

class RestoreOptions
{
private ?string $environmentName;
private ?string $environmentName = null;

private ?string $branchFrom;
private ?string $branchFrom = null;

private ?bool $restoreCode;

Expand Down
10 changes: 5 additions & 5 deletions src/Model/BasicProjectInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ class BasicProjectInfo

public string $title;

public ?string $region;
public ?string $region = null;

public ?string $subscription_id;
public ?string $subscription_id = null;

public ?OrganizationRef $organization_ref;
public ?OrganizationRef $organization_ref = null;

public ?string $created_at;
public ?string $created_at = null;

public ?string $status;
public ?string $status = null;

public ?string $organization_id;

Expand Down
2 changes: 1 addition & 1 deletion src/Model/CentralizedPermissions/UserExtendedAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class UserExtendedAccess extends ResourceWithReferences
/**
* @return static[]
*/
public static function byUser(string $userId, array $options, ClientInterface $client): static
public static function byUser(string $userId, array $options, ClientInterface $client): array
{
return self::getCollection('/users/' . rawurlencode($userId) . '/extended-access', 0, $options, $client);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Model/CentralizedPermissions/UserProjectAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class UserProjectAccess extends ResourceWithReferences
/**
* @return static[]
*/
public static function byUser(string $userId, array $options, ClientInterface $client): static
public static function byUser(string $userId, array $options, ClientInterface $client): array
{
return self::getCollection('/users/' . rawurlencode($userId) . '/project-access', 0, $options, $client);
}
Expand Down
60 changes: 20 additions & 40 deletions src/Model/Subscription/SubscriptionOptions.php
Original file line number Diff line number Diff line change
@@ -1,63 +1,43 @@
<?php

declare(strict_types=1);
/** @noinspection PhpUnusedPrivateFieldInspection */

namespace Platformsh\Client\Model\Subscription;

final class SubscriptionOptions
final readonly class SubscriptionOptions
{
private ?string $project_region;
private array $options;

private ?string $project_title;

private ?string $default_branch;

private ?string $options_url;

private ?array $options_custom;

private ?string $plan;

private ?int $environments;

private ?int $storage;

private ?string $owner;
private function __construct(array $options)
{
$this->options = $options;
}

/**
* @deprecated This is no longer supported. Poll the subscription instead of submitting a callback.
* @param array{
* project_region: ?string,
* project_title: ?string,
* default_branch: ?string,
* options_url: ?string,
* options_custom: ?array,
* plan: ?string,
* environments: ?int,
* storage: ?int,
* organization_id: ?string,
* } $options
*/
private ?array $activation_callback;

private ?string $organization_id;

public static function fromArray(array $options): self
{
$obj = new self();
foreach ($options as $key => $value) {
if (\property_exists($obj, $key)) {
$obj->{$key} = $value;
} else {
throw new \InvalidArgumentException('Unknown property: ' . $key);
}
}
return $obj;
return new self($options);
}

public function toArray(): array
{
$arr = [];
foreach ($this as $key => $value) {
if ($value !== null && $value !== 'organization_id') {
$arr[$key] = $value;
}
}
return $arr;
return $this->options;
}

public function organizationId(): ?string
{
return $this->organization_id;
return $this->options['organization_id'] ?? null;
}
}
2 changes: 1 addition & 1 deletion src/PlatformClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class PlatformClient
/**
* @var array|null A per-client cache for account info
*/
protected ?array $accountInfo;
protected ?array $accountInfo = null;

/**
* @var string|false|null A per-client cache for the user ID
Expand Down

0 comments on commit c859372

Please sign in to comment.