Completed
Push — master ( 1e0bdf...0e0b28 )
by Sergey
09:20 queued 10s
created

RequestHelper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 34
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createRequestData() 0 7 1
A getDataFromResponse() 0 12 4
1
<?php
2
3
namespace seregazhuk\PinterestBot\Helpers;
4
5
class RequestHelper
6
{
7
    /**
8
     * @param string|null $sourceUrl
9
     * @param array       $data
10
     * @return array
11
     */
12
    public static function createRequestData($data, $sourceUrl = null)
13
    {
14
        return [
15
            "source_url" => $sourceUrl,
16
            "data"       => json_encode($data),
17
        ];
18
    }
19
20
    /**
21
     * Check if specified data exists in response
22
     * @param      $response
23
     * @param null $key
24
     * @return array|bool
25
     */
26
    public static function getDataFromResponse($response, $key = null)
27
    {
28
        if (isset($response['resource_response']['data'])) {
29
            $data = $response['resource_response']['data'];
30
31
            if ($key) {
32
                return array_key_exists($key, $data) ? $data[$key] : false;
33
            }
34
            return $data;
35
        }
36
        return false;
37
    }
38
}