Header   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 31
c 2
b 0
f 0
dl 0
loc 94
rs 10
wmc 15

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getUserAgent() 0 7 2
A setHeaders() 0 7 3
A setUserAgent() 0 5 1
C getHeader() 0 50 9
1
<?php
2
3
namespace Daaner\TikTok\Traits;
4
5
trait Header
6
{
7
    protected $userAgent;
8
    protected $headers = [];
9
10
    /**
11
     * @param array $addition_headers
12
     * @return this
13
     */
14
    public function setHeaders($addition_headers)
15
    {
16
        if (is_array($addition_headers) && ! empty($addition_headers)) {
17
            $this->headers = array_merge($this->headers, $addition_headers);
18
        }
19
20
        return $this;
21
    }
22
23
    /**
24
     * @return array $headers
25
     */
26
    public function getHeader($headers)
27
    {
28
        /* add UserAgent Header */
29
        $this->getUserAgent();
30
        $this->headers = array_merge($this->headers, ['user-agent' => $this->userAgent]);
31
32
        /* add from config - primary_header */
33
        $this->headers = array_merge($this->headers, config('tiktok.primary_header'));
34
35
        /* add from config - use_header_referer */
36
        if (config('tiktok.use_header_referer')) {
37
            $this->headers = array_merge($this->headers, config('tiktok.referer'));
38
        }
39
40
        /* add from config - use_header_lang */
41
        if (config('tiktok.use_header_lang')) {
42
            $this->headers = array_merge($this->headers, config('tiktok.lang'));
43
        }
44
45
        /* add from config - use_header_browser */
46
        if (config('tiktok.use_header_browser')) {
47
            $this->headers = array_merge($this->headers, config('tiktok.browser'));
48
        }
49
50
        /* add from config - use_header_browser_ver */
51
        if (config('tiktok.use_header_browser_ver')) {
52
            $this->headers = array_merge($this->headers, config('tiktok.browser_ver'));
53
        }
54
55
        /* add from config - use_header_personal */
56
        if (config('tiktok.use_header_personal')) {
57
            $this->headers = array_merge($this->headers, config('tiktok.personal'));
58
        }
59
60
        /* add from config - use_header_personal_addition */
61
        if (config('tiktok.use_header_personal_addition')) {
62
            $this->headers = array_merge($this->headers, config('tiktok.personal_addition'));
63
        }
64
65
        /* add from config - verifyFp */
66
        if (config('tiktok.verifyFp')) {
67
            $this->headers = array_merge($this->headers, ['verifyFp' => config('tiktok.verifyFp')]);
68
        }
69
70
        /* add Response headers */
71
        if ($headers) {
72
            $this->headers = array_merge($this->headers, $headers);
73
        }
74
75
        return $this->headers;
76
    }
77
78
    /**
79
     * @param string $userAgent
80
     * @return this
81
     */
82
    public function setUserAgent($userAgent)
83
    {
84
        $this->userAgent = $userAgent;
85
86
        return $this;
87
    }
88
89
    /**
90
     * @return string $this->userAgent
91
     */
92
    public function getUserAgent()
93
    {
94
        if (! $this->userAgent) {
95
            $this->userAgent = config('tiktok.user_agent');
96
        }
97
98
        return $this->userAgent;
99
    }
100
}
101