Issues (184)

src/FeiYu.php (184 issues)

1
<?php
2
0 ignored issues
show
Missing file doc comment
Loading history...
3
namespace FeiYuCRM;
4
5
/**
6
 * FeiYuCRM system class
7
 * @author haosijia <[email protected]>
0 ignored issues
show
There must be exactly one blank line before the tags in a doc comment
Loading history...
8
 */
0 ignored issues
show
Missing @category tag in class comment
Loading history...
Missing @package tag in class comment
Loading history...
Missing @license tag in class comment
Loading history...
Missing @link tag in class comment
Loading history...
9
class FeiYu
10
{
11
  // Server address
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
12
  public $host = '';
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
13
  // Data fetch route
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
14
  public $pull_route = '';
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
15
  // Upload data route
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
16
  public $push_route = '';
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
17
  // Encryption key
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
18
  public $signature_key = '';
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
19
  // Token
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
20
  public $token = '';
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
21
22
  // Timestamp
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
23
  protected $timestamp = '';
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
24
  // Signature
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
25
  protected $signature = '';
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
26
  // Start time
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
27
  protected $start_time = '';
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
28
  // End time
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
29
  protected $end_time = '';
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
30
  // Page size
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
31
  protected $page_size = '';
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
32
  // Run route
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
33
  protected $fetch_route = '';
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
34
  // Data from host
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
35
  protected $res_data = '';
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
36
  // Push data source
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
37
  protected $push_data = '';
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
38
39 2
  public function __construct($options)
0 ignored issues
show
Line indented incorrectly; expected 4 spaces, found 2
Loading history...
Missing doc comment for function __construct()
Loading history...
40
  {
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
41 2
    $this->host = isset($options['host'])?$options['host']:$this->host;
0 ignored issues
show
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
42 2
    $this->pull_route = isset($options['pull_route'])?$options['pull_route']:$this->pull_route;
0 ignored issues
show
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
43 2
    $this->push_route = isset($options['push_route'])?$options['push_route']:$this->push_route;
0 ignored issues
show
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
44 2
    $this->signature_key = isset($options['signature_key'])?$options['signature_key']:$this->signature_key;
0 ignored issues
show
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
45 2
    $this->token = isset($options['token'])?$options['token']:$this->token;
0 ignored issues
show
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
46 2
    $this->timestamp = time();
0 ignored issues
show
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
47 2
  }
0 ignored issues
show
Line indented incorrectly; expected 4 spaces, found 2
Loading history...
48
49
  /**
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
50
   * pull data
0 ignored issues
show
Doc comment short description must start with a capital letter
Loading history...
51
   * @param string $start_time ['Y-m-d']
0 ignored issues
show
There must be exactly one blank line before the tags in a doc comment
Loading history...
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
52
   * @param string $end_time ['Y-m-d']
0 ignored issues
show
Expected 3 spaces after parameter name; 1 found
Loading history...
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
53
   * @param int $page_size
0 ignored issues
show
Missing parameter comment
Loading history...
Expected 4 spaces after parameter type; 1 found
Loading history...
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
54
   * @return $this
0 ignored issues
show
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
55
   */
56 1
  public function pullData($start_time, $end_time, $page_size)
0 ignored issues
show
Line indented incorrectly; expected 4 spaces, found 2
Loading history...
57
  {
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
58 1
    $this->start_time = strtotime($start_time);
0 ignored issues
show
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
59 1
    $this->end_time = strtotime($end_time);
0 ignored issues
show
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
60 1
    $this->page_size = $page_size;
0 ignored issues
show
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
61 1
    $this->fetch_route = $this->pull_route;
0 ignored issues
show
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
62 1
    return $this;
0 ignored issues
show
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
63
  }
0 ignored issues
show
Line indented incorrectly; expected 4 spaces, found 2
Loading history...
64
65
  /**
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
66
   * push data
0 ignored issues
show
Doc comment short description must start with a capital letter
Loading history...
67
   * @param array $data
0 ignored issues
show
There must be exactly one blank line before the tags in a doc comment
Loading history...
Missing parameter comment
Loading history...
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
68
   * @return bool
0 ignored issues
show
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
69
   */
70 1
  public function pushData($data)
0 ignored issues
show
Line indented incorrectly; expected 4 spaces, found 2
Loading history...
71
  {
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
72 1
    if(!isset($data['clue_convert_state']) || !isset($data['clue_id'])){
0 ignored issues
show
Line indented incorrectly; expected 8 spaces, found 4
Loading history...
Expected "if (...) {\n"; found "if(...){\n"
Loading history...
There must be a single space between the closing parenthesis and the opening brace of a multi-line IF statement; found 0 spaces
Loading history...
73
      throw new FeiYuException("Upload data is missing the necessary parameters", 1);
0 ignored issues
show
Line indented incorrectly; expected at least 12 spaces, found 6
Loading history...
74
    }
0 ignored issues
show
Line indented incorrectly; expected 8 spaces, found 4
Loading history...
75 1
    if(!is_numeric($data['clue_convert_state'])){
0 ignored issues
show
Line indented incorrectly; expected 8 spaces, found 4
Loading history...
Expected "if (...) {\n"; found "if(...){\n"
Loading history...
There must be a single space between the closing parenthesis and the opening brace of a multi-line IF statement; found 0 spaces
Loading history...
76
      throw new FeiYuException("'clue_convert_state' must be a numeric type", 1);
0 ignored issues
show
Line indented incorrectly; expected at least 12 spaces, found 6
Loading history...
77
    }
0 ignored issues
show
Line indented incorrectly; expected 8 spaces, found 4
Loading history...
78 1
    $data['clue_convert_state'] = (int)$data['clue_convert_state'];
0 ignored issues
show
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
79 1
    $this->push_data = json_encode([
0 ignored issues
show
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
80 1
      'source' => 0,
0 ignored issues
show
This line of the multi-line function call does not seem to be indented correctly. Expected 8 spaces, but found 6.
Loading history...
Line indented incorrectly; expected at least 8 spaces, found 6
Loading history...
81
      'data' => [
0 ignored issues
show
This line of the multi-line function call does not seem to be indented correctly. Expected 8 spaces, but found 6.
Loading history...
Line indented incorrectly; expected at least 8 spaces, found 6
Loading history...
82 1
        'clue_id' => $data['clue_id'],
83 1
        'clue_convert_state' => $data['clue_convert_state'],
84
      ],
0 ignored issues
show
This line of the multi-line function call does not seem to be indented correctly. Expected 8 spaces, but found 6.
Loading history...
Line indented incorrectly; expected at least 8 spaces, found 6
Loading history...
85
    ]);
0 ignored issues
show
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
86 1
    $this->fetch_route = $this->push_route;
0 ignored issues
show
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
87 1
    $this->fetchCurl();
0 ignored issues
show
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
88
    return !$this->getResData()['status'];
0 ignored issues
show
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
89
  }
0 ignored issues
show
Line indented incorrectly; expected 4 spaces, found 2
Loading history...
90
91
  /**
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
92
   * get result data from curl
0 ignored issues
show
Doc comment short description must start with a capital letter
Loading history...
93
   * @return string
0 ignored issues
show
There must be exactly one blank line before the tags in a doc comment
Loading history...
94
   */
95
  public function getResData()
0 ignored issues
show
Line indented incorrectly; expected 4 spaces, found 2
Loading history...
96
  {
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
97
    return $this->res_data;
0 ignored issues
show
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
98
  }
0 ignored issues
show
Line indented incorrectly; expected 4 spaces, found 2
Loading history...
99
100
  /**
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
Parameter $callback should have a doc-comment as per coding-style.
Loading history...
101
   * get all page data and run callback function in every page
0 ignored issues
show
Doc comment short description must start with a capital letter
Loading history...
102
   * @return string
0 ignored issues
show
There must be exactly one blank line before the tags in a doc comment
Loading history...
103
   */
104 1
  public function run($callback)
0 ignored issues
show
Line indented incorrectly; expected 4 spaces, found 2
Loading history...
105
  {
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
106 1
    $page = 1;
0 ignored issues
show
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
107
108
    do {
0 ignored issues
show
Line indented incorrectly; expected 8 spaces, found 4
Loading history...
109 1
      $this->fetchCurl($page);
0 ignored issues
show
Line indented incorrectly; expected at least 12 spaces, found 6
Loading history...
110
111
      if (call_user_func($callback, $this->res_data['data']) === false) {
0 ignored issues
show
Line indented incorrectly; expected 12 spaces, found 6
Loading history...
112
        return false;
0 ignored issues
show
Line indented incorrectly; expected at least 16 spaces, found 8
Loading history...
113
      }
0 ignored issues
show
Line indented incorrectly; expected 12 spaces, found 6
Loading history...
114
115
      $page++;
0 ignored issues
show
Line indented incorrectly; expected at least 12 spaces, found 6
Loading history...
116
    } while (($page-1)*($this->page_size) < $this->res_data['count']);
0 ignored issues
show
Line indented incorrectly; expected 8 spaces, found 4
Loading history...
117
118
    return true;
0 ignored issues
show
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
119
  }
0 ignored issues
show
Line indented incorrectly; expected 4 spaces, found 2
Loading history...
120
121
  /**
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
122
   * encrypt url and start_time and end_time to signature
0 ignored issues
show
Doc comment short description must start with a capital letter
Loading history...
123
   * @return $this
0 ignored issues
show
There must be exactly one blank line before the tags in a doc comment
Loading history...
124
   */
125 2
  protected function encryptData()
0 ignored issues
show
Line indented incorrectly; expected 4 spaces, found 2
Loading history...
126
  {
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
127
    // 拼接中的空格很重要
0 ignored issues
show
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
128 2
    if($this->fetch_route == $this->pull_route){
0 ignored issues
show
Line indented incorrectly; expected 8 spaces, found 4
Loading history...
Expected "if (...) {\n"; found "if(...){\n"
Loading history...
There must be a single space between the closing parenthesis and the opening brace of a multi-line IF statement; found 0 spaces
Loading history...
129 1
      $data = $this->fetch_route.'?start_time='.$this->start_time.'&end_time='.$this->end_time.' '.$this->timestamp;
0 ignored issues
show
Line indented incorrectly; expected at least 12 spaces, found 6
Loading history...
130
    } else {
0 ignored issues
show
Line indented incorrectly; expected 8 spaces, found 4
Loading history...
131 1
      $data = $this->fetch_route.' '.$this->timestamp;
0 ignored issues
show
Line indented incorrectly; expected at least 12 spaces, found 6
Loading history...
132
    }
0 ignored issues
show
Line indented incorrectly; expected 8 spaces, found 4
Loading history...
133 2
    $this->signature = base64_encode(hash_hmac('sha256', $data, $this->signature_key));
0 ignored issues
show
It seems like $this->signature_key can also be of type mixed; however, parameter $key of hash_hmac() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

133
    $this->signature = base64_encode(hash_hmac('sha256', $data, /** @scrutinizer ignore-type */ $this->signature_key));
Loading history...
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
134 2
    return $this;
0 ignored issues
show
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
135
  }
0 ignored issues
show
Line indented incorrectly; expected 4 spaces, found 2
Loading history...
136
137
  /**
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
138
   * fetch data by curl
0 ignored issues
show
Doc comment short description must start with a capital letter
Loading history...
139
   * @param string $page
0 ignored issues
show
There must be exactly one blank line before the tags in a doc comment
Loading history...
Missing parameter comment
Loading history...
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
140
   * @return $this
0 ignored issues
show
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
141
   */
142 2
  protected function fetchCurl($page = 1)
0 ignored issues
show
Line indented incorrectly; expected 4 spaces, found 2
Loading history...
143
  {
0 ignored issues
show
Line indented incorrectly; expected at least 4 spaces, found 2
Loading history...
144 2
    $this->encryptData();
0 ignored issues
show
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
145 2
    $ch = curl_init();
0 ignored issues
show
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
146 2
    if(!$ch){
0 ignored issues
show
$ch is of type false|resource, thus it always evaluated to false.
Loading history...
Line indented incorrectly; expected 8 spaces, found 4
Loading history...
Expected "if (...) {\n"; found "if(...){\n"
Loading history...
There must be a single space between the closing parenthesis and the opening brace of a multi-line IF statement; found 0 spaces
Loading history...
147
      throw new FeiYuException('cURL init failed', 1);
0 ignored issues
show
Line indented incorrectly; expected at least 12 spaces, found 6
Loading history...
148
    }
0 ignored issues
show
Line indented incorrectly; expected 8 spaces, found 4
Loading history...
149 2
    curl_setopt($ch, CURLOPT_URL, $this->host.$this->fetch_route.'?page='.$page.'&page_size='.$this->page_size.'&start_time='.$this->start_time.'&end_time='.$this->end_time);
0 ignored issues
show
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
150 2
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
0 ignored issues
show
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
151 2
    curl_setopt($ch, CURLOPT_TIMEOUT, 5);
0 ignored issues
show
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
152 2
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
0 ignored issues
show
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
153 2
        'Content-Type: application/json;charset=UTF-8',
154 2
        'Signature: ' . $this->signature,
155 2
        'Timestamp: ' . $this->timestamp,
156 2
        'Access-Token: ' . $this->token,
157
    ]);
