GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

SearchItemTrait::buildPostContent()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 4

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 25
ccs 17
cts 17
cp 1
c 0
b 0
f 0
rs 9.7666
cc 4
nc 3
nop 0
crap 4
1
<?php
2
3
namespace AlibabaCloud\ImageSearch\V20180120\Traits;
4
5
/**
6
 * Trait SearchItemTrait
7
 *
8
 * @package AlibabaCloud\ImageSearch\V20180120\Traits
9
 */
10
trait SearchItemTrait
11
{
12
    /**
13
     * @var int
14
     */
15
    private $start = 0;
16
17
    /**
18
     * @var int
19
     */
20
    private $num = 10;
21
22
    /**
23
     * @var string
24
     */
25
    private $cateId = '';
26
27
    /**
28
     * @var
29
     */
30
    private $searchPicture;
31
32
    /**
33
     * @return bool
34
     */
35 1
    public function buildPostContent()
36
    {
37 1
        if (!$this->searchPicture) {
38 1
            return false;
39
        }
40
41 1
        $map = [];
42
43 1
        $map['s'] = $this->start;
44 1
        $map['n'] = $this->num;
45 1
        if ($this->cateId !== null && $this->cateId !== '') {
46 1
            $map['cat_id'] = $this->cateId;
47 1
        }
48
49 1
        $encodePicName    = base64_encode('searchPic');
50 1
        $encodePicContent = base64_encode($this->searchPicture);
51
52 1
        $map['pic_list']     = $encodePicName;
53 1
        $map[$encodePicName] = $encodePicContent;
54
55 1
        $content = $this->buildContent($map);
56 1
        $this->body($content);
0 ignored issues
show
Bug introduced by
It seems like body() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
        $this->/** @scrutinizer ignore-call */ 
57
               body($content);
Loading history...
57 1
        $this->format('JSON');
0 ignored issues
show
Bug introduced by
It seems like format() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

57
        $this->/** @scrutinizer ignore-call */ 
58
               format('JSON');
Loading history...
58
59 1
        return true;
60
    }
61
62
    /**
63
     * @param mixed $start
64
     *
65
     * @return $this
66
     */
67 1
    public function withStart($start)
68
    {
69 1
        $this->start = $start;
70 1
        $this->buildPostContent();
71
72 1
        return $this;
73
    }
74
75
    /**
76
     * @param mixed $num
77
     *
78
     * @return $this
79
     */
80 1
    public function withNum($num)
81
    {
82 1
        $this->num = $num;
83 1
        $this->buildPostContent();
84
85 1
        return $this;
86
    }
87
88
    /**
89
     * @param mixed $cateId
90
     *
91
     * @return $this
92
     */
93 1
    public function withCateId($cateId)
94
    {
95 1
        $this->cateId = $cateId;
96 1
        $this->buildPostContent();
97
98 1
        return $this;
99
    }
100
101
    /**
102
     * @param mixed $searchPicture
103
     *
104
     * @return $this
105
     */
106 1
    public function withSearchPicture($searchPicture)
107
    {
108 1
        $this->searchPicture = $searchPicture;
109 1
        $this->buildPostContent();
110
111 1
        return $this;
112
    }
113
114
    /**
115
     * @param $map
116
     *
117
     * @return string
118
     */
119 1
    private function buildContent($map)
120
    {
121 1
        $meta  = '';
122 1
        $body  = '';
123 1
        $start = 0;
124
125 1
        foreach ($map as $key => $value) {
126 1
            if ($meta !== '') {
127 1
                $meta .= '#';
128 1
            }
129 1
            $meta  .= $key . ',' . $start . ',' . ($start + strlen($value));
130 1
            $body  .= $value;
131 1
            $start += strlen($value);
132 1
        }
133
134 1
        return $meta . '^' . $body;
135
    }
136
}
137