22
33namespace RicardoFiorani \Validator ;
44
5- use GuzzleHttp \Client ;
6- use GuzzleHttp \ClientInterface ;
5+ use GuzzleHttp \Psr7 \ Request ;
6+ use Psr \ Http \ Client \ClientInterface ;
77use RicardoFiorani \Validator \Response \ValidationResponseFactory ;
88use RicardoFiorani \Validator \Response \ValidationResponseInterface ;
99
@@ -14,49 +14,45 @@ class Validator implements ValidatorInterface
1414 /**
1515 * @var ClientInterface
1616 */
17- private $ client ;
17+ private $ httpClient ;
1818
19- public function __construct (?ClientInterface $ client = null )
20- {
21- if (is_null ($ client )) {
22- $ client = new Client ();
23- }
19+ /**
20+ * @var ValidationResponseFactory
21+ */
22+ private $ responseFactory ;
2423
25- $ this ->setClient ($ client );
24+ public function __construct (ClientInterface $ httpClient )
25+ {
26+ $ this ->setHttpClient ($ httpClient );
27+ $ this ->responseFactory = new ValidationResponseFactory ();
2628 }
2729
28- public function setClient (ClientInterface $ client )
30+ public function setHttpClient (ClientInterface $ httpClient )
2931 {
30- $ this ->client = $ client ;
32+ $ this ->httpClient = $ httpClient ;
3133 }
3234
3335 /**
34- * @throws \GuzzleHttp\Exception\GuzzleException
36+ * @throws \Psr\Http\Client\ClientExceptionInterface
3537 */
3638 public function validateUrl (string $ url ): ValidationResponseInterface
3739 {
3840 $ url = $ this ->normaliseUrl ($ url );
39- $ response = $ this ->client ->request ('GET ' , self ::CLOUDFLARE_AMP_VALIDATOR_ENDPOINT . $ url );
41+ $ request = new Request ('GET ' , self ::CLOUDFLARE_AMP_VALIDATOR_ENDPOINT . $ url );
42+ $ response = $ this ->httpClient ->sendRequest ($ request );
4043
41- return ValidationResponseFactory:: createFromGuzzleResponse ($ response );
44+ return $ this -> responseFactory -> create ($ response );
4245 }
4346
4447 /**
45- * @param string $content
46- * @return ValidationResponseInterface
47- * @throws \GuzzleHttp\Exception\GuzzleException
48+ * @throws \Psr\Http\Client\ClientExceptionInterface
4849 */
4950 public function validateContent (string $ content ): ValidationResponseInterface
5051 {
51- $ response = $ this ->client ->request (
52- 'POST ' ,
53- self ::CLOUDFLARE_AMP_VALIDATOR_ENDPOINT ,
54- [
55- 'body ' => $ content ,
56- ]
57- );
52+ $ request = new Request ('POST ' , self ::CLOUDFLARE_AMP_VALIDATOR_ENDPOINT , [], $ content );
53+ $ response = $ this ->httpClient ->sendRequest ($ request );
5854
59- return ValidationResponseFactory:: createFromGuzzleResponse ($ response );
55+ return $ this -> responseFactory -> create ($ response );
6056 }
6157
6258 private function normaliseUrl (string $ url ): string
0 commit comments