77use Psr \Log \LoggerInterface ;
88use Symfony \Component \HttpClient \HttpClient ;
99use Symfony \Contracts \HttpClient \Exception \TransportExceptionInterface ;
10+ use Mooore \WordpressIntegrationCms \Exception \HTTPClientTypeRequiredException ;
1011
1112abstract class Wordpress
1213{
@@ -49,11 +50,12 @@ public function setBaseUrl(string $baseUrl)
4950 * @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface
5051 * @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface
5152 * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
53+ * @throws HTTPClientTypeRequiredException
5254 */
5355 public function all (int $ pageSize = 10 , array $ filters = []): \Generator
5456 {
5557 if (is_null ($ this ->type )) {
56- throw new \ Exception ("Type is required for HTTPClient " );
58+ throw new HTTPClientTypeRequiredException ("Type is required for HTTPClient " );
5759 }
5860 $ peekHeaders = $ this ->peek ($ pageSize );
5961
@@ -95,22 +97,26 @@ public function all(int $pageSize = 10, array $filters = []): \Generator
9597 * @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface
9698 * @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface
9799 * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
100+ * @throws HTTPClientTypeRequiredException
98101 */
99102 public function get (int $ id ): array
100103 {
101104 if (is_null ($ this ->type )) {
102- throw new \ Exception ("Type is required for HTTPClient " );
105+ throw new HTTPClientTypeRequiredException ("Type is required for HTTPClient " );
103106 }
104107
105108 $ response = $ this ->client ->request ('GET ' , static ::WP_JSON_URL_PREFIX . $ this ->type . '/ ' . $ id );
106109
107110 return json_decode ($ response ->getContent (), true );
108111 }
109112
113+ /**
114+ * @throws HTTPClientTypeRequiredException
115+ */
110116 public function postMetaDataToPage (int $ pageId , string $ key , string $ value , string $ authentication )
111117 {
112118 if (is_null ($ this ->type )) {
113- throw new \ Exception ("Type is required for HTTPClient " );
119+ throw new HTTPClientTypeRequiredException ("Type is required for HTTPClient " );
114120 }
115121
116122 try {
@@ -136,11 +142,12 @@ public function postMetaDataToPage(int $pageId, string $key, string $value, stri
136142 * @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface
137143 * @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface
138144 * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
145+ * @throws HTTPClientTypeRequiredException
139146 */
140147 public function peek (int $ pageSize ): array
141148 {
142149 if (is_null ($ this ->type )) {
143- throw new \ Exception ("Type is required for HTTPClient " );
150+ throw new HTTPClientTypeRequiredException ("Type is required for HTTPClient " );
144151 }
145152
146153 $ peekResponse = $ this ->client ->request ('HEAD ' , static ::WP_JSON_URL_PREFIX . $ this ->type . '?per_page= ' . $ pageSize );
0 commit comments