Skip to content

Commit

Permalink
[fix] add null-coalescing operator to setViews method
Browse files Browse the repository at this point in the history
API (`instagram plugin`) returns `reels` with `view count` equals to `null`. But in `setViews` function in `reelsBaseHydrator` `view count` can't be a `null` (only `int` can be set). This leads to `exception`.

This update just adds `null-coalescing operator` for this case, and if `view count` will be equals to `null`, it will be set to `0`.
  • Loading branch information
deevanych committed Nov 26, 2024
1 parent 8e39f0f commit 9840470
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ cache/
!assets/.gitkeep
assets/

.php-cs-fixer.cache
.php-cs-fixer.cache

.idea
2 changes: 1 addition & 1 deletion src/Instagram/Hydrator/ReelsHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function reelsBaseHydrator(\StdClass $node): Reels
$reels->setDate(\DateTime::createFromFormat('U', (string) $node->taken_at));
$reels->setLikes($node->like_count);
$reels->setIsLiked($node->has_liked);
$reels->setViews($node->view_count);
$reels->setViews($node->view_count ?? 0);
$reels->setPlays($node->play_count);
$reels->setDuration($node->video_duration);
$reels->setHeight($node->original_height);
Expand Down

0 comments on commit 9840470

Please sign in to comment.