mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-05 07:52:34 +00:00
Add phpstan level 7(#544)
This commit is contained in:
@ -49,7 +49,7 @@ public function data(array $input): array
|
||||
* @throws CouldNotConnectToProvider
|
||||
* @throws ConnectionException
|
||||
*/
|
||||
public function connect(?array $credentials = null): bool
|
||||
public function connect(array $credentials): bool
|
||||
{
|
||||
$connect = Http::withToken($credentials['token'])->get($this->apiUrl.'/servers');
|
||||
if (! $connect->ok()) {
|
||||
@ -62,25 +62,25 @@ public function connect(?array $credentials = null): bool
|
||||
public function plans(?string $region): array
|
||||
{
|
||||
try {
|
||||
/** @var array{server_types?: array<int, array{name: string, cores: int, memory: int, disk: int, prices: array<int, array{location: string}>}>} $plans */
|
||||
$plans = Http::withToken($this->serverProvider->credentials['token'])
|
||||
->get($this->apiUrl.'/server_types', ['per_page' => 50])
|
||||
->json();
|
||||
|
||||
return collect($plans['server_types'])->filter(function ($type) use ($region) {
|
||||
return collect($type['prices'])->filter(function ($price) use ($region) {
|
||||
return $price['location'] === $region;
|
||||
});
|
||||
})
|
||||
->mapWithKeys(function ($value) {
|
||||
return [
|
||||
$value['name'] => __('server_providers.plan', [
|
||||
'name' => $value['name'],
|
||||
'cpu' => $value['cores'],
|
||||
'memory' => $value['memory'],
|
||||
'disk' => $value['disk'],
|
||||
]),
|
||||
];
|
||||
})
|
||||
/** @var array<int, array{name: string, cores: int, memory: int, disk: int, prices: array<int, array{location: string}>}> $serverTypes */
|
||||
$serverTypes = $plans['server_types'] ?? [];
|
||||
|
||||
return collect($serverTypes)
|
||||
->filter(fn (array $type): bool => collect($type['prices'])->contains(fn (array $price): bool => $price['location'] === $region)
|
||||
)
|
||||
->mapWithKeys(fn (array $value): array => [
|
||||
$value['name'] => __('server_providers.plan', [
|
||||
'name' => $value['name'],
|
||||
'cpu' => $value['cores'],
|
||||
'memory' => $value['memory'],
|
||||
'disk' => $value['disk'],
|
||||
]),
|
||||
])
|
||||
->toArray();
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
@ -94,8 +94,11 @@ public function regions(): array
|
||||
->get($this->apiUrl.'/locations', ['per_page' => 50])
|
||||
->json();
|
||||
|
||||
return collect($regions['locations'])
|
||||
->mapWithKeys(fn ($value) => [$value['name'] => $value['city'].' - '.$value['country']])
|
||||
/** @var array<int, array{name: string, city: string, country: string}> $locations */
|
||||
$locations = $regions['locations'];
|
||||
|
||||
return collect($locations)
|
||||
->mapWithKeys(fn (array $value): array => [$value['name'] => $value['city'].' - '.$value['country']])
|
||||
->toArray();
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
|
Reference in New Issue
Block a user