Skip to content

Commit c859372

Browse files
committed
Fix typed properties used before initialization and return type for static[]
1 parent e1e88af commit c859372

File tree

9 files changed

+35
-55
lines changed

9 files changed

+35
-55
lines changed

src/Connection/Connector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ class Connector implements ConnectorInterface
2626
{
2727
protected array $config = [];
2828

29-
protected ?ClientInterface $client;
29+
protected ?ClientInterface $client = null;
3030

3131
protected $oauthMiddleware;
3232

33-
protected ?AbstractProvider $provider;
33+
protected ?AbstractProvider $provider = null;
3434

3535
protected SessionInterface $session;
3636

src/Model/ActivityLog/LogItem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static function singleFromJson(string $str): self|false
4646
* @return static[]
4747
*@deprecated use LogItem::multipleFromJsonStreamWithSeal() instead
4848
*/
49-
public static function multipleFromJsonStream(string $str): static
49+
public static function multipleFromJsonStream(string $str): array
5050
{
5151
$items = [];
5252
foreach (explode("\n", trim($str, "\n")) as $line) {

src/Model/ApiResourceBase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ abstract class ApiResourceBase implements \ArrayAccess
3434

3535
protected bool $isFull = false;
3636

37-
protected ?Collection $parentCollection;
37+
protected ?Collection $parentCollection = null;
3838

3939
/**
4040
* @param array $data The raw data for the resource
@@ -230,7 +230,7 @@ public static function getRequired(): array
230230
*
231231
* @return static[]
232232
*/
233-
public static function getCollection(string $url, int $limit, array $options, ClientInterface $client): static
233+
public static function getCollection(string $url, int $limit, array $options, ClientInterface $client): array
234234
{
235235
$items = static::getCollectionWithParent($url, $client, $options)['items'];
236236

src/Model/Backups/RestoreOptions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
class RestoreOptions
88
{
9-
private ?string $environmentName;
9+
private ?string $environmentName = null;
1010

11-
private ?string $branchFrom;
11+
private ?string $branchFrom = null;
1212

1313
private ?bool $restoreCode;
1414

src/Model/BasicProjectInfo.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ class BasicProjectInfo
2121

2222
public string $title;
2323

24-
public ?string $region;
24+
public ?string $region = null;
2525

26-
public ?string $subscription_id;
26+
public ?string $subscription_id = null;
2727

28-
public ?OrganizationRef $organization_ref;
28+
public ?OrganizationRef $organization_ref = null;
2929

30-
public ?string $created_at;
30+
public ?string $created_at = null;
3131

32-
public ?string $status;
32+
public ?string $status = null;
3333

3434
public ?string $organization_id;
3535

src/Model/CentralizedPermissions/UserExtendedAccess.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class UserExtendedAccess extends ResourceWithReferences
2727
/**
2828
* @return static[]
2929
*/
30-
public static function byUser(string $userId, array $options, ClientInterface $client): static
30+
public static function byUser(string $userId, array $options, ClientInterface $client): array
3131
{
3232
return self::getCollection('/users/' . rawurlencode($userId) . '/extended-access', 0, $options, $client);
3333
}

src/Model/CentralizedPermissions/UserProjectAccess.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class UserProjectAccess extends ResourceWithReferences
2424
/**
2525
* @return static[]
2626
*/
27-
public static function byUser(string $userId, array $options, ClientInterface $client): static
27+
public static function byUser(string $userId, array $options, ClientInterface $client): array
2828
{
2929
return self::getCollection('/users/' . rawurlencode($userId) . '/project-access', 0, $options, $client);
3030
}
Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,43 @@
11
<?php
22

33
declare(strict_types=1);
4-
/** @noinspection PhpUnusedPrivateFieldInspection */
54

65
namespace Platformsh\Client\Model\Subscription;
76

8-
final class SubscriptionOptions
7+
final readonly class SubscriptionOptions
98
{
10-
private ?string $project_region;
9+
private array $options;
1110

12-
private ?string $project_title;
13-
14-
private ?string $default_branch;
15-
16-
private ?string $options_url;
17-
18-
private ?array $options_custom;
19-
20-
private ?string $plan;
21-
22-
private ?int $environments;
23-
24-
private ?int $storage;
25-
26-
private ?string $owner;
11+
private function __construct(array $options)
12+
{
13+
$this->options = $options;
14+
}
2715

2816
/**
29-
* @deprecated This is no longer supported. Poll the subscription instead of submitting a callback.
17+
* @param array{
18+
* project_region: ?string,
19+
* project_title: ?string,
20+
* default_branch: ?string,
21+
* options_url: ?string,
22+
* options_custom: ?array,
23+
* plan: ?string,
24+
* environments: ?int,
25+
* storage: ?int,
26+
* organization_id: ?string,
27+
* } $options
3028
*/
31-
private ?array $activation_callback;
32-
33-
private ?string $organization_id;
34-
3529
public static function fromArray(array $options): self
3630
{
37-
$obj = new self();
38-
foreach ($options as $key => $value) {
39-
if (\property_exists($obj, $key)) {
40-
$obj->{$key} = $value;
41-
} else {
42-
throw new \InvalidArgumentException('Unknown property: ' . $key);
43-
}
44-
}
45-
return $obj;
31+
return new self($options);
4632
}
4733

4834
public function toArray(): array
4935
{
50-
$arr = [];
51-
foreach ($this as $key => $value) {
52-
if ($value !== null && $value !== 'organization_id') {
53-
$arr[$key] = $value;
54-
}
55-
}
56-
return $arr;
36+
return $this->options;
5737
}
5838

5939
public function organizationId(): ?string
6040
{
61-
return $this->organization_id;
41+
return $this->options['organization_id'] ?? null;
6242
}
6343
}

src/PlatformClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class PlatformClient
3838
/**
3939
* @var array|null A per-client cache for account info
4040
*/
41-
protected ?array $accountInfo;
41+
protected ?array $accountInfo = null;
4242

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

0 commit comments

Comments
 (0)