0 ignored issues
show
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
158 2
    if($this->fetch_route == $this->push_route){
0 ignored issues
show
Line indented incorrectly; expected 8 spaces, found 4
Loading history...
Expected "if (...) {\n"; found "if(...){\n"
Loading history...
There must be a single space between the closing parenthesis and the opening brace of a multi-line IF statement; found 0 spaces
Loading history...
159 1
      curl_setopt($ch, CURLOPT_POST, true);
0 ignored issues
show
Line indented incorrectly; expected at least 12 spaces, found 6
Loading history...
160 1
      curl_setopt($ch, CURLOPT_POSTFIELDS, $this->push_data);
0 ignored issues
show
Line indented incorrectly; expected at least 12 spaces, found 6
Loading history...
161
    }
0 ignored issues
show
Line indented incorrectly; expected 8 spaces, found 4
Loading history...
162 2
    $output = curl_exec($ch);
0 ignored issues
show
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
163 2
    $error = curl_error($ch);
0 ignored issues
show
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
164 2
    curl_close($ch);
0 ignored issues
show
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
165 2
    if($error != ''){
0 ignored issues
show
Line indented incorrectly; expected 8 spaces, found 4
Loading history...
Expected "if (...) {\n"; found "if(...){\n"
Loading history...
There must be a single space between the closing parenthesis and the opening brace of a multi-line IF statement; found 0 spaces
Loading history...
166
      throw new FeiYuException($error, 1);
0 ignored issues
show
Line indented incorrectly; expected at least 12 spaces, found 6
Loading history...
167
    }
