RemoteFileConnectionSettings::getServerType()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace ConfigToken\ConnectionSettings\Types;
4
5
6
use ConfigToken\ConnectionSettings\Exception\ConnectionSettingsException;
7
use ConfigToken\FileClient\Types\RemoteFileClient;
8
9
class RemoteFileConnectionSettings extends GenericConnectionSettings
10
{
11
    const URL = 'url';
12
    const FIELD_NAME = 'field';
13
    const REQUEST_METHOD = 'method';
14
15
    const METHOD_GET = 'GET';
16
    const METHOD_POST = 'POST';
17
18
    /**
19
     * Get the file server type identifier corresponding to the client's implementation.
20
     *
21
     * @return string|null If fallback class for all server types.
22
     */
23
    public static function getServerType()
24
    {
25
        return RemoteFileClient::getServerType();
26
    }
27
28
    /**
29
     * @param array|null $parameters
30
     */
31
    public function __construct(array $parameters = null)
32
    {
33
        parent::__construct($parameters);
34
        if (!$this->hasFieldName()) {
35
            $this->setFieldName('fileName');
36
        }
37
        if (!$this->hasRequestMethod()) {
38
            $this->setRequestMethod(static::METHOD_GET);
39
        }
40
    }
41
42
43
    /**
44
     * Check if the GitLab URL was set.
45
     *
46
     * @return boolean
47
     */
48
    public function hasUrl()
49
    {
50
        return $this->hasParameter(self::URL);
51
    }
52
53
    /**
54
     * Get the GitLab URL.
55
     *
56
     * @return string|null
57
     */
58
    public function getUrl()
59
    {
60
        return $this->getParameter(self::URL);
61
    }
62
63
    /**
64
     * Set the GitLab URL.
65
     *
66
     * @param string $value The new value.
67
     * @return $this
68
     */
69
    public function setUrl($value)
70
    {
71
        return $this->setParameter(self::URL, $value);
72
    }
73
74
    /**
75
     * Check if the field name used in GET/POST to request the file was set.
76
     *
77
     * @return boolean
78
     */
79
    public function hasFieldName()
80
    {
81
        return $this->hasParameter(self::FIELD_NAME);
82
    }
83
84
    /**
85
     * Get the field name used in GET/POST to request the file.
86
     *
87
     * @return string|null
88
     */
89
    public function getFieldName()
90
    {
91
        return $this->getParameter(self::FIELD_NAME);
92
    }
93
94
    /**
95
     * Set the field name used in GET/POST to request the file.
96
     *
97
     * @param string $value The new value.
98
     * @return $this
99
     */
100
    public function setFieldName($value)
101
    {
102
        return $this->setParameter(self::FIELD_NAME, $value);
103
    }
104
105
    /**
106
     * Check if the request method was set.
107
     *
108
     * @return boolean
109
     */
110
    public function hasRequestMethod()
111
    {
112
        return $this->hasParameter(self::REQUEST_METHOD);
113
    }
114
115
    /**
116
     * Get the request method.
117
     *
118
     * @return string|null
119
     */
120
    public function getRequestMethod()
121
    {
122
        return $this->getParameter(self::REQUEST_METHOD);
123
    }
124
125
    /**
126
     * Set the request method.
127
     *
128
     * @param string $value The new value.
129
     * @return $this
130
     */
131
    public function setRequestMethod($value)
132
    {
133
        return $this->setParameter(self::REQUEST_METHOD, $value);
134
    }
135
136
    /**
137
     * Get the required keys.
138
     *
139
     * @return array
140
     */
141
    protected static function getRequiredKeys()
142
    {
143
        return array(static::URL, static::FIELD_NAME, static::REQUEST_METHOD);
144
    }
145
146
    /**
147
     * Validate the connection parameters and throw appropriate exceptions.
148
     *
149
     * @throws ConnectionSettingsException
150
     */
151
    public function validate()
152
    {
153
        parent::validate();
154
        $requestMethod = $this->getRequestMethod();
155
        if (($requestMethod != static::METHOD_GET) && ($requestMethod != static::METHOD_GET)) {
156
            throw new ConnectionSettingsException(
157
                $this,
158
                sprintf('Invalid request method "%s"', $requestMethod)
159
            );
160
        }
161
    }
162
163
}