Skip to content

Commit dfae73f

Browse files
committed
Validation Improvements Of Configuration Array
1 parent e4d41fb commit dfae73f

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

TwitterOAuth.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,20 @@ class TwitterOAuth
3434
*/
3535
public function __construct(array $config)
3636
{
37-
$defs = array(
37+
$keys = array(
3838
'consumer_key' => '',
3939
'consumer_secret' => '',
4040
'oauth_token' => '',
41-
'oauth_token_secret' => '',
41+
'oauth_token_secret' => ''
4242
);
4343

44-
$filters = array(
45-
'consumer_key' => FILTER_SANITIZE_STRING,
46-
'consumer_secret' => FILTER_SANITIZE_STRING,
47-
'oauth_token' => FILTER_SANITIZE_STRING,
48-
'oauth_token_secret' => FILTER_SANITIZE_STRING,
49-
);
44+
if (count(array_intersect_key($keys, $config)) !== 4) {
45+
throw new \Exception('Missing parameters in configuration array');
46+
}
5047

51-
$this->config = filter_var_array(array_merge($defs, $config), $filters);
48+
$this->config = $config;
5249

53-
unset($defs, $filters);
50+
unset($keys, $config);
5451
}
5552

5653
/**

0 commit comments

Comments
 (0)