0 ignored issues
show
Line indented incorrectly; expected 8 spaces, found 4
Loading history...
168 2
    $this->res_data = json_decode($output, true);
0 ignored issues
show
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
169 2
    if($this->res_data['status'] != 'success'){
0 ignored issues
show
Line indented incorrectly; expected 8 spaces, found 4
Loading history...
Expected "if (...) {\n"; found "if(...){\n"
Loading history...
There must be a single space between the closing parenthesis and the opening brace of a multi-line IF statement; found 0 spaces
Loading history...
170 2
      if(is_array($this->res_data['msg'])){
0 ignored issues
show
Line indented incorrectly; expected 12 spaces, found 6
Loading history...
Expected "if (...) {\n"; found "if(...){\n"
Loading history...
There must be a single space between the closing parenthesis and the opening brace of a multi-line IF statement; found 0 spaces
Loading history...
171
        throw new FeiYuException(json_encode($this->res_data['msg']), 1);
0 ignored issues
show
Line indented incorrectly; expected at least 16 spaces, found 8
Loading history...
172
      }
0 ignored issues
show
Line indented incorrectly; expected 12 spaces, found 6
Loading history...
173 2
      throw new FeiYuException($this->res_data['msg'], 1);
0 ignored issues
show
Line indented incorrectly; expected at least 12 spaces, found 6
Loading history...
174
    }
0 ignored issues
show
Line indented incorrectly; expected 8 spaces, found 4
Loading history...
175
    return $this;
0 ignored issues
show
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
176
  }
0 ignored issues
show
Line indented incorrectly; expected 4 spaces, found 2
Loading history...
177
}
178
179
class FeiYuException extends \Exception
0 ignored issues
show
Missing doc comment for class FeiYuException
Loading history...
180
{
181
  
182
}