diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index e8d7871..7068a9e 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -9,7 +9,7 @@ jobs: strategy: matrix: - php: [ '7.2', '7.3', '7.4', '8', '8.1', '8.2', '8.3'] + php: ['8.2', '8.3'] steps: - name: "Init repository" @@ -26,9 +26,10 @@ jobs: run: composer install - name: "Tests" - run: php vendor/bin/phpunit tests --whitelist src --coverage-clover ./build/logs/clover.xml + run: composer tests - - name: "Coveralls" - run: php vendor/bin/php-coveralls -v - env: - COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: "CS Fix" + run: composer cs-fix + + - name: "Phpstan" + run: composer phpstan diff --git a/.gitignore b/.gitignore index 75d66f5..5392461 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,6 @@ cache/ .phpunit.result.cache !assets/.gitkeep -assets/ \ No newline at end of file +assets/ + +.php-cs-fixer.cache \ No newline at end of file diff --git a/README.md b/README.md index 6675188..4f9eb2c 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,9 @@ [![All Contributors](https://img.shields.io/badge/all_contributors-30-orange.svg)](#contributors) +> **Warning** +> 2023-12-31 - Version 7.0.0 will drop support for PHP < 8.2 + > **Warning** > 2022-11-09 - Instagram changed his DOM AGAIN... Please update to this version 6.16.4 @@ -62,6 +65,10 @@ composer require pgrimaud/instagram-user-feed # Changelog +**v7.0.0** - 2023-12-31: + +- Drop support for PHP < 8.2 + **v6.16.6** - 2023-12-31: - Add support for Symfony 7 diff --git a/composer.json b/composer.json index 9abfd92..31f8849 100644 --- a/composer.json +++ b/composer.json @@ -37,18 +37,21 @@ } }, "require": { - "php": ">=7.2.5", + "php": ">=8.2", "ext-curl": "*", "ext-json": "*", - "symfony/cache": "^3.4|^4.3|^5.0|^6.0|^7.0", - "guzzlehttp/guzzle": "^6.0|^7.0" + "symfony/cache": "^6.0|^7.0", + "guzzlehttp/guzzle": "^7.0" }, "require-dev": { - "php-coveralls/php-coveralls": "^2.2", - "phpunit/phpunit": "^8.5|^9.5", - "symfony/var-dumper": "^5.0|^6.0|^7.0" + "phpunit/phpunit": "^9.5", + "symfony/var-dumper": "^6.0|^7.0", + "phpstan/phpstan": "^1.10", + "friendsofphp/php-cs-fixer": "^3.45" }, "scripts": { - "test": "phpunit tests --whitelist src" + "tests": "vendor/bin/phpunit tests --whitelist src --coverage-clover ./build/logs/clover.xml", + "phpstan": "vendor/bin/phpstan analyze src examples tests --level max", + "cs-fix": "vendor/bin/php-cs-fixer fix src --rules=@PSR12" } } diff --git a/src/Instagram/Api.php b/src/Instagram/Api.php index 7672069..b3b9bec 100644 --- a/src/Instagram/Api.php +++ b/src/Instagram/Api.php @@ -150,7 +150,7 @@ public function login(string $username, string $password, ?ImapClient $imapClien { $login = new Login($this->client, $username, $password, $imapClient, $this->challengeDelay); - if ( !($this->cachePool instanceof CacheItemPoolInterface) ) { + if (!($this->cachePool instanceof CacheItemPoolInterface)) { throw new InstagramAuthException('You must set cachePool / login with cookies, example: \n$cachePool = new \Symfony\Component\Cache\Adapter\FilesystemAdapter("Instagram", 0, __DIR__ . "/../cache"); \n$api = new \Instagram\Api($cachePool);'); } @@ -775,7 +775,7 @@ public function getTimeline(string $maxId = null): TimelineFeed return $hydrator->getTimelineFeed(); } - + /** * @param string $user * diff --git a/src/Instagram/Auth/Checkpoint/ImapClient.php b/src/Instagram/Auth/Checkpoint/ImapClient.php index 669ab27..80c90e6 100644 --- a/src/Instagram/Auth/Checkpoint/ImapClient.php +++ b/src/Instagram/Auth/Checkpoint/ImapClient.php @@ -103,7 +103,7 @@ public function getLastInstagramEmailContent(int $try = 1): string $resource = @imap_open('{' . $this->getServer() . '/' . $this->getConnectionType() . '/ssl}INBOX', $this->getLogin(), $this->getPassword()); if (!$resource) { - throw new InstagramAuthException('Unable to open IMAP stream.'); + throw new InstagramAuthException('Unable to open IMAP stream.'); } $numberMax = imap_num_msg($resource); diff --git a/src/Instagram/Auth/Login.php b/src/Instagram/Auth/Login.php index f5094b1..eb02ee9 100644 --- a/src/Instagram/Auth/Login.php +++ b/src/Instagram/Auth/Login.php @@ -115,7 +115,7 @@ public function process(): CookieJar if (property_exists($response, 'authenticated') && $response->authenticated == true) { return $cookieJar; - } else if (property_exists($response, 'error_type') && $response->error_type === 'generic_request_error') { + } elseif (property_exists($response, 'error_type') && $response->error_type === 'generic_request_error') { throw new InstagramAuthException('Generic error / Your IP may be block from Instagram. You should consider using a proxy.'); } else { throw new InstagramAuthException('Wrong login / password'); diff --git a/src/Instagram/Auth/Session.php b/src/Instagram/Auth/Session.php index d3ea363..4fa5f00 100644 --- a/src/Instagram/Auth/Session.php +++ b/src/Instagram/Auth/Session.php @@ -8,7 +8,7 @@ class Session { - const SESSION_KEY = 'instagram.session'; + public const SESSION_KEY = 'instagram.session'; /** * @var CookieJar diff --git a/src/Instagram/Hydrator/CarouselHydrator.php b/src/Instagram/Hydrator/CarouselHydrator.php index 3c6ea02..e3998ac 100644 --- a/src/Instagram/Hydrator/CarouselHydrator.php +++ b/src/Instagram/Hydrator/CarouselHydrator.php @@ -85,7 +85,7 @@ public function carouselMediaHydrator(array $carouselItems): array 'width' => $carouselItem->original_width, 'height' => $carouselItem->original_height, ]; - + if (property_exists($carouselItem, 'image_versions2')) { $carouselMedia['image'] = $carouselItem->image_versions2->candidates; } @@ -97,11 +97,11 @@ public function carouselMediaHydrator(array $carouselItems): array if (property_exists($carouselItem, 'video_duration')) { $carouselMedia['duration'] = $carouselItem->video_duration; } - + if (property_exists($carouselItem, 'accessibility_caption')) { $carouselMedia['accessibilityCaption'] = $carouselItem->accessibility_caption; } - + if (property_exists($carouselItem, 'number_of_qualities')) { $carouselMedia['quality'] = $carouselItem->number_of_qualities; } @@ -114,7 +114,7 @@ public function carouselMediaHydrator(array $carouselItems): array /** * @param int $media_type - * + * * @return string * @throws InstagramFetchException */ diff --git a/src/Instagram/Hydrator/ImageHydrator.php b/src/Instagram/Hydrator/ImageHydrator.php index 358629e..1a6cde7 100644 --- a/src/Instagram/Hydrator/ImageHydrator.php +++ b/src/Instagram/Hydrator/ImageHydrator.php @@ -35,7 +35,7 @@ public function imageBaseHydrator(\StdClass $node): Image $image->setDate(\DateTime::createFromFormat('U', (string) $node->taken_at)); $image->setLikes($node->like_count); $image->setIsLiked($node->has_liked); - + $image->setHeight($node->original_height); $image->setWidth($node->original_width); diff --git a/src/Instagram/Hydrator/MediaDetailedHydrator.php b/src/Instagram/Hydrator/MediaDetailedHydrator.php index 5d3a0de..0ceaa5e 100644 --- a/src/Instagram/Hydrator/MediaDetailedHydrator.php +++ b/src/Instagram/Hydrator/MediaDetailedHydrator.php @@ -1,220 +1,223 @@ -isCarousel($node) - ? $this->mediaDetailedCarouselHydrator($media, $node) - : $this->mediaDetailedDataHydrator($media, $node); - } - - /** - * @param Media $media - * @param \StdClass $node - * - * @return Media|MediaDetailed - * @throws InstagramFetchException - */ - public function mediaBaseHydrator(Media $media, \StdClass $node): Media - { - $media->setId((int) $node->pk); - $media->setShortCode($node->code); - - $media->setTypeName($this->getTypeName($node->media_type)); - - if ($node->caption) { - $media->setCaption($node->caption->text); - $media->setHashtags(InstagramHelper::buildHashtags($node->caption->text)); - - $date = new \DateTime(); - $date->setTimestamp($node->caption->created_at); - - $media->setDate($date); - } else { - if ($node->taken_at) { - $date = new \DateTime(); - $date->setTimestamp($node->taken_at); - $media->setDate($date); - } - } - - $thumbnailSrc = $displaySrc = ''; - if (property_exists($node, 'image_versions2')) { - foreach ($node->image_versions2->candidates as $img) { - if ($img->width == 640) - $thumbnailSrc = $img->url; - - if ($img->width == $node->original_width) - $displaySrc = $img->url; - } - } - - $media->setThumbnailSrc($thumbnailSrc); - $media->setDisplaySrc($displaySrc); - - if (property_exists($node, 'comment_count')) { - $media->setComments($node->comment_count); - } - - if (property_exists($node, 'like_count')) { - $media->setLikes($node->like_count); - } - - $media->setLink(InstagramHelper::URL_BASE . "p/{$node->code}/"); - - if (isset($node->location)) { - $media->setLocation($node->location); - } - - $media->setVideo($this->isVideo($node)); - - if (property_exists($node, 'video_versions')) { - foreach ($node->video_versions as $video) { - if ($video->type == 101) { - $videoSrc = $video->url; - } - } - $media->setVideoUrl($videoSrc ?? null); - } - - if (property_exists($node, 'view_count')) { - $media->setVideoViewCount((int) $node->view_count); - } - - if (property_exists($node, 'product_type')) { - $media->setIgtv($node->product_type === 'igtv'); - } - - $media->setOwnerId((int) $node->user->pk); - - return $media; - } - - - /** - * @param MediaDetailed $media - * @param \StdClass $node - * - * @return MediaDetailed - */ - private function mediaDetailedDataHydrator(MediaDetailed $media, \StdClass $node): Media - { - $media->setDisplayResources($node->image_versions2->candidates); - - $media->setHeight($node->original_height); - $media->setWidth($node->original_width); - - if ($this->isVideo($node)) { - $media->setHasAudio($node->has_audio); - } - - if (property_exists($node, 'usertags')) { - $taggedUsers = []; - foreach ($node->usertags->in as $user) { - $taggedUsers[] = $user->user; - } - - $media->setTaggedUsers($taggedUsers); - } - - return $media; - } - - /** - * @param MediaDetailed $media - * @param \StdClass $node - * - * @return MediaDetailed - * @throws InstagramFetchException - */ - private function mediaDetailedCarouselHydrator(MediaDetailed $media, \StdClass $node): Media - { - $scItems = []; - foreach ($node->carousel_media as $key => $item) { - $scItem = new MediaDetailed(); - $scItem->setId((int) $item->pk); - $scItem->setShortCode($node->code); - $scItem->setHeight($item->original_height); - $scItem->setWidth($item->original_width); - $scItem->setTypeName($this->getTypeName($item->media_type)); - $scItem->setDisplayResources($item->image_versions2->candidates); - - $scItem->setVideo($this->isVideo($node)); - - if (property_exists($item, 'video_versions')) { - foreach ($item->video_versions as $video) { - if ($video->type == 101) { - $videoSrc = $video->url; - } - } - $scItem->setVideoUrl($videoSrc ?? null); - } - - $scItems[] = $scItem; - - if ($key == 0) - $media->setDisplayResources($item->image_versions2->candidates); - } - - $media->setSideCarItems($scItems); - - return $media; - } - - /** - * @param int $media_type - * @return string - * @throws InstagramFetchException - */ - private function getTypeName(int $media_type): string - { - switch ($media_type) { - case Media::MEDIA_TYPE_IMAGE: - $type = Media::TYPE_IMAGE; - break; - case Media::MEDIA_TYPE_VIDEO: - $type = Media::TYPE_VIDEO; - break; - case Media::MEDIA_TYPE_CAROUSEL: - $type = Media::TYPE_CAROUSEL; - break; - default: - throw new InstagramFetchException('Media type ' . $media_type . ' not found'); - } - - return $type; - } - - /** - * @param \StdClass $node - * @return bool - */ - private function isCarousel(\StdClass $node): bool - { - return $node->media_type === Media::MEDIA_TYPE_CAROUSEL; - } - - /** - * @param \StdClass $node - * @return bool - */ - private function isVideo(\StdClass $node): bool - { - return $node->media_type === Media::MEDIA_TYPE_VIDEO; - } -} +isCarousel($node) + ? $this->mediaDetailedCarouselHydrator($media, $node) + : $this->mediaDetailedDataHydrator($media, $node); + } + + /** + * @param Media $media + * @param \StdClass $node + * + * @return Media|MediaDetailed + * @throws InstagramFetchException + */ + public function mediaBaseHydrator(Media $media, \StdClass $node): Media + { + $media->setId((int) $node->pk); + $media->setShortCode($node->code); + + $media->setTypeName($this->getTypeName($node->media_type)); + + if ($node->caption) { + $media->setCaption($node->caption->text); + $media->setHashtags(InstagramHelper::buildHashtags($node->caption->text)); + + $date = new \DateTime(); + $date->setTimestamp($node->caption->created_at); + + $media->setDate($date); + } else { + if ($node->taken_at) { + $date = new \DateTime(); + $date->setTimestamp($node->taken_at); + $media->setDate($date); + } + } + + $thumbnailSrc = $displaySrc = ''; + if (property_exists($node, 'image_versions2')) { + foreach ($node->image_versions2->candidates as $img) { + if ($img->width == 640) { + $thumbnailSrc = $img->url; + } + + if ($img->width == $node->original_width) { + $displaySrc = $img->url; + } + } + } + + $media->setThumbnailSrc($thumbnailSrc); + $media->setDisplaySrc($displaySrc); + + if (property_exists($node, 'comment_count')) { + $media->setComments($node->comment_count); + } + + if (property_exists($node, 'like_count')) { + $media->setLikes($node->like_count); + } + + $media->setLink(InstagramHelper::URL_BASE . "p/{$node->code}/"); + + if (isset($node->location)) { + $media->setLocation($node->location); + } + + $media->setVideo($this->isVideo($node)); + + if (property_exists($node, 'video_versions')) { + foreach ($node->video_versions as $video) { + if ($video->type == 101) { + $videoSrc = $video->url; + } + } + $media->setVideoUrl($videoSrc ?? null); + } + + if (property_exists($node, 'view_count')) { + $media->setVideoViewCount((int) $node->view_count); + } + + if (property_exists($node, 'product_type')) { + $media->setIgtv($node->product_type === 'igtv'); + } + + $media->setOwnerId((int) $node->user->pk); + + return $media; + } + + + /** + * @param MediaDetailed $media + * @param \StdClass $node + * + * @return MediaDetailed + */ + private function mediaDetailedDataHydrator(MediaDetailed $media, \StdClass $node): Media + { + $media->setDisplayResources($node->image_versions2->candidates); + + $media->setHeight($node->original_height); + $media->setWidth($node->original_width); + + if ($this->isVideo($node)) { + $media->setHasAudio($node->has_audio); + } + + if (property_exists($node, 'usertags')) { + $taggedUsers = []; + foreach ($node->usertags->in as $user) { + $taggedUsers[] = $user->user; + } + + $media->setTaggedUsers($taggedUsers); + } + + return $media; + } + + /** + * @param MediaDetailed $media + * @param \StdClass $node + * + * @return MediaDetailed + * @throws InstagramFetchException + */ + private function mediaDetailedCarouselHydrator(MediaDetailed $media, \StdClass $node): Media + { + $scItems = []; + foreach ($node->carousel_media as $key => $item) { + $scItem = new MediaDetailed(); + $scItem->setId((int) $item->pk); + $scItem->setShortCode($node->code); + $scItem->setHeight($item->original_height); + $scItem->setWidth($item->original_width); + $scItem->setTypeName($this->getTypeName($item->media_type)); + $scItem->setDisplayResources($item->image_versions2->candidates); + + $scItem->setVideo($this->isVideo($node)); + + if (property_exists($item, 'video_versions')) { + foreach ($item->video_versions as $video) { + if ($video->type == 101) { + $videoSrc = $video->url; + } + } + $scItem->setVideoUrl($videoSrc ?? null); + } + + $scItems[] = $scItem; + + if ($key == 0) { + $media->setDisplayResources($item->image_versions2->candidates); + } + } + + $media->setSideCarItems($scItems); + + return $media; + } + + /** + * @param int $media_type + * @return string + * @throws InstagramFetchException + */ + private function getTypeName(int $media_type): string + { + switch ($media_type) { + case Media::MEDIA_TYPE_IMAGE: + $type = Media::TYPE_IMAGE; + break; + case Media::MEDIA_TYPE_VIDEO: + $type = Media::TYPE_VIDEO; + break; + case Media::MEDIA_TYPE_CAROUSEL: + $type = Media::TYPE_CAROUSEL; + break; + default: + throw new InstagramFetchException('Media type ' . $media_type . ' not found'); + } + + return $type; + } + + /** + * @param \StdClass $node + * @return bool + */ + private function isCarousel(\StdClass $node): bool + { + return $node->media_type === Media::MEDIA_TYPE_CAROUSEL; + } + + /** + * @param \StdClass $node + * @return bool + */ + private function isVideo(\StdClass $node): bool + { + return $node->media_type === Media::MEDIA_TYPE_VIDEO; + } +} diff --git a/src/Instagram/Hydrator/MediaHydrator.php b/src/Instagram/Hydrator/MediaHydrator.php index e656764..b5276f8 100644 --- a/src/Instagram/Hydrator/MediaHydrator.php +++ b/src/Instagram/Hydrator/MediaHydrator.php @@ -69,7 +69,7 @@ public function hydrateTaggedMedias(\StdClass $node): TaggedMediasFeed $feed->setEndCursor($node->edge_user_to_photos_of_you->page_info->end_cursor); foreach ($node->edge_user_to_photos_of_you->edges as $node) { - $media = $this->hydrateProfile->mediaBaseHydrator(new Media, $node->node); + $media = $this->hydrateProfile->mediaBaseHydrator(new Media(), $node->node); $feed->addMedia($media); } diff --git a/src/Instagram/Hydrator/MediaProfileHydrator.php b/src/Instagram/Hydrator/MediaProfileHydrator.php index 238c690..b388fcb 100644 --- a/src/Instagram/Hydrator/MediaProfileHydrator.php +++ b/src/Instagram/Hydrator/MediaProfileHydrator.php @@ -1,89 +1,89 @@ -setId((int) $node->id); - $media->setShortCode($node->shortcode); - if (property_exists($node, '__typename')) { - $media->setTypeName($node->__typename); - } - - if ($node->edge_media_to_caption->edges) { - $media->setCaption($node->edge_media_to_caption->edges[0]->node->text); - $media->setHashtags(InstagramHelper::buildHashtags($node->edge_media_to_caption->edges[0]->node->text)); - } - - $media->setHeight($node->dimensions->height); - $media->setWidth($node->dimensions->width); - - $thumbnailSrc = property_exists($node, 'thumbnail_src') ? $node->thumbnail_src : $node->display_url; - - $media->setThumbnailSrc($thumbnailSrc); - $media->setDisplaySrc($node->display_url); - - $date = new \DateTime(); - $date->setTimestamp($node->taken_at_timestamp); - - $media->setDate($date); - - if (property_exists($node, 'edge_media_to_comment')) { - $commentsCount = $node->edge_media_to_comment->count; - } else { - $commentsCount = $node->edge_media_to_parent_comment->count; - } - - $media->setComments($commentsCount); - $media->setLikes($node->edge_media_preview_like->count); - - $media->setLink(InstagramHelper::URL_BASE . "p/{$node->shortcode}/"); - - $thumbNails = []; - if (property_exists($node, 'thumbnail_resources')) { - $thumbNails = $node->thumbnail_resources; - } - - $media->setThumbnails($thumbNails); - - if (isset($node->location)) { - $media->setLocation($node->location); - } - - $media->setVideo((bool) $node->is_video); - - if (property_exists($node, 'video_url')) { - $media->setVideoUrl($node->video_url); - } - - if (property_exists($node, 'video_view_count')) { - $media->setVideoViewCount((int) $node->video_view_count); - } - - if (property_exists($node, 'accessibility_caption')) { - $media->setAccessibilityCaption($node->accessibility_caption); - } - - if (property_exists($node, 'product_type')) { - $media->setIgtv($node->product_type === 'igtv'); - } - - if (property_exists($node, 'owner')) { - $media->setOwnerId((int) $node->owner->id); - } - - return $media; - } -} \ No newline at end of file +setId((int) $node->id); + $media->setShortCode($node->shortcode); + if (property_exists($node, '__typename')) { + $media->setTypeName($node->__typename); + } + + if ($node->edge_media_to_caption->edges) { + $media->setCaption($node->edge_media_to_caption->edges[0]->node->text); + $media->setHashtags(InstagramHelper::buildHashtags($node->edge_media_to_caption->edges[0]->node->text)); + } + + $media->setHeight($node->dimensions->height); + $media->setWidth($node->dimensions->width); + + $thumbnailSrc = property_exists($node, 'thumbnail_src') ? $node->thumbnail_src : $node->display_url; + + $media->setThumbnailSrc($thumbnailSrc); + $media->setDisplaySrc($node->display_url); + + $date = new \DateTime(); + $date->setTimestamp($node->taken_at_timestamp); + + $media->setDate($date); + + if (property_exists($node, 'edge_media_to_comment')) { + $commentsCount = $node->edge_media_to_comment->count; + } else { + $commentsCount = $node->edge_media_to_parent_comment->count; + } + + $media->setComments($commentsCount); + $media->setLikes($node->edge_media_preview_like->count); + + $media->setLink(InstagramHelper::URL_BASE . "p/{$node->shortcode}/"); + + $thumbNails = []; + if (property_exists($node, 'thumbnail_resources')) { + $thumbNails = $node->thumbnail_resources; + } + + $media->setThumbnails($thumbNails); + + if (isset($node->location)) { + $media->setLocation($node->location); + } + + $media->setVideo((bool) $node->is_video); + + if (property_exists($node, 'video_url')) { + $media->setVideoUrl($node->video_url); + } + + if (property_exists($node, 'video_view_count')) { + $media->setVideoViewCount((int) $node->video_view_count); + } + + if (property_exists($node, 'accessibility_caption')) { + $media->setAccessibilityCaption($node->accessibility_caption); + } + + if (property_exists($node, 'product_type')) { + $media->setIgtv($node->product_type === 'igtv'); + } + + if (property_exists($node, 'owner')) { + $media->setOwnerId((int) $node->owner->id); + } + + return $media; + } +} diff --git a/src/Instagram/Hydrator/TimelineFeedHydrator.php b/src/Instagram/Hydrator/TimelineFeedHydrator.php index 552efa2..7cb3602 100644 --- a/src/Instagram/Hydrator/TimelineFeedHydrator.php +++ b/src/Instagram/Hydrator/TimelineFeedHydrator.php @@ -54,12 +54,12 @@ public function hydrateTimelineFeed(\StdClass $feed): void $timeline = $this->timelineHydrator->timelineBaseHydrator($feedItem->media_or_ad); $this->timelineFeed->addTimeline($timeline); } - + // Sponsored Feed if (!property_exists($feedItem, 'label')) { } } - + // Suggested User Feed if (property_exists($feedItem, 'suggested_users')) { } diff --git a/src/Instagram/Hydrator/TimelineHydrator.php b/src/Instagram/Hydrator/TimelineHydrator.php index bda0fab..d4d2f6e 100644 --- a/src/Instagram/Hydrator/TimelineHydrator.php +++ b/src/Instagram/Hydrator/TimelineHydrator.php @@ -37,7 +37,7 @@ public function timelineBaseHydrator(\StdClass $node): Timeline /** * @param string $mediaType - * + * * @return mixed Image|Carousel|Video|Reels|Igtv */ public function hydrateTimelineMedia(string $mediaType, \StdClass $node) @@ -80,7 +80,7 @@ public function hydrateTimelineMedia(string $mediaType, \StdClass $node) /** * @param int $media_type * @param string $product_type - * + * * @return string * @throws InstagramFetchException */ diff --git a/src/Instagram/Model/Live.php b/src/Instagram/Model/Live.php index d7505c0..65b1fab 100644 --- a/src/Instagram/Model/Live.php +++ b/src/Instagram/Model/Live.php @@ -66,4 +66,4 @@ public function __serialize(): array { return $this->toArray(); } -} \ No newline at end of file +} diff --git a/src/Instagram/Model/Media.php b/src/Instagram/Model/Media.php index 57e0f0d..cd78a27 100644 --- a/src/Instagram/Model/Media.php +++ b/src/Instagram/Model/Media.php @@ -8,13 +8,13 @@ class Media { - const TYPE_IMAGE = 'image'; - const TYPE_VIDEO = 'video'; - const TYPE_CAROUSEL = 'carousel'; + public const TYPE_IMAGE = 'image'; + public const TYPE_VIDEO = 'video'; + public const TYPE_CAROUSEL = 'carousel'; - const MEDIA_TYPE_IMAGE = 1; - const MEDIA_TYPE_VIDEO = 2; - const MEDIA_TYPE_CAROUSEL = 8; + public const MEDIA_TYPE_IMAGE = 1; + public const MEDIA_TYPE_VIDEO = 2; + public const MEDIA_TYPE_CAROUSEL = 8; /** * @var int diff --git a/src/Instagram/Model/Profile.php b/src/Instagram/Model/Profile.php index 30d3434..06f0c52 100644 --- a/src/Instagram/Model/Profile.php +++ b/src/Instagram/Model/Profile.php @@ -148,7 +148,6 @@ public function setBiography(string $biography): void * @return int */ public function getFollowers(): int - { return $this->followers; } diff --git a/src/Instagram/Model/TaggedMediasFeed.php b/src/Instagram/Model/TaggedMediasFeed.php index 43c2cfe..071cd25 100644 --- a/src/Instagram/Model/TaggedMediasFeed.php +++ b/src/Instagram/Model/TaggedMediasFeed.php @@ -68,4 +68,4 @@ public function setEndCursor(string $endCursor): void { $this->endCursor = $endCursor; } -} \ No newline at end of file +} diff --git a/src/Instagram/Model/Timeline.php b/src/Instagram/Model/Timeline.php index 97d2f4e..1331369 100644 --- a/src/Instagram/Model/Timeline.php +++ b/src/Instagram/Model/Timeline.php @@ -8,15 +8,15 @@ class Timeline { - const TYPE_IMAGE = 'image'; - const TYPE_VIDEO = 'video'; - const TYPE_REELS = 'reels'; - const TYPE_IGTV = 'igtv'; - const TYPE_CAROUSEL = 'carousel'; - - const MEDIA_TYPE_IMAGE = 1; - const MEDIA_TYPE_VIDEO = 2; - const MEDIA_TYPE_CAROUSEL = 8; + public const TYPE_IMAGE = 'image'; + public const TYPE_VIDEO = 'video'; + public const TYPE_REELS = 'reels'; + public const TYPE_IGTV = 'igtv'; + public const TYPE_CAROUSEL = 'carousel'; + + public const MEDIA_TYPE_IMAGE = 1; + public const MEDIA_TYPE_VIDEO = 2; + public const MEDIA_TYPE_CAROUSEL = 8; /** * @var string diff --git a/src/Instagram/Transport/CommentPost.php b/src/Instagram/Transport/CommentPost.php index c68a84b..957ff8e 100644 --- a/src/Instagram/Transport/CommentPost.php +++ b/src/Instagram/Transport/CommentPost.php @@ -44,4 +44,4 @@ private function fetchData(string $endpoint, string $message): string return $data->status; } -} \ No newline at end of file +} diff --git a/src/Instagram/Transport/HtmlProfileDataFeed.php b/src/Instagram/Transport/HtmlProfileDataFeed.php index a25a927..05a999b 100644 --- a/src/Instagram/Transport/HtmlProfileDataFeed.php +++ b/src/Instagram/Transport/HtmlProfileDataFeed.php @@ -26,7 +26,7 @@ public function fetchData(string $userName): \StdClass 'accept-language' => OptionHelper::$LOCALE, ], ]; - + if (!empty($this->session)) { $headers['cookies'] = $this->session->getCookies(); } diff --git a/src/Instagram/Transport/JsonMediaCommentsFeed.php b/src/Instagram/Transport/JsonMediaCommentsFeed.php index 7cc55b3..08d8e19 100644 --- a/src/Instagram/Transport/JsonMediaCommentsFeed.php +++ b/src/Instagram/Transport/JsonMediaCommentsFeed.php @@ -28,7 +28,7 @@ public function fetchData(string $code, int $limit): \StdClass $data = $this->fetchJsonDataFeed($endpoint); - return !empty($data->data->shortcode_media->edge_media_to_comment) ? $data->data->shortcode_media->edge_media_to_comment : new \StdClass; + return !empty($data->data->shortcode_media->edge_media_to_comment) ? $data->data->shortcode_media->edge_media_to_comment : new \StdClass(); } /** @@ -51,6 +51,6 @@ public function fetchMoreData(string $code, string $endCursor): \StdClass $data = $this->fetchJsonDataFeed($endpoint); - return !empty($data->data->shortcode_media->edge_media_to_comment) ? $data->data->shortcode_media->edge_media_to_comment : new \StdClass; + return !empty($data->data->shortcode_media->edge_media_to_comment) ? $data->data->shortcode_media->edge_media_to_comment : new \StdClass(); } } diff --git a/src/Instagram/Transport/JsonProfileAlternativeDataFeed.php b/src/Instagram/Transport/JsonProfileAlternativeDataFeed.php index e827c27..a0b6dd5 100644 --- a/src/Instagram/Transport/JsonProfileAlternativeDataFeed.php +++ b/src/Instagram/Transport/JsonProfileAlternativeDataFeed.php @@ -11,7 +11,7 @@ class JsonProfileAlternativeDataFeed extends AbstractDataFeed { - const IG_APP_ID = 936619743392459; + public const IG_APP_ID = 936619743392459; /** * @param int $userId @@ -62,4 +62,4 @@ public function fetchData(int $userId): \StdClass return $data->user; } -} \ No newline at end of file +} diff --git a/src/Instagram/Transport/JsonStoryHighlightsStoriesDataFeed.php b/src/Instagram/Transport/JsonStoryHighlightsStoriesDataFeed.php index fe92a58..a13ef17 100644 --- a/src/Instagram/Transport/JsonStoryHighlightsStoriesDataFeed.php +++ b/src/Instagram/Transport/JsonStoryHighlightsStoriesDataFeed.php @@ -34,7 +34,7 @@ public function fetchData(StoryHighlightsFolder $folder): \StdClass $endpoint = InstagramHelper::URL_BASE . 'graphql/query/?query_hash=' . InstagramHelper::QUERY_HASH_HIGHLIGHTS_STORIES . '&variables=' . json_encode($variables); $data = $this->fetchJsonDataFeed($endpoint); - + return $data->data->reels_media[0]; } } diff --git a/src/Instagram/Transport/LiveData.php b/src/Instagram/Transport/LiveData.php index b306b0d..9fb2b5a 100644 --- a/src/Instagram/Transport/LiveData.php +++ b/src/Instagram/Transport/LiveData.php @@ -8,7 +8,6 @@ use Instagram\Exception\InstagramFetchException; use Instagram\Utils\{Endpoints, OptionHelper, CacheResponse}; - class LiveData extends AbstractDataFeed { /** diff --git a/src/Instagram/Transport/ReelsDataFeed.php b/src/Instagram/Transport/ReelsDataFeed.php index ec98af8..a2abfac 100644 --- a/src/Instagram/Transport/ReelsDataFeed.php +++ b/src/Instagram/Transport/ReelsDataFeed.php @@ -11,7 +11,7 @@ class ReelsDataFeed extends AbstractDataFeed { - const IG_APP_ID = 936619743392459; + public const IG_APP_ID = 936619743392459; /** * @param int $userId @@ -77,4 +77,4 @@ public function fetchData(int $userId, string $maxId = null): \StdClass return $data; } -} \ No newline at end of file +} diff --git a/src/Instagram/Transport/TimelineDataFeed.php b/src/Instagram/Transport/TimelineDataFeed.php index 0b742e9..8fe82f6 100644 --- a/src/Instagram/Transport/TimelineDataFeed.php +++ b/src/Instagram/Transport/TimelineDataFeed.php @@ -12,7 +12,7 @@ class TimelineDataFeed extends AbstractDataFeed { - const IG_APP_ID = 1217981644879628; + public const IG_APP_ID = 1217981644879628; /** * @param string|null $maxId @@ -128,4 +128,4 @@ public function fetchDataTimelineFeed(string $maxId = null): array return $data; } -} \ No newline at end of file +} diff --git a/src/Instagram/Utils/CacheResponse.php b/src/Instagram/Utils/CacheResponse.php index f0e7f11..f38c864 100644 --- a/src/Instagram/Utils/CacheResponse.php +++ b/src/Instagram/Utils/CacheResponse.php @@ -18,16 +18,16 @@ class CacheResponse * * @return void */ - public static function setResponse(Response $response): void - { - self::$response = $response; - } + public static function setResponse(Response $response): void + { + self::$response = $response; + } /** * @return \GuzzleHttp\Psr7\Response|null */ - public static function getResponse(): mixed - { - return self::$response; - } + public static function getResponse(): mixed + { + return self::$response; + } } diff --git a/src/Instagram/Utils/Endpoints.php b/src/Instagram/Utils/Endpoints.php index 63252ea..315aa77 100644 --- a/src/Instagram/Utils/Endpoints.php +++ b/src/Instagram/Utils/Endpoints.php @@ -6,23 +6,23 @@ class Endpoints { - const FOLLOW_URL = 'https://www.instagram.com/web/friendships/{{accountId}}/follow/'; - const UNFOLLOW_URL = 'https://www.instagram.com/web/friendships/{{accountId}}/unfollow/'; + public const FOLLOW_URL = 'https://www.instagram.com/web/friendships/{{accountId}}/follow/'; + public const UNFOLLOW_URL = 'https://www.instagram.com/web/friendships/{{accountId}}/unfollow/'; - const LIKE_URL = 'https://www.instagram.com/web/likes/{{postId}}/like/'; - const UNLIKE_URL = 'https://www.instagram.com/web/likes/{{postId}}/unlike/'; + public const LIKE_URL = 'https://www.instagram.com/web/likes/{{postId}}/like/'; + public const UNLIKE_URL = 'https://www.instagram.com/web/likes/{{postId}}/unlike/'; - const LOCATION_URL = 'https://www.instagram.com/explore/locations/{{locationId}}/'; + public const LOCATION_URL = 'https://www.instagram.com/explore/locations/{{locationId}}/'; - const LIVE_URL = 'https://www.instagram.com/{{username}}/live/?__a=1'; + public const LIVE_URL = 'https://www.instagram.com/{{username}}/live/?__a=1'; - const REELS_URL = 'https://i.instagram.com/api/v1/clips/user/?hl=en'; + public const REELS_URL = 'https://i.instagram.com/api/v1/clips/user/?hl=en'; - const PROFILE_URL = 'https://i.instagram.com/api/v1/users/{{userId}}/info/'; + public const PROFILE_URL = 'https://i.instagram.com/api/v1/users/{{userId}}/info/'; - const COMMENT_URL = 'https://www.instagram.com/web/comments/{{postId}}/add/'; + public const COMMENT_URL = 'https://www.instagram.com/web/comments/{{postId}}/add/'; - const TIMELINE_URL = 'https://i.instagram.com/api/v1/feed/timeline/'; + public const TIMELINE_URL = 'https://i.instagram.com/api/v1/feed/timeline/'; /** * @param int $accountId diff --git a/src/Instagram/Utils/InstagramHelper.php b/src/Instagram/Utils/InstagramHelper.php index cb69eee..7cf52ff 100644 --- a/src/Instagram/Utils/InstagramHelper.php +++ b/src/Instagram/Utils/InstagramHelper.php @@ -6,27 +6,27 @@ class InstagramHelper { - const URL_IG = 'https://www.instagram.com'; + public const URL_IG = 'https://www.instagram.com'; /** @todo IMPROVE ME LATER HEEHH */ - const URL_BASE = 'https://www.instagram.com/'; - const URL_API_BASE = 'https://i.instagram.com/'; - const URL_AUTH = 'https://www.instagram.com/accounts/login/ajax/'; - const URL_MEDIA_DETAILED = 'https://www.instagram.com/p/'; + public const URL_BASE = 'https://www.instagram.com/'; + public const URL_API_BASE = 'https://i.instagram.com/'; + public const URL_AUTH = 'https://www.instagram.com/accounts/login/ajax/'; + public const URL_MEDIA_DETAILED = 'https://www.instagram.com/p/'; - const QUERY_HASH_PROFILE = 'c9100bf9110dd6361671f113dd02e7d6'; - const QUERY_HASH_MEDIAS = '42323d64886122307be10013ad2dcc44'; - const QUERY_HASH_IGTVS = 'bc78b344a68ed16dd5d7f264681c4c76'; - const QUERY_HASH_STORIES = '5ec1d322b38839230f8e256e1f638d5f'; - const QUERY_HASH_HIGHLIGHTS_FOLDERS = 'ad99dd9d3646cc3c0dda65debcd266a7'; - const QUERY_HASH_HIGHLIGHTS_STORIES = '5ec1d322b38839230f8e256e1f638d5f'; - const QUERY_HASH_FOLLOWERS = 'c76146de99bb02f6415203be841dd25a'; - const QUERY_HASH_FOLLOWINGS = 'd04b0a864b4b54837c0d870b0e77e076'; - const QUERY_HASH_HASHTAG = '174a5243287c5f3a7de741089750ab3b'; - const QUERY_HASH_COMMENTS = '33ba35852cb50da46f5b5e889df7d159'; - const QUERY_HASH_TAGGED_MEDIAS = 'be13233562af2d229b008d2976b998b5'; + public const QUERY_HASH_PROFILE = 'c9100bf9110dd6361671f113dd02e7d6'; + public const QUERY_HASH_MEDIAS = '42323d64886122307be10013ad2dcc44'; + public const QUERY_HASH_IGTVS = 'bc78b344a68ed16dd5d7f264681c4c76'; + public const QUERY_HASH_STORIES = '5ec1d322b38839230f8e256e1f638d5f'; + public const QUERY_HASH_HIGHLIGHTS_FOLDERS = 'ad99dd9d3646cc3c0dda65debcd266a7'; + public const QUERY_HASH_HIGHLIGHTS_STORIES = '5ec1d322b38839230f8e256e1f638d5f'; + public const QUERY_HASH_FOLLOWERS = 'c76146de99bb02f6415203be841dd25a'; + public const QUERY_HASH_FOLLOWINGS = 'd04b0a864b4b54837c0d870b0e77e076'; + public const QUERY_HASH_HASHTAG = '174a5243287c5f3a7de741089750ab3b'; + public const QUERY_HASH_COMMENTS = '33ba35852cb50da46f5b5e889df7d159'; + public const QUERY_HASH_TAGGED_MEDIAS = 'be13233562af2d229b008d2976b998b5'; - const PAGINATION_DEFAULT = 12; - const PAGINATION_DEFAULT_FIRST_FOLLOW = 24; + public const PAGINATION_DEFAULT = 12; + public const PAGINATION_DEFAULT_FIRST_FOLLOW = 24; /** * @param string|null $caption @@ -34,7 +34,7 @@ class InstagramHelper * * @codeCoverageIgnore */ - static function buildHashtags(?string $caption): array + public static function buildHashtags(?string $caption): array { if ($caption) { preg_match_all('/(?