Completed
Branch develop (8213ca)
by Neomerx
02:19
created

DefaultSettingsTrait::getDefaultSettings()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 96
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 96
ccs 16
cts 16
cp 1
rs 8.3859
cc 1
eloc 15
nc 1
nop 0
crap 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php namespace Neomerx\Cors\Strategies;
2
3
/**
4
 * Copyright 2015 [email protected] (www.neomerx.com)
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
use \Neomerx\Cors\Contracts\Http\ParsedUrlInterface;
20
21
/**
22
 * @package Neomerx\Cors
23
 */
24
trait DefaultSettingsTrait
25
{
26
    /**
27
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<*,array|false|integer>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
28
     */
29 19
    protected function getDefaultSettings()
30
    {
31
        return [
32
            /**
33
             * Array should be in parse_url() result format.
34
             * @see http://php.net/manual/function.parse-url.php
35
             */
36 19
            Settings::KEY_SERVER_ORIGIN        => [
37 19
                Settings::KEY_SERVER_ORIGIN_SCHEME => '',
38 19
                Settings::KEY_SERVER_ORIGIN_HOST   => '',
39 19
                Settings::KEY_SERVER_ORIGIN_PORT   => ParsedUrlInterface::DEFAULT_PORT,
40 19
            ],
41
            /**
42
             * A list of allowed request origins (lower-cased, no trail slashes).
43
             * Value `true` enables and value `null` disables origin.
44
             * If all origins '*' are enabled all settings for other origins are ignored.
45
             * For example, [
46
             *     'http://example.com:123'     => true,
47
             *     'http://evil.com'            => null,
48
             *     Settings::VALUE_ALLOW_ORIGIN_ALL => null,
49
             * ];
50
             */
51 19
            Settings::KEY_ALLOWED_ORIGINS      => [],
52
            /**
53
             * A list of allowed request methods (case sensitive).
54
             * Value `true` enables and value `null` disables method.
55
             * For example, [
56
             *     'GET'    => true,
57
             *     'PATCH'  => true,
58
             *     'POST'   => true,
59
             *     'PUT'    => null,
60
             *     'DELETE' => true,
61
             * ];
62
             * Security Note: you have to remember CORS is not access control system and you should not expect all
63
             * cross-origin requests will have pre-flights. For so-called 'simple' methods with so-called 'simple'
64
             * headers request will be made without pre-flight. Thus you can not restrict such requests with CORS
65
             * and should use other means.
66
             * For example method 'GET' without any headers or with only 'simple' headers will not have pre-flight
67
             * request so disabling it will not restrict access to resource(s).
68
             * You can read more on 'simple' methods at http://www.w3.org/TR/cors/#simple-method
69
             */
70 19
            Settings::KEY_ALLOWED_METHODS      => [],
71
            /**
72
             * A list of allowed request headers (lower-cased). Value `true` enables and
73
             * value `null` disables header.
74
             * For example, [
75
             *     'content-type'                => true,
76
             *     'x-custom-request-header'     => null,
77
             *     Settings::VALUE_ALLOW_ALL_HEADERS => null,
78
             * ];
79
             * Security Note: you have to remember CORS is not access control system and you should not expect all
80
             * cross-origin requests will have pre-flights. For so-called 'simple' methods with so-called 'simple'
81
             * headers request will be made without pre-flight. Thus you can not restrict such requests with CORS
82
             * and should use other means.
83
             * For example method 'GET' without any headers or with only 'simple' headers will not have pre-flight
84
             * request so disabling it will not restrict access to resource(s).
85
             * You can read more on 'simple' headers at http://www.w3.org/TR/cors/#simple-header
86
             */
87 19
            Settings::KEY_ALLOWED_HEADERS      => [],
88
            /**
89
             * A list of headers (case insensitive) which will be made accessible to
90
             * user agent (browser) in response.
91
             * Value `true` enables and value `null` disables header.
92
             * For example, [
93
             *     'Content-Type'             => true,
94
             *     'X-Custom-Response-Header' => true,
95
             *     'X-Disabled-Header'        => null,
96
             * ];
97
             */
98 19
            Settings::KEY_EXPOSED_HEADERS      => [],
99
            /**
100
             * If access with credentials is supported by the resource.
101
             */
102 19
            Settings::KEY_IS_USING_CREDENTIALS => false,
103
            /**
104
             * Pre-flight response cache max period in seconds.
105
             */
106 19
            Settings::KEY_FLIGHT_CACHE_MAX_AGE => 0,
107
            /**
108
             * If allowed methods should be added to pre-flight response when
109
             * 'simple' method is requested (see #6.2.9 CORS).
110
             * @see http://www.w3.org/TR/cors/#resource-preflight-requests
111
             */
112 19
            Settings::KEY_IS_FORCE_ADD_METHODS => false,
113
            /**
114
             * If allowed headers should be added when request headers are 'simple' and
115
             * non of them is 'Content-Type' (see #6.2.10 CORS).
116
             * @see http://www.w3.org/TR/cors/#resource-preflight-requests
117
             */
118 19
            Settings::KEY_IS_FORCE_ADD_HEADERS => false,
119
            /**
120
             * If request 'Host' header should be checked against server's origin.
121
             */
122 19
            Settings::KEY_IS_CHECK_HOST        => false,
123 19
        ];
124
    }
125
}
126