Completed
Push — master ( dfec85...be4840 )
by Peter
02:18
created

BaseApi   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A execute() 0 12 1
A prepare() 0 4 2
1
<?php
2
3
namespace PeterColes\Betfair\Api;
4
5
use PeterColes\Betfair\Http\Client as HttpClient;
6
7
abstract class BaseApi
8
{
9
    protected $httpClient;
10
11
    protected $method;
12
13
    public function __construct(HttpClient $httpClient = null)
14
    {
15
        $this->httpClient = $httpClient ?: new HttpClient;
16
    }
17
18
    public function execute($params)
19
    {
20
        $this->method = array_shift($params);
21
22
        return $this->httpClient
23
            ->setMethod('post')
24
            ->setEndPoint(static::ENDPOINT.$this->method.'/')
25
            ->authHeaders()
26
            ->addHeader([ 'Content-Type' => 'application/json' ])
27
            ->setParams($this->prepare($params))
28
            ->send();
29
    }
30
31
    protected function prepare($params)
32
    {
33
        return !empty($params) ? $params[ 0 ] : null;
34
    }
35
}
36