Completed
Pull Request — master (#8)
by
unknown
03:23
created

GlobalOptOut::getInputFilePath()   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 0
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
/**
11
 * Updates a list of user's optout status
12
 *
13
 * @since 2016-06-27
14
 */
15
final class GlobalOptOut extends Resource
16
{
17
    const RESOURCE = 'accounts/{account_id}/tailored_audiences/{route}';
18
19
    // This is a hack to allow PUT requests for an entity without an ID
20
    const RESOURCE_ID_REPLACE = '{route}';
21
    const ROUTE = 'global_opt_out';
22
23
    protected $input_file_path;
24
    protected $list_type;
25
26
    protected $properties = [
27
        'input_file_path',
28
        'list type',
29
    ];
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function getId()
35
    {
36
        return self::ROUTE;
37
    }
38
39
    public function getInputFilePath()
40
    {
41
        return $this->input_file_path;
42
    }
43
44
    public function setInputFilePath($path)
45
    {
46
        $this->input_file_path = $path;
47
    }
48
49
    /**
50
     * @return mixed
51
     */
52
    public function getListType()
53
    {
54
        return $this->assureValidType($this->list_type);
55
    }
56
57
    /**
58
     * @param string $type
59
     */
60
    public function setListType($type)
61
    {
62
        $this->list_type = $this->assureValidType($type);
63
    }
64
65
    /**
66
     * Asserts that the given type is valid
67
     *
68
     * @param string $type
69
     * @throws InvalidType - if type is invalid or null
70
     *
71
     * @return string
72
     */
73 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...
74
    {
75
        foreach (TailoredAudience::getTypes() as $allowedType) {
76
            if ($type === $allowedType) {
77
                return $type;
78
            }
79
        }
80
81
        throw new InvalidType(
82
            sprintf('"%s" is not a valid type for %s', $type, TailoredAudience::class)
83
        );
84
    }
85
86
    /**
87
     * @return array
88
     */
89
    public function getProperties()
90
    {
91
        return $this->properties;
92
    }
93
}
94