Refund::setDefaultOptions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 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