Completed
Pull Request — master (#8)
by
unknown
02:37
created

GlobalOptOut::setInputFilePath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Hborras\TwitterAdsSDK\TwitterAds\TailoredAudience;
4
5
use Hborras\TwitterAdsSDK\TwitterAds;
6
use Hborras\TwitterAdsSDK\TwitterAds\Resource;
7
use Hborras\TwitterAdsSDK\TwitterAds\TailoredAudience\Exception\InvalidType;
8
use Hborras\TwitterAdsSDK\Arrayable;
9
10
final class GlobalOptOut extends Resource
11
{
12
    const RESOURCE = 'accounts/{account_id}/tailored_audiences/{route}';
13
14
    // This is a hack to allow PUT requests for an entity without an ID
15
    const RESOURCE_ID_REPLACE = '{route}';
16
    const ROUTE = 'global_opt_out';
17
18
    protected $input_file_path;
19
    protected $list_type;
20
21
    protected $properties = [
22
        'input_file_path',
23
        'list type',
24
    ];
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function getId()
30
    {
31
        return self::ROUTE;
32
    }
33
34
    public function getInputFilePath()
35
    {
36
        return $this->input_file_path;
37
    }
38
39
    public function setInputFilePath($path)
40
    {
41
        $this->input_file_path = $path;
42
    }
43
44
    /**
45
     * @return mixed
46
     */
47
    public function getListType()
48
    {
49
        return $this->assureValidType($this->list_type);
50
    }
51
52
    /**
53
     * @param string $type
54
     */
55
    public function setListType($type)
56
    {
57
        $this->list_type = $this->assureValidType($type);
58
    }
59
60
    /**
61
     * Asserts that the given type is valid
62
     *
63
     * @param string $type
64
     * @throws InvalidType - if type is invalid or null
65
     *
66
     * @return string
67
     */
68 View Code Duplication
    private function assureValidType($type)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
69
    {
70
        foreach (TailoredAudience::getTypes() as $allowedType) {
71
            if ($type === $allowedType) {
72
                return $type;
73
            }
74
        }
75
76
        throw new InvalidType(
77
            sprintf('"%s" is not a valid type for %s', $type, TailoredAudience::class)
78
        );
79
    }
80
}
81