Completed
Pull Request — master (#18)
by Stéphane
66:12 queued 61:24
created

HttpConfiguration   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 0
cbo 1
dl 0
loc 57
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A redirectsAllowed() 0 4 1
A allowRedirectsMax() 0 4 1
A allowRedirectsReferer() 0 4 1
1
<?php
2
/**
3
 * This file is part of the bee4/transport package.
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 *
7
 * @copyright Bee4 2015
8
 * @author  Stephane HULARD <[email protected]>
9
 * @package Bee4\Transport\Configuration
10
 */
11
12
namespace Bee4\Transport\Configuration;
13
14
/**
15
 * HTTP Configuration implementation
16
 * @package Bee4\Transport\Configuration
17
 */
18
class HttpConfiguration extends Configuration
19
{
20
    /**
21
     * Default configuration values
22
     */
23
    const DEFAULTS = [
24
        'allow_redirects' => [
25
            'max' => null,
26
            'referer' => true,
27
        ],
28
        'accept_encoding' => null,
29
        'user_agent' => null,
30
        'commands' => [
31
            'request' => null,
32
            'post' => null
33
        ]
34
    ];
35
36
    /**
37
     * Build a configuration instance
38
     * @param array $data
39
     */
40
    public function __construct(array $data = [])
41
    {
42
        parent::__construct(array_merge(
43
            self::DEFAULTS,
44
            $data
45
        ));
46
    }
47
48
    /**
49
     * Check if redirects are allowed
50
     * @return boolean
51
     */
52
    public function redirectsAllowed()
53
    {
54
        return $this['allow_redirects']!==false;
55
    }
56
57
    /**
58
     * Define how much redirects must be followed, default null = infinite
59
     * @return Configuration|integer|null
60
     */
61
    public function allowRedirectsMax($max = null)
62
    {
63
        return $this->arrayValue('allow_redirects', 'max', $max);
64
    }
65
66
    /**
67
     * Define if referer must be set during redirection
68
     * @return Configuration|boolean
69
     */
70
    public function allowRedirectsReferer($referer = null)
71
    {
72
        return $this->arrayValue('allow_redirects', 'referer', $referer);
73
    }
74
}
75