Authenticates::addHeader()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
/**
3
 * Authenticates Trait
4
 */
5
namespace Twigger\UnionCloud\API\Traits;
6
7
/**
8
 * Helper functions for Authenticators
9
 *
10
 * Includes:
11
 *      an array_keys_exist function, to validate parameters are all given
12
 *      A header function to add a header to Guzzle HTTP options
13
 *
14
 * @package Twigger\UnionCloud\API\Core\Traits
15
 */
16
trait Authenticates
17
{
18
    /**
19
     * Checks all the keys are present in the parameter array
20
     *
21
     * This can be used for validation. Create an array of all required fields, and pass them in along
22
     * with the the parameters passed in by the user to ensure all are present
23
     *
24
     * @param array $keys Array of keys that should be present in the configuration
25
     * @param array $parameters The parameters passed from the user
26
     *
27
     * @return bool
28
     */
29
    public function authArrayKeysExist($keys, $parameters)
30
    {
31
        foreach ($keys as $key) {
32
            if (!array_key_exists($key, $parameters)) {
33
                return false;
34
            }
35
        }
36
37
        return true;
38
    }
39
40
    /**
41
     * Add header to Guzzle HTTP options array
42
     *
43
     * @param array $options An options array
44
     * @param string $headerName Name of the header to input into the Guzzle options array
45
     * @param mixed $headerValue Value of the header
46
     *
47
     * @return mixed options array (transformed)
48
     */
49
    public function addHeader($options, $headerName, $headerValue)
50
    {
51
        $options['headers'][$headerName] = $headerValue;
52
        return $options;
53
    }
54
}