Refund   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 2
A setDefaultOptions() 0 7 1
A getMethod() 0 4 1
A getPath() 0 4 1
A getData() 0 4 1
1
<?php
2
3
namespace Pin\Charge;
4
5
use Pin\RequestInterface;
6
use Symfony\Component\OptionsResolver\OptionsResolver;
7
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
8
9
class Refund implements RequestInterface
10
{
11
    protected $options;
12
    protected $token;
13
14
    public function __construct($token, array $options = array())
15
    {
16
        // token
17
        if (!is_string($token)) {
18
            throw new InvalidOptionsException('The first argument is expected to be of type "string"');
19
        }
20
21
        $this->token = $token;
22
23
        // options
24
        $resolver = new OptionsResolver();
25
        $this->setDefaultOptions($resolver);
26
27
        $this->options = $resolver->resolve($options);
28
    }
29
30
    protected function setDefaultOptions(OptionsResolver $resolver)
31
    {
32
        $resolver
33
            ->setRequired(array('amount'))
34
            ->setAllowedTypes('amount', 'numeric')
35
        ;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function getMethod()
42
    {
43
        return self::METHOD_POST;
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function getPath()
50
    {
51
        return sprintf('/1/charges/%s/refunds', $this->token);
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function getData()
58
    {
59
        return $this->options;
60
    }
61
}
62