Skip to content

Commit 9d6de86

Browse files
committed
Typing responses for stricter typing
1 parent 3ec92e0 commit 9d6de86

21 files changed

+413
-116
lines changed

src/Data/SpaceData.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,6 @@ public function createdAt(): null|string
4848
return $this->getFormattedDateTime('created_at', "", format: "Y-m-d");
4949
}
5050

51-
public function updatedAt(): null|string
52-
{
53-
return $this->getFormattedDateTime('updated_at', "", format: "Y-m-d");
54-
}
55-
56-
5751

5852
public function planDescription(): null|string
5953
{

src/Data/SpacesData.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,7 @@ public static function make(array $data = []): self
1818
return new self($data);
1919
}
2020

21-
/**
22-
* @param array<string, array<mixed>> $data
23-
*/
24-
public static function makeFromResponse(array $data = []): self
25-
{
26-
return new self($data["spaces"] ?? []);
27-
}
21+
2822

2923

3024
public function howManySpaces(): int

src/Endpoints/AssetApi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Storyblok\ManagementApi\Data\StoryblokData;
1010
use Storyblok\ManagementApi\QueryParameters\AssetsParams;
1111
use Storyblok\ManagementApi\QueryParameters\PaginationParams;
12-
use Storyblok\ManagementApi\StoryblokResponseInterface;
12+
use Storyblok\ManagementApi\Response\StoryblokResponseInterface;
1313
use Symfony\Component\HttpClient\HttpClient;
1414

1515
/**

src/Endpoints/EndpointBase.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
use Psr\Log\NullLogger;
99
use Storyblok\ManagementApi\Data\StoryblokData;
1010
use Storyblok\ManagementApi\ManagementApiClient;
11-
use Storyblok\ManagementApi\StoryblokResponse;
12-
use Storyblok\ManagementApi\StoryblokResponseInterface;
11+
use Storyblok\ManagementApi\Response\StoryblokResponse;
12+
use Storyblok\ManagementApi\Response\StoryblokResponseInterface;
1313
use Symfony\Contracts\HttpClient\HttpClientInterface;
14+
use Symfony\Contracts\HttpClient\ResponseInterface;
1415

1516
/**
1617
* Class EndpointBase
@@ -38,12 +39,27 @@ public function makeRequest(
3839
array $options = [],
3940
string $dataClass = StoryblokData::class,
4041
): StoryblokResponseInterface {
41-
$response = $this->httpClient->request(
42+
$response = $this->makeHttpRequest(
4243
$method,
4344
$path,
4445
$options,
4546
);
46-
4747
return StoryblokResponse::make($response, $dataClass);
4848
}
49+
50+
/**
51+
* @param array<mixed> $options
52+
* @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
53+
*/
54+
public function makeHttpRequest(
55+
string $method,
56+
string $path,
57+
array $options = [],
58+
): ResponseInterface {
59+
return $this->httpClient->request(
60+
$method,
61+
$path,
62+
$options,
63+
);
64+
}
4965
}

src/Endpoints/ManagementApi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Storyblok\ManagementApi\Endpoints;
66

7-
use Storyblok\ManagementApi\StoryblokResponseInterface;
7+
use Storyblok\ManagementApi\Response\StoryblokResponseInterface;
88

