@@ -17,47 +17,34 @@ class CachedClient implements IClient
1717{
1818 use Github \Strict;
1919
20- /** @var Storages\ICache|null */
21- private $ cache ;
20+ private IClient $ client ;
2221
23- /** @var IClient */
24- private $ client ;
25-
26- /** @var bool */
27- private $ forbidRecheck ;
28-
29- /** @var callable|null */
22+ /** @var ?callable(Response $response): void */
3023 private $ onResponse ;
3124
3225
3326 /**
34- * @param Storages\ICache
35- * @param IClient
36- * @param bool forbid checking Github for new data; more or less development purpose only
27+ * @param bool $forbidRecheck Forbid checking GitHub for new data; more or less development purpose only
3728 */
38- public function __construct (Storages \ICache $ cache , IClient $ client = null , $ forbidRecheck = false )
39- {
40- $ this ->cache = $ cache ;
29+ public function __construct (
30+ private Storages \ICache $ cache ,
31+ IClient $ client = null ,
32+ private bool $ forbidRecheck = false ,
33+ ) {
4134 $ this ->client = $ client ?: Github \Helpers::createDefaultClient ();
42- $ this ->forbidRecheck = (bool ) $ forbidRecheck ;
4335 }
4436
4537
46- /**
47- * @return IClient
48- */
49- public function getInnerClient ()
38+ public function getInnerClient (): IClient
5039 {
5140 return $ this ->client ;
5241 }
5342
5443
5544 /**
56- * @return Response
57- *
5845 * @throws BadResponseException
5946 */
60- public function request (Request $ request )
47+ public function request (Request $ request ): Response
6148 {
6249 $ request = clone $ request ;
6350
@@ -106,37 +93,29 @@ public function request(Request $request)
10693 }
10794
10895
109- /**
110- * @param callable|null function(Request $request)
111- * @return self
112- */
113- public function onRequest ($ callback )
96+ /** @inheritdoc */
97+ public function onRequest (?callable $ callback ): static
11498 {
11599 $ this ->client ->onRequest ($ callback );
116100 return $ this ;
117101 }
118102
119103
120- /**
121- * @param callable|null function(Response $response)
122- * @return self
123- */
124- public function onResponse ($ callback )
104+ /** @inheritdoc */
105+ public function onResponse (?callable $ callback ): static
125106 {
126107 $ this ->client ->onResponse (null );
127108 $ this ->onResponse = $ callback ;
128109 return $ this ;
129110 }
130111
131112
132- /**
133- * @return bool
134- */
135- protected function isCacheable (Response $ response )
113+ protected function isCacheable (Response $ response ): bool
136114 {
137115 /** @todo Do it properly. Vary:, Pragma:, TTL... */
138116 if (!$ response ->isCode (200 )) {
139117 return false ;
118+
140119 } elseif (preg_match ('#max-age=0|must-revalidate#i ' , $ response ->getHeader ('Cache-Control ' , '' ))) {
141120 return false ;
142121 }
0 commit comments