Profile   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 71
rs 10
c 0
b 0
f 0
wmc 11
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
D getProfile() 0 61 10
1
<?php
2
3
namespace Integrations\Connectors\Instagram;
4
5
use Log;
6
use App\Models\User;
7
use Exception;
8
use Muleta\Utils\Debugger\ErrorHelper;
9
10
class Profile extends Instagram
11
{
12
    
13
    public function __construct()
14
    {
15
        
16
    }
17
18
    public static function getProfile($username)
19
    {
20
        try {
21
            $options  = array('http' => array('user_agent' => 'Mozilla/5.0 (iPhone; CPU iPhone OS 12_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 Instagram 105.0.0.11.118 (iPhone11,8; iOS 12_3_1; en_US; en-US; scale=2.00; 828x1792; 165586599)'));
22
            $context  = stream_context_create($options);
23
24
            $html = file_get_contents('https://instagram.com/'.$username, false, $context);
25
            //Get user ID
26
            $subData = substr($html, strpos($html, 'window._sharedData'), strpos($html, '};'));
27
            $userID = strstr($subData, '"id":"');
28
            $userID = str_replace('"id":"', '', $userID);
29
            $userID = strstr($userID, '"', true);
30
31
            //Download user info
32
            $jsonData = file_get_contents('https://i.instagram.com/api/v1/users/'.$userID.'/info/', false, $context);
33
            $decodedInfo = json_decode($jsonData);
34
35
            $data = [];
36
37
            if (isset($decodedInfo->user->hd_profile_pic_url_info->url)) {
38
                $data['profilePic'] = $decodedInfo->user->hd_profile_pic_url_info->url;
39
            } else {
40
                $data['profilePic'] = $decodedInfo->user->profile_pic_url;
41
            }
42
43
            if (isset($decodedInfo->user->username)) {
44
                $data['username'] = $decodedInfo->user->username;
45
            } 
46
47
            if (isset($decodedInfo->user->follower_count)) {
48
                $data['follower'] = $decodedInfo->user->follower_count;
49
            } 
50
51
            if (isset($decodedInfo->user->following_count)) {
52
                $data['following'] = $decodedInfo->user->following_count;
53
            } 
54
55
            if (isset($decodedInfo->user->full_name)) {
56
                $data['full_name'] = $decodedInfo->user->full_name;
57
            } 
58
59
            if (isset($decodedInfo->user->is_private)) {
60
                $data['isPrivate'] = $decodedInfo->user->is_private;
61
            } 
62
63
            if (isset($decodedInfo->user->is_verified)) {
64
                $data['isVerified'] = $decodedInfo->user->is_verified;
65
            } 
66
67
            if (isset($decodedInfo->user->biography)) {
68
                $data['bio'] = $decodedInfo->user->biography;
69
            }
70
            
71
            return $data;
72
            
73
        } catch (\Exception $e) {
74
            ErrorHelper::registerAndReturnMessage($e);
75
        }
76
        return false;
77
78
    }
79
80
}
81