99
/**
1010
*

src/Endpoints/SpaceApi.php

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,42 @@
77
use Storyblok\ManagementApi\Data\SpaceData;
88
use Storyblok\ManagementApi\Data\SpacesData;
99
use Storyblok\ManagementApi\Data\StoryblokData;
10-
use Storyblok\ManagementApi\StoryblokResponseInterface;
10+
use Storyblok\ManagementApi\Response\SpaceResponse;
11+
use Storyblok\ManagementApi\Response\SpacesResponse;
12+
use Storyblok\ManagementApi\Response\StoryblokResponse;
13+
use Storyblok\ManagementApi\Response\StoryblokResponseInterface;
1114

1215
/**
1316
*
1417
*/
1518
class SpaceApi extends EndpointBase
1619
{
17-
public function all(): StoryblokResponseInterface
20+
public function all(): SpacesResponse
1821
{
19-
return $this->makeRequest(
22+
$httpResponse = $this->makeHttpRequest(
2023
"GET",
2124
'/v1/spaces',
22-
dataClass: SpacesData::class,
2325
);
26+
return new SpacesResponse($httpResponse, SpacesData::class);
2427
}
2528

2629

27-
public function get(string $spaceId): StoryblokResponseInterface
30+
31+
32+
public function get(string $spaceId): SpaceResponse
2833
{
29-
return $this->makeRequest(
34+
$httpResponse = $this->makeHttpRequest(
3035
"GET",
3136
'/v1/spaces/' . $spaceId,
32-
dataClass: SpaceData::class,
3337
);
38+
return new SpaceResponse($httpResponse);
3439
}
3540

3641

37-
public function create(StoryblokData $storyblokData): StoryblokResponseInterface
42+
public function create(StoryblokData $storyblokData): SpaceResponse
3843
{
39-
return $this->makeRequest(
44+
45+
$httpResponse = $this->makeHttpRequest(
4046
"POST",
4147
"/v1/spaces",
4248
[
@@ -45,11 +51,12 @@ public function create(StoryblokData $storyblokData): StoryblokResponseInterface
4551
],
4652
],
4753
);
54+
return new SpaceResponse($httpResponse);
4855
}
4956

50-
public function duplicate(string|int $duplicateId, string $name): StoryblokResponseInterface
57+
public function duplicate(string|int $duplicateId, string $name): SpaceResponse
5158
{
52-
return $this->makeRequest(
59+
$httpResponse = $this->makeHttpRequest(
5360
"POST",
5461
"/v1/spaces",
5562
[
@@ -61,31 +68,34 @@ public function duplicate(string|int $duplicateId, string $name): StoryblokRespo
6168
],
6269
],
6370
);
71+
return new SpaceResponse($httpResponse);
6472
}
6573

6674
/**
6775
* @param $spaceId
6876
*/
69-
public function delete(string $spaceId): StoryblokResponseInterface
77+
public function delete(string $spaceId): SpaceResponse
7078
{
71-
return $this->makeRequest(
79+
$httpResponse = $this->makeHttpRequest(
7280
"DELETE",
7381
'/v1/spaces/' . $spaceId,
7482
);
83+
return new SpaceResponse($httpResponse);
7584
}
7685

7786
/**
7887
* @param $spaceId
7988
*/
80-
public function backup(string $spaceId): StoryblokResponseInterface
89+
public function backup(string $spaceId): SpaceResponse
8190
{
82-
return $this->makeRequest(
91+
$httpResponse = $this->makeHttpRequest(
8392
"POST",
8493
sprintf('/v1/spaces/%s/backups', $spaceId),
8594
[
8695
"body" => [
8796
],
8897
],
8998
);
99+
return new SpaceResponse($httpResponse);
90100
}
91101
}

src/Endpoints/StoryApi.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,17 @@
44

55
namespace Storyblok\ManagementApi\Endpoints;
66

7+
use Psr\Log\LoggerInterface;
78
use Psr\Log\NullLogger;
8-
use Storyblok\ManagementApi\ManagementApiClient;
9-
use Storyblok\ManagementApi\QueryParameters\Filters\QueryFilters;
10-
use Storyblok\ManagementApi\QueryParameters\PaginationParams;
11-
use Storyblok\ManagementApi\QueryParameters\StoriesParams;
12-
use Storyblok\ManagementApi\Data\StoryblokDataInterface;
13-
use Symfony\Contracts\HttpClient\HttpClientInterface;
149
use Storyblok\ManagementApi\Data\StoriesData;
1510
use Storyblok\ManagementApi\Data\StoryData;
1611
use Storyblok\ManagementApi\Exceptions\InvalidStoryDataException;
1712
use Storyblok\ManagementApi\Exceptions\StoryblokApiException;
18-
use Storyblok\ManagementApi\StoryblokResponseInterface;
19-
use Psr\Log\LoggerInterface;
13+
use Storyblok\ManagementApi\ManagementApiClient;
14+
use Storyblok\ManagementApi\QueryParameters\Filters\QueryFilters;
15+
use Storyblok\ManagementApi\QueryParameters\PaginationParams;
16+
use Storyblok\ManagementApi\QueryParameters\StoriesParams;
17+
use Storyblok\ManagementApi\Response\StoryblokResponseInterface;
2018

2119
/**
2220
* StoryApi handles all story-related operations in the Storyblok Management API

src/Endpoints/StoryBulkApi.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,17 @@
44

55
namespace Storyblok\ManagementApi\Endpoints;
66

7+
use Psr\Log\LoggerInterface;
78
use Psr\Log\NullLogger;
9+
use Storyblok\ManagementApi\Data\StoriesData;
10+
use Storyblok\ManagementApi\Data\StoryblokDataInterface;
11+
use Storyblok\ManagementApi\Data\StoryData;
12+
use Storyblok\ManagementApi\Exceptions\StoryblokApiException;
813
use Storyblok\ManagementApi\ManagementApiClient;
914
use Storyblok\ManagementApi\QueryParameters\Filters\QueryFilters;
1015
use Storyblok\ManagementApi\QueryParameters\PaginationParams;
1116
use Storyblok\ManagementApi\QueryParameters\StoriesParams;
12-
use Storyblok\ManagementApi\Data\StoryblokDataInterface;
13-
use Symfony\Contracts\HttpClient\HttpClientInterface;
14-
use Storyblok\ManagementApi\Data\StoriesData;
15-
use Storyblok\ManagementApi\Data\StoryData;
16-
use Storyblok\ManagementApi\Exceptions\InvalidStoryDataException;
17-
use Storyblok\ManagementApi\Exceptions\StoryblokApiException;
18-
use Storyblok\ManagementApi\StoryblokResponseInterface;
19-
use Psr\Log\LoggerInterface;
17+
use Storyblok\ManagementApi\Response\StoryblokResponseInterface;
2018

2119
/**
2220
* StoryApi handles all story-related operations in the Storyblok Management API

src/Endpoints/TagApi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use Storyblok\ManagementApi\Data\TagData;
88
use Storyblok\ManagementApi\Data\TagsData;
9-
use Storyblok\ManagementApi\StoryblokResponseInterface;
9+
use Storyblok\ManagementApi\Response\StoryblokResponseInterface;
1010

1111
/**
1212
*

src/Endpoints/UserApi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace Storyblok\ManagementApi\Endpoints;
66

77
use Storyblok\ManagementApi\Data\UserData;
8-
use Storyblok\ManagementApi\StoryblokResponseInterface;
8+
use Storyblok\ManagementApi\Response\StoryblokResponseInterface;
99

1010
/**
1111
*

0 commit comments

Comments
 (0)