UserInfo   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 10
eloc 28
c 2
b 0
f 0
dl 0
loc 65
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getUser() 0 18 2
A ModelSettings() 0 5 1
B getUserInfo() 0 21 7
1
<?php
2
3
namespace Daaner\TikTok\Models;
4
5
use Daaner\TikTok\TikTok;
6
7
class UserInfo extends TikTok
8
{
9
    protected $url;
10
    protected $arrayPrimary;
11
    protected $arraySecondary;
12
13
    /**
14
     * @return $this
15
     */
16
    public function ModelSettings()
17
    {
18
        $this->url = config('tiktok.user_info.link');
19
        $this->arrayPrimary = config('tiktok.user_info.array_primary');
20
        $this->arraySecondary = config('tiktok.user_info.array_secondary');
21
    }
22
23
    /**
24
     * @param string $userName
25
     * @return array
26
     */
27
    public function getUser($userName)
28
    {
29
        /* add settings */
30
        $this->ModelSettings();
31
32
        $userName = '@'.str_replace('@', '', $userName);
33
34
        if (! $userName) {
35
            return [
36
                'success' => false,
37
                'result' => null,
38
                'info' => __('tiktok::tiktok.error_username'),
39
            ];
40
        }
41
42
        $response = $this->getResponse($this->url.$userName);
43
44
        return $response;
45
    }
46
47
    /**
48
     * @param string $userName
49
     * @return array
50
     */
51
    public function getUserInfo($userName)
52
    {
53
        $data = $this->getUser($userName);
54
55
        $result = [];
56
        $result['success'] = $data['success'];
57
58
        if ($data['success'] && isset($data['result']['statusCode']) && $data['result']['statusCode'] == 0) {
59
            if (isset($data['result'][$this->arrayPrimary])) {
60
                $result['primary'] = $data['result'][$this->arrayPrimary];
61
            }
62
63
            if ($this->arraySecondary && isset($data['result'][$this->arrayPrimary])) {
64
                $result['secondary'] = $data['result'][$this->arraySecondary];
65
            }
66
        } else {
67
            $result['info'] = __('tiktok::tiktok.user_no_found');
68
            $result['success'] = false;
69
        }
70
71
        return $result;
72
    }
73
}
74