@@ -11,6 +11,7 @@ class Subscription extends Resource
1111{
1212 protected const ATTRIBUTES = [
1313 'id ' ,
14+ 'project_id ' ,
1415 'endpoint ' ,
1516 'p256dh ' ,
1617 'auth ' ,
@@ -23,6 +24,7 @@ class Subscription extends Resource
2324
2425 protected const READ_ONLY_ATTRIBUTES = [
2526 'id ' ,
27+ 'project_id ' ,
2628 'last_click_at ' ,
2729 'created_at ' ,
2830 'project_id ' ,
@@ -58,7 +60,7 @@ public static function findAll(array $query = [], ?int $projectId = null): array
5860 $ items = $ response ['body ' ];
5961
6062 return array_map (
61- fn (array $ item ) => new self (self :: injectProjectId ( $ item, $ resolvedProjectId ) ),
63+ fn (array $ item ) => new self ($ item ),
6264 $ items
6365 );
6466 }
@@ -104,7 +106,7 @@ public static function find(int $subscriptionId, ?int $projectId = null): self
104106 self ::ensureStatus ($ response , 200 );
105107 $ data = $ response ['body ' ];
106108
107- return new self (self :: injectProjectId ( $ data, $ resolvedProjectId ) );
109+ return new self ($ data );
108110 }
109111
110112 /**
@@ -124,7 +126,7 @@ public static function create(array $payload, ?int $projectId = null): self
124126 self ::ensureStatus ($ response , 201 );
125127 $ data = $ response ['body ' ];
126128
127- return new self (self :: injectProjectId ( $ data, $ resolvedProjectId ) );
129+ return new self ($ data );
128130 }
129131
130132 /**
@@ -138,7 +140,7 @@ public function refresh(?int $projectId = null): self
138140 $ response = self ::httpGet ("/projects/ {$ project }/subscriptions/ {$ this ->requireId ()}" );
139141 self ::ensureStatus ($ response , 200 );
140142 $ data = $ response ['body ' ];
141- $ this ->setAttributes (self :: injectProjectId ( $ data, $ project ) );
143+ $ this ->setAttributes ($ data );
142144 return $ this ;
143145 }
144146
@@ -158,7 +160,7 @@ public function update(array $payload, ?int $projectId = null): self
158160 ]);
159161 self ::ensureStatus ($ response , 200 );
160162 $ data = $ response ['body ' ];
161- $ this ->setAttributes (self :: injectProjectId ( $ data, $ project ) );
163+ $ this ->setAttributes ($ data );
162164 return $ this ;
163165 }
164166
@@ -181,28 +183,16 @@ public function delete(?int $projectId = null): void
181183 */
182184 private function determineProjectId (?int $ projectId = null ): int
183185 {
184- if ($ projectId !== null ) {
185- return $ projectId ;
186- }
187-
188186 if (isset ($ this ->attributes ['project_id ' ])) {
189187 return (int ) $ this ->attributes ['project_id ' ];
190188 }
191189
192- return Pushpad::resolveProjectId (null );
190+ return Pushpad::resolveProjectId ($ projectId );
193191 }
194192
195193 /**
196194 * @param array<string, mixed> $data
197195 * @param int $projectId
198196 * @return array<string, mixed>
199197 */
200- private static function injectProjectId (array $ data , int $ projectId ): array
201- {
202- if (!isset ($ data ['project_id ' ])) {
203- $ data ['project_id ' ] = $ projectId ;
204- }
205-
206- return $ data ;
207- }
208198}
0 commit comments