Conditions | 3 |
Paths | 4 |
Total Lines | 87 |
Code Lines | 78 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
41 | public function getConfigTreeBuilder() |
||
42 | { |
||
43 | $treeBuilder = new TreeBuilder(); |
||
44 | $rootNode = $treeBuilder->root($this->alias); |
||
45 | |||
46 | $rootNode |
||
47 | ->addDefaultsIfNotSet() |
||
48 | ->children() |
||
49 | ->scalarNode('psr7_message_factory') |
||
50 | ->cannotBeEmpty() |
||
51 | ->defaultValue('oauth2_security.psr7_message_factory.default') |
||
52 | ->info('PSR7 requests and responses factory') |
||
53 | ->end() |
||
54 | ->end(); |
||
55 | if (class_exists(BearerToken::class)) { |
||
56 | $rootNode |
||
57 | ->children() |
||
58 | ->arrayNode('bearer_token') |
||
59 | ->addDefaultsIfNotSet() |
||
60 | ->canBeDisabled() |
||
61 | ->children() |
||
62 | ->scalarNode('realm') |
||
63 | ->isRequired() |
||
64 | ->info('The realm displayed in the authentication header') |
||
65 | ->end() |
||
66 | ->booleanNode('authorization_header') |
||
67 | ->defaultTrue() |
||
68 | ->info('Allow the access token to be sent in the authorization header (recommended).') |
||
69 | ->end() |
||
70 | ->booleanNode('request_body') |
||
71 | ->defaultFalse() |
||
72 | ->info('Allow the access token to be sent in the request body (not recommended).') |
||
73 | ->end() |
||
74 | ->booleanNode('query_string') |
||
75 | ->defaultFalse() |
||
76 | ->info('Allow the access token to be sent in the query string (not recommended).') |
||
77 | ->end() |
||
78 | ->end() |
||
79 | ->end() |
||
80 | ->end(); |
||
81 | } |
||
82 | |||
83 | if (class_exists(MacToken::class)) { |
||
84 | $rootNode |
||
85 | ->children() |
||
86 | ->arrayNode('mac_token') |
||
87 | ->addDefaultsIfNotSet() |
||
88 | ->canBeDisabled() |
||
89 | ->validate() |
||
90 | ->ifTrue(function ($config) { |
||
91 | return $config['min_length'] > $config['max_length']; |
||
92 | }) |
||
93 | ->thenInvalid('The option "min_length" must not be greater than "max_length".') |
||
94 | ->end() |
||
95 | ->validate() |
||
96 | ->ifTrue(function ($config) { |
||
97 | return !in_array($config['algorithm'], ['hmac-sha-256', 'hmac-sha-1']); |
||
98 | }) |
||
99 | ->thenInvalid('The algorithm is not supported. Please use one of the following one: "hmac-sha-1", "hmac-sha-256".') |
||
100 | ->end() |
||
101 | ->children() |
||
102 | ->integerNode('min_length') |
||
103 | ->defaultValue(50) |
||
104 | ->min(1) |
||
105 | ->info('Minimum length for the generated MAC key') |
||
106 | ->end() |
||
107 | ->integerNode('max_length') |
||
108 | ->defaultValue(100) |
||
109 | ->min(2) |
||
110 | ->info('Maximum length for the generated MAC key') |
||
111 | ->end() |
||
112 | ->scalarNode('algorithm') |
||
113 | ->defaultValue('hmac-sha-256') |
||
114 | ->info('Hashing algorithm. Must be either "hmac-sha-1" or "hmac-sha-256"') |
||
115 | ->end() |
||
116 | ->integerNode('timestamp_lifetime') |
||
117 | ->defaultValue(10) |
||
118 | ->min(1) |
||
119 | ->info('Default lifetime of the MAC') |
||
120 | ->end() |
||
121 | ->end() |
||
122 | ->end() |
||
123 | ->end(); |
||
124 | } |
||
125 | |||
126 | return $treeBuilder; |
||
127 | } |
||
128 | } |
||
129 |