@@ -128,11 +128,9 @@ public function getLocale(): ?string
128128 return $ this ->locale ;
129129 }
130130
131- public function localeAlternate (? string $ locale ): self
131+ public function localeAlternate (string $ locale ): self
132132 {
133- if (null !== $ locale ) {
134- $ this ->localeAlternates [] = $ locale ;
135- }
133+ $ this ->localeAlternates [] = $ locale ;
136134
137135 return $ this ;
138136 }
@@ -160,14 +158,10 @@ public function getSiteName(): ?string
160158 /**
161159 * Add an image to represent your object.
162160 *
163- * @param Image|string|null $image Image object or URL
161+ * @param Image|string $image Image object or URL
164162 */
165- public function image (Image |string | null $ image ): self
163+ public function image (Image |string $ image ): self
166164 {
167- if (null === $ image ) {
168- return $ this ;
169- }
170-
171165 if (is_string ($ image )) {
172166 $ image = new Image ($ image );
173167 }
@@ -188,14 +182,10 @@ public function getImages(): array
188182 /**
189183 * Add a video to complement your object.
190184 *
191- * @param Video|string|null $video Video object or URL
185+ * @param Video|string $video Video object or URL
192186 */
193- public function video (Video |string | null $ video ): self
187+ public function video (Video |string $ video ): self
194188 {
195- if (null === $ video ) {
196- return $ this ;
197- }
198-
199189 if (is_string ($ video )) {
200190 $ video = new Video ($ video );
201191 }
@@ -216,14 +206,10 @@ public function getVideos(): array
216206 /**
217207 * Add an audio file to complement your object.
218208 *
219- * @param Audio|string|null $audio Audio object or URL
209+ * @param Audio|string $audio Audio object or URL
220210 */
221- public function audio (Audio |string | null $ audio ): self
211+ public function audio (Audio |string $ audio ): self
222212 {
223- if (null === $ audio ) {
224- return $ this ;
225- }
226-
227213 if (is_string ($ audio )) {
228214 $ audio = new Audio ($ audio );
229215 }
@@ -248,37 +234,16 @@ public function getAudios(): array
248234 */
249235 public function toArray (): array
250236 {
251- $ data = [];
252-
253- if (null !== $ this ->title ) {
254- $ data ['og:title ' ] = $ this ->title ;
255- }
256-
257- $ data ['og:type ' ] = $ this ->type ->getType ();
258-
259- if (null !== $ this ->url ) {
260- $ data ['og:url ' ] = $ this ->url ;
261- }
262-
263- if (null !== $ this ->description ) {
264- $ data ['og:description ' ] = $ this ->description ;
265- }
266-
267- if (null !== $ this ->determiner ) {
268- $ data ['og:determiner ' ] = $ this ->determiner ;
269- }
270-
271- if (null !== $ this ->locale ) {
272- $ data ['og:locale ' ] = $ this ->locale ;
273- }
274-
275- if ([] !== $ this ->localeAlternates ) {
276- $ data ['og:locale:alternate ' ] = $ this ->localeAlternates ;
277- }
278-
279- if (null !== $ this ->siteName ) {
280- $ data ['og:site_name ' ] = $ this ->siteName ;
281- }
237+ $ data = array_filter ([
238+ 'og:title ' => $ this ->title ,
239+ 'og:type ' => $ this ->type ->getType (),
240+ 'og:url ' => $ this ->url ,
241+ 'og:description ' => $ this ->description ,
242+ 'og:determiner ' => $ this ->determiner ,
243+ 'og:locale ' => $ this ->locale ,
244+ 'og:locale:alternate ' => [] !== $ this ->localeAlternates ? $ this ->localeAlternates : null ,
245+ 'og:site_name ' => $ this ->siteName ,
246+ ], static fn ($ value ) => null !== $ value );
282247
283248 foreach ($ this ->images as $ image ) {
284249 foreach ($ image ->toArray () as $ property => $ value ) {
0 commit comments