Passed
Push — master ( 14fbd7...a7a005 )
by
unknown
55s queued 15s
created
src/Provider/Slack.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 
53 53
         $data = new Data\Collection($response);
54 54
 
55
-        if (!$data->exists('ok') || !$data->get('ok')) {
55
+        if ( ! $data->exists('ok') || ! $data->get('ok')) {
56 56
             throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
57 57
         }
58 58
 
@@ -87,14 +87,14 @@  discard block
 block discarded – undo
87 87
         $maxSize = 0;
88 88
         foreach ($data->filter('user')->properties() as $property) {
89 89
             if (preg_match('/^image_(\d+)$/', $property, $matches) === 1) {
90
-                $availableSize = (int)$matches[1];
90
+                $availableSize = (int) $matches[1];
91 91
                 if ($maxSize < $availableSize) {
92 92
                     $maxSize = $availableSize;
93 93
                 }
94 94
             }
95 95
         }
96 96
         if ($maxSize > 0) {
97
-            return $data->filter('user')->get('image_' . $maxSize);
97
+            return $data->filter('user')->get('image_'.$maxSize);
98 98
         }
99 99
         return null;
100 100
     }
Please login to merge, or discard this patch.
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -17,84 +17,84 @@
 block discarded – undo
17 17
  */
18 18
 class Slack extends OAuth2
19 19
 {
20
-    /**
21
-     * {@inheritdoc}
22
-     */
23
-    protected $scope = 'identity.basic identity.email identity.avatar';
20
+	/**
21
+	 * {@inheritdoc}
22
+	 */
23
+	protected $scope = 'identity.basic identity.email identity.avatar';
24 24
 
25
-    /**
26
-     * {@inheritdoc}
27
-     */
28
-    protected $apiBaseUrl = 'https://slack.com/';
25
+	/**
26
+	 * {@inheritdoc}
27
+	 */
28
+	protected $apiBaseUrl = 'https://slack.com/';
29 29
 
30
-    /**
31
-     * {@inheritdoc}
32
-     */
33
-    protected $authorizeUrl = 'https://slack.com/oauth/authorize';
30
+	/**
31
+	 * {@inheritdoc}
32
+	 */
33
+	protected $authorizeUrl = 'https://slack.com/oauth/authorize';
34 34
 
35
-    /**
36
-     * {@inheritdoc}
37
-     */
38
-    protected $accessTokenUrl = 'https://slack.com/api/oauth.access';
35
+	/**
36
+	 * {@inheritdoc}
37
+	 */
38
+	protected $accessTokenUrl = 'https://slack.com/api/oauth.access';
39 39
 
40
-    /**
41
-     * {@inheritdoc}
42
-     */
43
-    protected $apiDocumentation = 'https://api.slack.com/docs/sign-in-with-slack';
40
+	/**
41
+	 * {@inheritdoc}
42
+	 */
43
+	protected $apiDocumentation = 'https://api.slack.com/docs/sign-in-with-slack';
44 44
 
45
-    /**
46
-     * {@inheritdoc}
47
-     */
48
-    public function getUserProfile()
49
-    {
50
-        $response = $this->apiRequest('api/users.identity');
45
+	/**
46
+	 * {@inheritdoc}
47
+	 */
48
+	public function getUserProfile()
49
+	{
50
+		$response = $this->apiRequest('api/users.identity');
51 51
 
52
-        $data = new Data\Collection($response);
52
+		$data = new Data\Collection($response);
53 53
 
54
-        if (!$data->exists('ok') || !$data->get('ok')) {
55
-            throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
56
-        }
54
+		if (!$data->exists('ok') || !$data->get('ok')) {
55
+			throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
56
+		}
57 57
 
58
-        $userProfile = new User\Profile();
58
+		$userProfile = new User\Profile();
59 59
 
60
-        $userProfile->identifier = $data->filter('user')->get('id');
61
-        $userProfile->displayName = $data->filter('user')->get('name');
62
-        $userProfile->email = $data->filter('user')->get('email');
63
-        $userProfile->photoURL = $this->findLargestImage($data);
60
+		$userProfile->identifier = $data->filter('user')->get('id');
61
+		$userProfile->displayName = $data->filter('user')->get('name');
62
+		$userProfile->email = $data->filter('user')->get('email');
63
+		$userProfile->photoURL = $this->findLargestImage($data);
64 64
 
65
-        return $userProfile;
66
-    }
65
+		return $userProfile;
66
+	}
67 67
 
68
-    /**
69
-     * Returns the url of the image with the highest resolution in the user
70
-     * object.
71
-     *
72
-     * Slack sends multiple image urls with different resolutions. As they make
73
-     * no guarantees which resolutions will be included we have to search all
74
-     * <code>image_*</code> properties for the one with the highest resolution.
75
-     * The resolution is attached to the property name such as
76
-     * <code>image_32</code> or <code>image_192</code>.
77
-     *
78
-     * @param Data\Collection $data response object as returned by
79
-     *     <code>api/users.identity</code>
80
-     *
81
-     * @return string|null the value of the <code>image_*</code> property with
82
-     *     the highest resolution.
83
-     */
84
-    private function findLargestImage(Data\Collection $data)
85
-    {
86
-        $maxSize = 0;
87
-        foreach ($data->filter('user')->properties() as $property) {
88
-            if (preg_match('/^image_(\d+)$/', $property, $matches) === 1) {
89
-                $availableSize = (int)$matches[1];
90
-                if ($maxSize < $availableSize) {
91
-                    $maxSize = $availableSize;
92
-                }
93
-            }
94
-        }
95
-        if ($maxSize > 0) {
96
-            return $data->filter('user')->get('image_' . $maxSize);
97
-        }
98
-        return null;
99
-    }
68
+	/**
69
+	 * Returns the url of the image with the highest resolution in the user
70
+	 * object.
71
+	 *
72
+	 * Slack sends multiple image urls with different resolutions. As they make
73
+	 * no guarantees which resolutions will be included we have to search all
74
+	 * <code>image_*</code> properties for the one with the highest resolution.
75
+	 * The resolution is attached to the property name such as
76
+	 * <code>image_32</code> or <code>image_192</code>.
77
+	 *
78
+	 * @param Data\Collection $data response object as returned by
79
+	 *     <code>api/users.identity</code>
80
+	 *
81
+	 * @return string|null the value of the <code>image_*</code> property with
82
+	 *     the highest resolution.
83
+	 */
84
+	private function findLargestImage(Data\Collection $data)
85
+	{
86
+		$maxSize = 0;
87
+		foreach ($data->filter('user')->properties() as $property) {
88
+			if (preg_match('/^image_(\d+)$/', $property, $matches) === 1) {
89
+				$availableSize = (int)$matches[1];
90
+				if ($maxSize < $availableSize) {
91
+					$maxSize = $availableSize;
92
+				}
93
+			}
94
+		}
95
+		if ($maxSize > 0) {
96
+			return $data->filter('user')->get('image_' . $maxSize);
97
+		}
98
+		return null;
99
+	}
100 100
 }
Please login to merge, or discard this patch.
src/Provider/Discord.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 
66 66
         $data = new Data\Collection($response);
67 67
 
68
-        if (!$data->exists('id')) {
68
+        if ( ! $data->exists('id')) {
69 69
             throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
70 70
         }
71 71
 
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 
88 88
         if ($data->get('avatar')) {
89 89
             $userProfile->photoURL = 'https://cdn.discordapp.com/avatars/';
90
-            $userProfile->photoURL .= $data->get('id') . '/' . $data->get('avatar') . '.png';
90
+            $userProfile->photoURL .= $data->get('id').'/'.$data->get('avatar').'.png';
91 91
         }
92 92
 
93 93
         return $userProfile;
Please login to merge, or discard this patch.
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -17,80 +17,80 @@
 block discarded – undo
17 17
  */
18 18
 class Discord extends OAuth2
19 19
 {
20
-    /**
21
-     * {@inheritdoc}
22
-     */
23
-    protected $scope = 'identify email';
24
-
25
-    /**
26
-     * {@inheritdoc}
27
-     */
28
-    protected $apiBaseUrl = 'https://discordapp.com/api/';
29
-
30
-    /**
31
-     * {@inheritdoc}
32
-     */
33
-    protected $authorizeUrl = 'https://discordapp.com/api/oauth2/authorize';
34
-
35
-    /**
36
-     * {@inheritdoc}
37
-     */
38
-    protected $accessTokenUrl = 'https://discordapp.com/api/oauth2/token';
39
-
40
-    /**
41
-     * {@inheritdoc}
42
-     */
43
-    protected $apiDocumentation = 'https://discordapp.com/developers/docs/topics/oauth2';
44
-
45
-    /**
46
-     * {@inheritdoc}
47
-     */
48
-    protected function initialize()
49
-    {
50
-        parent::initialize();
51
-
52
-        if ($this->isRefreshTokenAvailable()) {
53
-            $this->tokenRefreshParameters += [
54
-                'client_id' => $this->clientId,
55
-                'client_secret' => $this->clientSecret,
56
-            ];
57
-        }
58
-    }
59
-
60
-    /**
61
-     * {@inheritdoc}
62
-     */
63
-    public function getUserProfile()
64
-    {
65
-        $response = $this->apiRequest('users/@me');
66
-
67
-        $data = new Data\Collection($response);
68
-
69
-        if (!$data->exists('id')) {
70
-            throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
71
-        }
72
-
73
-        // Makes display name more unique.
74
-        $displayName = $data->get('username') ?: $data->get('login');
75
-        if ($discriminator = $data->get('discriminator')) {
76
-            $displayName .= "#{$discriminator}";
77
-        }
78
-
79
-        $userProfile = new User\Profile();
80
-
81
-        $userProfile->identifier = $data->get('id');
82
-        $userProfile->displayName = $displayName;
83
-        $userProfile->email = $data->get('email');
84
-
85
-        if ($data->get('verified')) {
86
-            $userProfile->emailVerified = $data->get('email');
87
-        }
88
-
89
-        if ($data->get('avatar')) {
90
-            $userProfile->photoURL = 'https://cdn.discordapp.com/avatars/';
91
-            $userProfile->photoURL .= $data->get('id') . '/' . $data->get('avatar') . '.png';
92
-        }
93
-
94
-        return $userProfile;
95
-    }
20
+	/**
21
+	 * {@inheritdoc}
22
+	 */
23
+	protected $scope = 'identify email';
24
+
25
+	/**
26
+	 * {@inheritdoc}
27
+	 */
28
+	protected $apiBaseUrl = 'https://discordapp.com/api/';
29
+
30
+	/**
31
+	 * {@inheritdoc}
32
+	 */
33
+	protected $authorizeUrl = 'https://discordapp.com/api/oauth2/authorize';
34
+
35
+	/**
36
+	 * {@inheritdoc}
37
+	 */
38
+	protected $accessTokenUrl = 'https://discordapp.com/api/oauth2/token';
39
+
40
+	/**
41
+	 * {@inheritdoc}
42
+	 */
43
+	protected $apiDocumentation = 'https://discordapp.com/developers/docs/topics/oauth2';
44
+
45
+	/**
46
+	 * {@inheritdoc}
47
+	 */
48
+	protected function initialize()
49
+	{
50
+		parent::initialize();
51
+
52
+		if ($this->isRefreshTokenAvailable()) {
53
+			$this->tokenRefreshParameters += [
54
+				'client_id' => $this->clientId,
55
+				'client_secret' => $this->clientSecret,
56
+			];
57
+		}
58
+	}
59
+
60
+	/**
61
+	 * {@inheritdoc}
62
+	 */
63
+	public function getUserProfile()
64
+	{
65
+		$response = $this->apiRequest('users/@me');
66
+
67
+		$data = new Data\Collection($response);
68
+
69
+		if (!$data->exists('id')) {
70
+			throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
71
+		}
72
+
73
+		// Makes display name more unique.
74
+		$displayName = $data->get('username') ?: $data->get('login');
75
+		if ($discriminator = $data->get('discriminator')) {
76
+			$displayName .= "#{$discriminator}";
77
+		}
78
+
79
+		$userProfile = new User\Profile();
80
+
81
+		$userProfile->identifier = $data->get('id');
82
+		$userProfile->displayName = $displayName;
83
+		$userProfile->email = $data->get('email');
84
+
85
+		if ($data->get('verified')) {
86
+			$userProfile->emailVerified = $data->get('email');
87
+		}
88
+
89
+		if ($data->get('avatar')) {
90
+			$userProfile->photoURL = 'https://cdn.discordapp.com/avatars/';
91
+			$userProfile->photoURL .= $data->get('id') . '/' . $data->get('avatar') . '.png';
92
+		}
93
+
94
+		return $userProfile;
95
+	}
96 96
 }
Please login to merge, or discard this patch.
src/Provider/Dropbox.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@
 block discarded – undo
51 51
 
52 52
         $data = new Data\Collection($response);
53 53
 
54
-        if (!$data->exists('account_id') || !$data->get('account_id')) {
54
+        if ( ! $data->exists('account_id') || ! $data->get('account_id')) {
55 55
             throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
56 56
         }
57 57
 
Please login to merge, or discard this patch.
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -17,58 +17,58 @@
 block discarded – undo
17 17
  */
18 18
 class Dropbox extends OAuth2
19 19
 {
20
-    /**
21
-     * {@inheritdoc}
22
-     */
23
-    protected $scope = 'account_info.read';
20
+	/**
21
+	 * {@inheritdoc}
22
+	 */
23
+	protected $scope = 'account_info.read';
24 24
 
25
-    /**
26
-     * {@inheritdoc}
27
-     */
28
-    protected $apiBaseUrl = 'https://api.dropbox.com/2/';
25
+	/**
26
+	 * {@inheritdoc}
27
+	 */
28
+	protected $apiBaseUrl = 'https://api.dropbox.com/2/';
29 29
 
30
-    /**
31
-     * {@inheritdoc}
32
-     */
33
-    protected $authorizeUrl = 'https://www.dropbox.com/1/oauth2/authorize';
30
+	/**
31
+	 * {@inheritdoc}
32
+	 */
33
+	protected $authorizeUrl = 'https://www.dropbox.com/1/oauth2/authorize';
34 34
 
35
-    /**
36
-     * {@inheritdoc}
37
-     */
38
-    protected $accessTokenUrl = 'https://api.dropbox.com/1/oauth2/token';
35
+	/**
36
+	 * {@inheritdoc}
37
+	 */
38
+	protected $accessTokenUrl = 'https://api.dropbox.com/1/oauth2/token';
39 39
 
40
-    /**
41
-     * {@inheritdoc}
42
-     */
43
-    protected $apiDocumentation = 'https://www.dropbox.com/developers/documentation/http/documentation';
40
+	/**
41
+	 * {@inheritdoc}
42
+	 */
43
+	protected $apiDocumentation = 'https://www.dropbox.com/developers/documentation/http/documentation';
44 44
 
45
-    /**
46
-     * {@inheritdoc}
47
-     */
48
-    public function getUserProfile()
49
-    {
50
-        $response = $this->apiRequest('users/get_current_account', 'POST', [], [], true);
45
+	/**
46
+	 * {@inheritdoc}
47
+	 */
48
+	public function getUserProfile()
49
+	{
50
+		$response = $this->apiRequest('users/get_current_account', 'POST', [], [], true);
51 51
 
52
-        $data = new Data\Collection($response);
52
+		$data = new Data\Collection($response);
53 53
 
54
-        if (!$data->exists('account_id') || !$data->get('account_id')) {
55
-            throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
56
-        }
54
+		if (!$data->exists('account_id') || !$data->get('account_id')) {
55
+			throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
56
+		}
57 57
 
58
-        $userProfile = new User\Profile();
58
+		$userProfile = new User\Profile();
59 59
 
60
-        $userProfile->identifier = $data->get('account_id');
61
-        $userProfile->displayName = $data->filter('name')->get('display_name');
62
-        $userProfile->firstName = $data->filter('name')->get('given_name');
63
-        $userProfile->lastName = $data->filter('name')->get('surname');
64
-        $userProfile->email = $data->get('email');
65
-        $userProfile->photoURL = $data->get('profile_photo_url');
66
-        $userProfile->language = $data->get('locale');
67
-        $userProfile->country = $data->get('country');
68
-        if ($data->get('email_verified')) {
69
-            $userProfile->emailVerified = $data->get('email');
70
-        }
60
+		$userProfile->identifier = $data->get('account_id');
61
+		$userProfile->displayName = $data->filter('name')->get('display_name');
62
+		$userProfile->firstName = $data->filter('name')->get('given_name');
63
+		$userProfile->lastName = $data->filter('name')->get('surname');
64
+		$userProfile->email = $data->get('email');
65
+		$userProfile->photoURL = $data->get('profile_photo_url');
66
+		$userProfile->language = $data->get('locale');
67
+		$userProfile->country = $data->get('country');
68
+		if ($data->get('email_verified')) {
69
+			$userProfile->emailVerified = $data->get('email');
70
+		}
71 71
 
72
-        return $userProfile;
73
-    }
72
+		return $userProfile;
73
+	}
74 74
 }
Please login to merge, or discard this patch.
src/Provider/WeChatChina.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -12,23 +12,23 @@
 block discarded – undo
12 12
  */
13 13
 class WeChatChina extends WeChat
14 14
 {
15
-    /**
16
-     * {@inheritdoc}
17
-     */
18
-    protected $apiBaseUrl = 'https://api.weixin.qq.com/sns/';
15
+	/**
16
+	 * {@inheritdoc}
17
+	 */
18
+	protected $apiBaseUrl = 'https://api.weixin.qq.com/sns/';
19 19
 
20
-    /**
21
-     * {@inheritdoc}
22
-     */
23
-    protected $accessTokenUrl = 'https://api.weixin.qq.com/sns/oauth2/access_token';
20
+	/**
21
+	 * {@inheritdoc}
22
+	 */
23
+	protected $accessTokenUrl = 'https://api.weixin.qq.com/sns/oauth2/access_token';
24 24
 
25
-    /**
26
-     * {@inheritdoc}
27
-     */
28
-    protected $tokenRefreshUrl = 'https://api.weixin.qq.com/sns/oauth2/refresh_token';
25
+	/**
26
+	 * {@inheritdoc}
27
+	 */
28
+	protected $tokenRefreshUrl = 'https://api.weixin.qq.com/sns/oauth2/refresh_token';
29 29
 
30
-    /**
31
-     * {@ịnheritdoc}
32
-     */
33
-    protected $accessTokenInfoUrl = 'https://api.weixin.qq.com/sns/auth';
30
+	/**
31
+	 * {@ịnheritdoc}
32
+	 */
33
+	protected $accessTokenInfoUrl = 'https://api.weixin.qq.com/sns/auth';
34 34
 }
Please login to merge, or discard this patch.
src/Logger/LoggerInterface.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -12,39 +12,39 @@
 block discarded – undo
12 12
  */
13 13
 interface LoggerInterface
14 14
 {
15
-    /**
16
-     * Interesting events.
17
-     *
18
-     * Example: User logs in, SQL logs.
19
-     *
20
-     * @param string $message
21
-     * @param array $context
22
-     */
23
-    public function info($message, array $context = array());
15
+	/**
16
+	 * Interesting events.
17
+	 *
18
+	 * Example: User logs in, SQL logs.
19
+	 *
20
+	 * @param string $message
21
+	 * @param array $context
22
+	 */
23
+	public function info($message, array $context = array());
24 24
 
25
-    /**
26
-     * Detailed debug information.
27
-     *
28
-     * @param string $message
29
-     * @param array $context
30
-     */
31
-    public function debug($message, array $context = array());
25
+	/**
26
+	 * Detailed debug information.
27
+	 *
28
+	 * @param string $message
29
+	 * @param array $context
30
+	 */
31
+	public function debug($message, array $context = array());
32 32
 
33
-    /**
34
-     * Runtime errors that do not require immediate action but should typically
35
-     * be logged and monitored.
36
-     *
37
-     * @param string $message
38
-     * @param array $context
39
-     */
40
-    public function error($message, array $context = array());
33
+	/**
34
+	 * Runtime errors that do not require immediate action but should typically
35
+	 * be logged and monitored.
36
+	 *
37
+	 * @param string $message
38
+	 * @param array $context
39
+	 */
40
+	public function error($message, array $context = array());
41 41
 
42
-    /**
43
-     * Logs with an arbitrary level.
44
-     *
45
-     * @param mixed $level
46
-     * @param string $message
47
-     * @param array $context
48
-     */
49
-    public function log($level, $message, array $context = array());
42
+	/**
43
+	 * Logs with an arbitrary level.
44
+	 *
45
+	 * @param mixed $level
46
+	 * @param string $message
47
+	 * @param array $context
48
+	 */
49
+	public function log($level, $message, array $context = array());
50 50
 }
Please login to merge, or discard this patch.
src/Logger/Logger.php 2 patches
Indentation   +111 added lines, -111 removed lines patch added patch discarded remove patch
@@ -15,115 +15,115 @@
 block discarded – undo
15 15
  */
16 16
 class Logger implements LoggerInterface
17 17
 {
18
-    const NONE = 'none';  // turn logging off
19
-    const DEBUG = 'debug'; // debug, info and error messages
20
-    const INFO = 'info';  // info and error messages
21
-    const ERROR = 'error'; // only error messages
22
-
23
-    /**
24
-     * Debug level.
25
-     *
26
-     * One of Logger::NONE, Logger::DEBUG, Logger::INFO, Logger::ERROR
27
-     *
28
-     * @var string
29
-     */
30
-    protected $level;
31
-
32
-    /**
33
-     * Path to file writeable by the web server. Required if $this->level !== Logger::NONE.
34
-     *
35
-     * @var string
36
-     */
37
-    protected $file;
38
-
39
-    /**
40
-     * @param bool|string $level One of Logger::NONE, Logger::DEBUG, Logger::INFO, Logger::ERROR
41
-     * @param string $file File where to write messages
42
-     *
43
-     * @throws InvalidArgumentException
44
-     * @throws RuntimeException
45
-     */
46
-    public function __construct($level, $file)
47
-    {
48
-        $this->level = self::NONE;
49
-
50
-        if ($level && $level !== self::NONE) {
51
-            $this->initialize($file);
52
-
53
-            $this->level = $level === true ? Logger::DEBUG : $level;
54
-            $this->file = $file;
55
-        }
56
-    }
57
-
58
-    /**
59
-     * @param string $file
60
-     *
61
-     * @throws InvalidArgumentException
62
-     * @throws RuntimeException
63
-     */
64
-    protected function initialize($file)
65
-    {
66
-        if (!$file) {
67
-            throw new InvalidArgumentException('Log file is not specified.');
68
-        }
69
-
70
-        if (!file_exists($file) && !touch($file)) {
71
-            throw new RuntimeException(sprintf('Log file %s can not be created.', $file));
72
-        }
73
-
74
-        if (!is_writable($file)) {
75
-            throw new RuntimeException(sprintf('Log file %s is not writeable.', $file));
76
-        }
77
-    }
78
-
79
-    /**
80
-     * @inheritdoc
81
-     */
82
-    public function info($message, array $context = [])
83
-    {
84
-        if (!in_array($this->level, [self::DEBUG, self::INFO])) {
85
-            return;
86
-        }
87
-
88
-        $this->log(self::INFO, $message, $context);
89
-    }
90
-
91
-    /**
92
-     * @inheritdoc
93
-     */
94
-    public function debug($message, array $context = [])
95
-    {
96
-        if (!in_array($this->level, [self::DEBUG])) {
97
-            return;
98
-        }
99
-
100
-        $this->log(self::DEBUG, $message, $context);
101
-    }
102
-
103
-    /**
104
-     * @inheritdoc
105
-     */
106
-    public function error($message, array $context = [])
107
-    {
108
-        if (!in_array($this->level, [self::DEBUG, self::INFO, self::ERROR])) {
109
-            return;
110
-        }
111
-
112
-        $this->log(self::ERROR, $message, $context);
113
-    }
114
-
115
-    /**
116
-     * @inheritdoc
117
-     */
118
-    public function log($level, $message, array $context = [])
119
-    {
120
-        $datetime = new \DateTime();
121
-        $datetime = $datetime->format(DATE_ATOM);
122
-
123
-        $content = sprintf('%s -- %s -- %s -- %s', $level, $_SERVER['REMOTE_ADDR'], $datetime, $message);
124
-        $content .= ($context ? "\n" . print_r($context, true) : '');
125
-        $content .= "\n";
126
-
127
-        file_put_contents($this->file, $content, FILE_APPEND);
128
-    }
18
+	const NONE = 'none';  // turn logging off
19
+	const DEBUG = 'debug'; // debug, info and error messages
20
+	const INFO = 'info';  // info and error messages
21
+	const ERROR = 'error'; // only error messages
22
+
23
+	/**
24
+	 * Debug level.
25
+	 *
26
+	 * One of Logger::NONE, Logger::DEBUG, Logger::INFO, Logger::ERROR
27
+	 *
28
+	 * @var string
29
+	 */
30
+	protected $level;
31
+
32
+	/**
33
+	 * Path to file writeable by the web server. Required if $this->level !== Logger::NONE.
34
+	 *
35
+	 * @var string
36
+	 */
37
+	protected $file;
38
+
39
+	/**
40
+	 * @param bool|string $level One of Logger::NONE, Logger::DEBUG, Logger::INFO, Logger::ERROR
41
+	 * @param string $file File where to write messages
42
+	 *
43
+	 * @throws InvalidArgumentException
44
+	 * @throws RuntimeException
45
+	 */
46
+	public function __construct($level, $file)
47
+	{
48
+		$this->level = self::NONE;
49
+
50
+		if ($level && $level !== self::NONE) {
51
+			$this->initialize($file);
52
+
53
+			$this->level = $level === true ? Logger::DEBUG : $level;
54
+			$this->file = $file;
55
+		}
56
+	}
57
+
58
+	/**
59
+	 * @param string $file
60
+	 *
61
+	 * @throws InvalidArgumentException
62
+	 * @throws RuntimeException
63
+	 */
64
+	protected function initialize($file)
65
+	{
66
+		if (!$file) {
67
+			throw new InvalidArgumentException('Log file is not specified.');
68
+		}
69
+
70
+		if (!file_exists($file) && !touch($file)) {
71
+			throw new RuntimeException(sprintf('Log file %s can not be created.', $file));
72
+		}
73
+
74
+		if (!is_writable($file)) {
75
+			throw new RuntimeException(sprintf('Log file %s is not writeable.', $file));
76
+		}
77
+	}
78
+
79
+	/**
80
+	 * @inheritdoc
81
+	 */
82
+	public function info($message, array $context = [])
83
+	{
84
+		if (!in_array($this->level, [self::DEBUG, self::INFO])) {
85
+			return;
86
+		}
87
+
88
+		$this->log(self::INFO, $message, $context);
89
+	}
90
+
91
+	/**
92
+	 * @inheritdoc
93
+	 */
94
+	public function debug($message, array $context = [])
95
+	{
96
+		if (!in_array($this->level, [self::DEBUG])) {
97
+			return;
98
+		}
99
+
100
+		$this->log(self::DEBUG, $message, $context);
101
+	}
102
+
103
+	/**
104
+	 * @inheritdoc
105
+	 */
106
+	public function error($message, array $context = [])
107
+	{
108
+		if (!in_array($this->level, [self::DEBUG, self::INFO, self::ERROR])) {
109
+			return;
110
+		}
111
+
112
+		$this->log(self::ERROR, $message, $context);
113
+	}
114
+
115
+	/**
116
+	 * @inheritdoc
117
+	 */
118
+	public function log($level, $message, array $context = [])
119
+	{
120
+		$datetime = new \DateTime();
121
+		$datetime = $datetime->format(DATE_ATOM);
122
+
123
+		$content = sprintf('%s -- %s -- %s -- %s', $level, $_SERVER['REMOTE_ADDR'], $datetime, $message);
124
+		$content .= ($context ? "\n" . print_r($context, true) : '');
125
+		$content .= "\n";
126
+
127
+		file_put_contents($this->file, $content, FILE_APPEND);
128
+	}
129 129
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -15,9 +15,9 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class Logger implements LoggerInterface
17 17
 {
18
-    const NONE = 'none';  // turn logging off
18
+    const NONE = 'none'; // turn logging off
19 19
     const DEBUG = 'debug'; // debug, info and error messages
20
-    const INFO = 'info';  // info and error messages
20
+    const INFO = 'info'; // info and error messages
21 21
     const ERROR = 'error'; // only error messages
22 22
 
23 23
     /**
@@ -63,15 +63,15 @@  discard block
 block discarded – undo
63 63
      */
64 64
     protected function initialize($file)
65 65
     {
66
-        if (!$file) {
66
+        if ( ! $file) {
67 67
             throw new InvalidArgumentException('Log file is not specified.');
68 68
         }
69 69
 
70
-        if (!file_exists($file) && !touch($file)) {
70
+        if ( ! file_exists($file) && ! touch($file)) {
71 71
             throw new RuntimeException(sprintf('Log file %s can not be created.', $file));
72 72
         }
73 73
 
74
-        if (!is_writable($file)) {
74
+        if ( ! is_writable($file)) {
75 75
             throw new RuntimeException(sprintf('Log file %s is not writeable.', $file));
76 76
         }
77 77
     }
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
      */
82 82
     public function info($message, array $context = [])
83 83
     {
84
-        if (!in_array($this->level, [self::DEBUG, self::INFO])) {
84
+        if ( ! in_array($this->level, [self::DEBUG, self::INFO])) {
85 85
             return;
86 86
         }
87 87
 
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
      */
94 94
     public function debug($message, array $context = [])
95 95
     {
96
-        if (!in_array($this->level, [self::DEBUG])) {
96
+        if ( ! in_array($this->level, [self::DEBUG])) {
97 97
             return;
98 98
         }
99 99
 
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
      */
106 106
     public function error($message, array $context = [])
107 107
     {
108
-        if (!in_array($this->level, [self::DEBUG, self::INFO, self::ERROR])) {
108
+        if ( ! in_array($this->level, [self::DEBUG, self::INFO, self::ERROR])) {
109 109
             return;
110 110
         }
111 111
 
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
         $datetime = $datetime->format(DATE_ATOM);
122 122
 
123 123
         $content = sprintf('%s -- %s -- %s -- %s', $level, $_SERVER['REMOTE_ADDR'], $datetime, $message);
124
-        $content .= ($context ? "\n" . print_r($context, true) : '');
124
+        $content .= ($context ? "\n".print_r($context, true) : '');
125 125
         $content .= "\n";
126 126
 
127 127
         file_put_contents($this->file, $content, FILE_APPEND);
Please login to merge, or discard this patch.
src/Adapter/AbstractAdapter.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
      */
301 301
     protected function setCallback($callback)
302 302
     {
303
-        if (!filter_var($callback, FILTER_VALIDATE_URL)) {
303
+        if ( ! filter_var($callback, FILTER_VALIDATE_URL)) {
304 304
             throw new InvalidArgumentException('A valid callback url is required.');
305 305
         }
306 306
 
@@ -339,16 +339,16 @@  discard block
 block discarded – undo
339 339
      */
340 340
     protected function validateApiResponse($error = '')
341 341
     {
342
-        $error .= !empty($error) ? '. ' : '';
342
+        $error .= ! empty($error) ? '. ' : '';
343 343
 
344 344
         if ($this->httpClient->getResponseClientError()) {
345 345
             throw new HttpClientFailureException(
346
-                $error . 'HTTP client error: ' . $this->httpClient->getResponseClientError() . '.'
346
+                $error.'HTTP client error: '.$this->httpClient->getResponseClientError().'.'
347 347
             );
348 348
         }
349 349
 
350 350
         // if validateApiResponseHttpCode is set to false, we by pass verification of http status code
351
-        if (!$this->validateApiResponseHttpCode) {
351
+        if ( ! $this->validateApiResponseHttpCode) {
352 352
             return;
353 353
         }
354 354
 
@@ -356,8 +356,8 @@  discard block
 block discarded – undo
356 356
 
357 357
         if ($status < 200 || $status > 299) {
358 358
             throw new HttpRequestFailedException(
359
-                $error . 'HTTP error ' . $this->httpClient->getResponseHttpCode() .
360
-                '. Raw Provider API response: ' . $this->httpClient->getResponseBody() . '.'
359
+                $error.'HTTP error '.$this->httpClient->getResponseHttpCode().
360
+                '. Raw Provider API response: '.$this->httpClient->getResponseBody().'.'
361 361
             );
362 362
         }
363 363
     }
Please login to merge, or discard this patch.
Indentation   +345 added lines, -345 removed lines patch added patch discarded remove patch
@@ -24,349 +24,349 @@
 block discarded – undo
24 24
  */
25 25
 abstract class AbstractAdapter implements AdapterInterface
26 26
 {
27
-    use DataStoreTrait;
28
-
29
-    /**
30
-     * Provider ID (unique name).
31
-     *
32
-     * @var string
33
-     */
34
-    protected $providerId = '';
35
-
36
-    /**
37
-     * Specific Provider config.
38
-     *
39
-     * @var mixed
40
-     */
41
-    protected $config = [];
42
-
43
-    /**
44
-     * Extra Provider parameters.
45
-     *
46
-     * @var array
47
-     */
48
-    protected $params;
49
-
50
-    /**
51
-     * Callback url
52
-     *
53
-     * @var string
54
-     */
55
-    protected $callback = '';
56
-
57
-    /**
58
-     * Storage.
59
-     *
60
-     * @var StorageInterface
61
-     */
62
-    public $storage;
63
-
64
-    /**
65
-     * HttpClient.
66
-     *
67
-     * @var HttpClientInterface
68
-     */
69
-    public $httpClient;
70
-
71
-    /**
72
-     * Logger.
73
-     *
74
-     * @var LoggerInterface
75
-     */
76
-    public $logger;
77
-
78
-    /**
79
-     * Whether to validate API status codes of http responses
80
-     *
81
-     * @var bool
82
-     */
83
-    protected $validateApiResponseHttpCode = true;
84
-
85
-    /**
86
-     * Common adapters constructor.
87
-     *
88
-     * @param array $config
89
-     * @param HttpClientInterface $httpClient
90
-     * @param StorageInterface $storage
91
-     * @param LoggerInterface $logger
92
-     */
93
-    public function __construct(
94
-        $config = [],
95
-        HttpClientInterface $httpClient = null,
96
-        StorageInterface $storage = null,
97
-        LoggerInterface $logger = null
98
-    ) {
99
-        $this->providerId = (new \ReflectionClass($this))->getShortName();
100
-
101
-        $this->config = new Data\Collection($config);
102
-
103
-        $this->setHttpClient($httpClient);
104
-
105
-        $this->setStorage($storage);
106
-
107
-        $this->setLogger($logger);
108
-
109
-        $this->configure();
110
-
111
-        $this->logger->debug(sprintf('Initialize %s, config: ', get_class($this)), $config);
112
-
113
-        $this->initialize();
114
-    }
115
-
116
-    /**
117
-     * Load adapter's configuration
118
-     */
119
-    abstract protected function configure();
120
-
121
-    /**
122
-     * Adapter initializer
123
-     */
124
-    abstract protected function initialize();
125
-
126
-    /**
127
-     * {@inheritdoc}
128
-     */
129
-    abstract public function isConnected();
130
-
131
-    /**
132
-     * {@inheritdoc}
133
-     */
134
-    public function apiRequest($url, $method = 'GET', $parameters = [], $headers = [], $multipart = false)
135
-    {
136
-        throw new NotImplementedException('Provider does not support this feature.');
137
-    }
138
-
139
-    /**
140
-     * {@inheritdoc}
141
-     */
142
-    public function maintainToken()
143
-    {
144
-        // Nothing needed for most providers
145
-    }
146
-
147
-    /**
148
-     * {@inheritdoc}
149
-     */
150
-    public function getUserProfile()
151
-    {
152
-        throw new NotImplementedException('Provider does not support this feature.');
153
-    }
154
-
155
-    /**
156
-     * {@inheritdoc}
157
-     */
158
-    public function getUserContacts()
159
-    {
160
-        throw new NotImplementedException('Provider does not support this feature.');
161
-    }
162
-
163
-    /**
164
-     * {@inheritdoc}
165
-     */
166
-    public function getUserPages()
167
-    {
168
-        throw new NotImplementedException('Provider does not support this feature.');
169
-    }
170
-
171
-    /**
172
-     * {@inheritdoc}
173
-     */
174
-    public function getUserActivity($stream)
175
-    {
176
-        throw new NotImplementedException('Provider does not support this feature.');
177
-    }
178
-
179
-    /**
180
-     * {@inheritdoc}
181
-     */
182
-    public function setUserStatus($status)
183
-    {
184
-        throw new NotImplementedException('Provider does not support this feature.');
185
-    }
186
-
187
-    /**
188
-     * {@inheritdoc}
189
-     */
190
-    public function setPageStatus($status, $pageId)
191
-    {
192
-        throw new NotImplementedException('Provider does not support this feature.');
193
-    }
194
-
195
-    /**
196
-     * {@inheritdoc}
197
-     */
198
-    public function disconnect()
199
-    {
200
-        $this->clearStoredData();
201
-    }
202
-
203
-    /**
204
-     * {@inheritdoc}
205
-     */
206
-    public function getAccessToken()
207
-    {
208
-        $tokenNames = [
209
-            'access_token',
210
-            'access_token_secret',
211
-            'token_type',
212
-            'refresh_token',
213
-            'expires_in',
214
-            'expires_at',
215
-        ];
216
-
217
-        $tokens = [];
218
-
219
-        foreach ($tokenNames as $name) {
220
-            if ($this->getStoredData($name)) {
221
-                $tokens[$name] = $this->getStoredData($name);
222
-            }
223
-        }
224
-
225
-        return $tokens;
226
-    }
227
-
228
-    /**
229
-     * {@inheritdoc}
230
-     */
231
-    public function setAccessToken($tokens = [])
232
-    {
233
-        $this->clearStoredData();
234
-
235
-        foreach ($tokens as $token => $value) {
236
-            $this->storeData($token, $value);
237
-        }
238
-
239
-        // Re-initialize token parameters.
240
-        $this->initialize();
241
-    }
242
-
243
-    /**
244
-     * {@inheritdoc}
245
-     */
246
-    public function setHttpClient(HttpClientInterface $httpClient = null)
247
-    {
248
-        $this->httpClient = $httpClient ?: new HttpClient();
249
-
250
-        if ($this->config->exists('curl_options') && method_exists($this->httpClient, 'setCurlOptions')) {
251
-            $this->httpClient->setCurlOptions($this->config->get('curl_options'));
252
-        }
253
-    }
254
-
255
-    /**
256
-     * {@inheritdoc}
257
-     */
258
-    public function getHttpClient()
259
-    {
260
-        return $this->httpClient;
261
-    }
262
-
263
-    /**
264
-     * {@inheritdoc}
265
-     */
266
-    public function setStorage(StorageInterface $storage = null)
267
-    {
268
-        $this->storage = $storage ?: new Session();
269
-    }
270
-
271
-    /**
272
-     * {@inheritdoc}
273
-     */
274
-    public function getStorage()
275
-    {
276
-        return $this->storage;
277
-    }
278
-
279
-    /**
280
-     * {@inheritdoc}
281
-     */
282
-    public function setLogger(LoggerInterface $logger = null)
283
-    {
284
-        $this->logger = $logger ?: new Logger(
285
-            $this->config->get('debug_mode'),
286
-            $this->config->get('debug_file')
287
-        );
288
-
289
-        if (method_exists($this->httpClient, 'setLogger')) {
290
-            $this->httpClient->setLogger($this->logger);
291
-        }
292
-    }
293
-
294
-    /**
295
-     * {@inheritdoc}
296
-     */
297
-    public function getLogger()
298
-    {
299
-        return $this->logger;
300
-    }
301
-
302
-    /**
303
-     * Set Adapter's API callback url
304
-     *
305
-     * @param string $callback
306
-     *
307
-     * @throws InvalidArgumentException
308
-     */
309
-    protected function setCallback($callback)
310
-    {
311
-        if (!filter_var($callback, FILTER_VALIDATE_URL)) {
312
-            throw new InvalidArgumentException('A valid callback url is required.');
313
-        }
314
-
315
-        $this->callback = $callback;
316
-    }
317
-
318
-    /**
319
-     * Overwrite Adapter's API endpoints
320
-     *
321
-     * @param array|Data\Collection $endpoints
322
-     */
323
-    protected function setApiEndpoints($endpoints = null)
324
-    {
325
-        if (empty($endpoints)) {
326
-            return;
327
-        }
328
-
329
-        $collection = is_array($endpoints) ? new Data\Collection($endpoints) : $endpoints;
330
-
331
-        $this->apiBaseUrl = $collection->get('api_base_url') ?: $this->apiBaseUrl;
332
-        $this->authorizeUrl = $collection->get('authorize_url') ?: $this->authorizeUrl;
333
-        $this->accessTokenUrl = $collection->get('access_token_url') ?: $this->accessTokenUrl;
334
-    }
335
-
336
-
337
-    /**
338
-     * Validate signed API responses Http status code.
339
-     *
340
-     * Since the specifics of error responses is beyond the scope of RFC6749 and OAuth Core specifications,
341
-     * Hybridauth will consider any HTTP status code that is different than '200 OK' as an ERROR.
342
-     *
343
-     * @param string $error String to pre append to message thrown in exception
344
-     *
345
-     * @throws HttpClientFailureException
346
-     * @throws HttpRequestFailedException
347
-     */
348
-    protected function validateApiResponse($error = '')
349
-    {
350
-        $error .= !empty($error) ? '. ' : '';
351
-
352
-        if ($this->httpClient->getResponseClientError()) {
353
-            throw new HttpClientFailureException(
354
-                $error . 'HTTP client error: ' . $this->httpClient->getResponseClientError() . '.'
355
-            );
356
-        }
357
-
358
-        // if validateApiResponseHttpCode is set to false, we by pass verification of http status code
359
-        if (!$this->validateApiResponseHttpCode) {
360
-            return;
361
-        }
362
-
363
-        $status = $this->httpClient->getResponseHttpCode();
364
-
365
-        if ($status < 200 || $status > 299) {
366
-            throw new HttpRequestFailedException(
367
-                $error . 'HTTP error ' . $this->httpClient->getResponseHttpCode() .
368
-                '. Raw Provider API response: ' . $this->httpClient->getResponseBody() . '.'
369
-            );
370
-        }
371
-    }
27
+	use DataStoreTrait;
28
+
29
+	/**
30
+	 * Provider ID (unique name).
31
+	 *
32
+	 * @var string
33
+	 */
34
+	protected $providerId = '';
35
+
36
+	/**
37
+	 * Specific Provider config.
38
+	 *
39
+	 * @var mixed
40
+	 */
41
+	protected $config = [];
42
+
43
+	/**
44
+	 * Extra Provider parameters.
45
+	 *
46
+	 * @var array
47
+	 */
48
+	protected $params;
49
+
50
+	/**
51
+	 * Callback url
52
+	 *
53
+	 * @var string
54
+	 */
55
+	protected $callback = '';
56
+
57
+	/**
58
+	 * Storage.
59
+	 *
60
+	 * @var StorageInterface
61
+	 */
62
+	public $storage;
63
+
64
+	/**
65
+	 * HttpClient.
66
+	 *
67
+	 * @var HttpClientInterface
68
+	 */
69
+	public $httpClient;
70
+
71
+	/**
72
+	 * Logger.
73
+	 *
74
+	 * @var LoggerInterface
75
+	 */
76
+	public $logger;
77
+
78
+	/**
79
+	 * Whether to validate API status codes of http responses
80
+	 *
81
+	 * @var bool
82
+	 */
83
+	protected $validateApiResponseHttpCode = true;
84
+
85
+	/**
86
+	 * Common adapters constructor.
87
+	 *
88
+	 * @param array $config
89
+	 * @param HttpClientInterface $httpClient
90
+	 * @param StorageInterface $storage
91
+	 * @param LoggerInterface $logger
92
+	 */
93
+	public function __construct(
94
+		$config = [],
95
+		HttpClientInterface $httpClient = null,
96
+		StorageInterface $storage = null,
97
+		LoggerInterface $logger = null
98
+	) {
99
+		$this->providerId = (new \ReflectionClass($this))->getShortName();
100
+
101
+		$this->config = new Data\Collection($config);
102
+
103
+		$this->setHttpClient($httpClient);
104
+
105
+		$this->setStorage($storage);
106
+
107
+		$this->setLogger($logger);
108
+
109
+		$this->configure();
110
+
111
+		$this->logger->debug(sprintf('Initialize %s, config: ', get_class($this)), $config);
112
+
113
+		$this->initialize();
114
+	}
115
+
116
+	/**
117
+	 * Load adapter's configuration
118
+	 */
119
+	abstract protected function configure();
120
+
121
+	/**
122
+	 * Adapter initializer
123
+	 */
124
+	abstract protected function initialize();
125
+
126
+	/**
127
+	 * {@inheritdoc}
128
+	 */
129
+	abstract public function isConnected();
130
+
131
+	/**
132
+	 * {@inheritdoc}
133
+	 */
134
+	public function apiRequest($url, $method = 'GET', $parameters = [], $headers = [], $multipart = false)
135
+	{
136
+		throw new NotImplementedException('Provider does not support this feature.');
137
+	}
138
+
139
+	/**
140
+	 * {@inheritdoc}
141
+	 */
142
+	public function maintainToken()
143
+	{
144
+		// Nothing needed for most providers
145
+	}
146
+
147
+	/**
148
+	 * {@inheritdoc}
149
+	 */
150
+	public function getUserProfile()
151
+	{
152
+		throw new NotImplementedException('Provider does not support this feature.');
153
+	}
154
+
155
+	/**
156
+	 * {@inheritdoc}
157
+	 */
158
+	public function getUserContacts()
159
+	{
160
+		throw new NotImplementedException('Provider does not support this feature.');
161
+	}
162
+
163
+	/**
164
+	 * {@inheritdoc}
165
+	 */
166
+	public function getUserPages()
167
+	{
168
+		throw new NotImplementedException('Provider does not support this feature.');
169
+	}
170
+
171
+	/**
172
+	 * {@inheritdoc}
173
+	 */
174
+	public function getUserActivity($stream)
175
+	{
176
+		throw new NotImplementedException('Provider does not support this feature.');
177
+	}
178
+
179
+	/**
180
+	 * {@inheritdoc}
181
+	 */
182
+	public function setUserStatus($status)
183
+	{
184
+		throw new NotImplementedException('Provider does not support this feature.');
185
+	}
186
+
187
+	/**
188
+	 * {@inheritdoc}
189
+	 */
190
+	public function setPageStatus($status, $pageId)
191
+	{
192
+		throw new NotImplementedException('Provider does not support this feature.');
193
+	}
194
+
195
+	/**
196
+	 * {@inheritdoc}
197
+	 */
198
+	public function disconnect()
199
+	{
200
+		$this->clearStoredData();
201
+	}
202
+
203
+	/**
204
+	 * {@inheritdoc}
205
+	 */
206
+	public function getAccessToken()
207
+	{
208
+		$tokenNames = [
209
+			'access_token',
210
+			'access_token_secret',
211
+			'token_type',
212
+			'refresh_token',
213
+			'expires_in',
214
+			'expires_at',
215
+		];
216
+
217
+		$tokens = [];
218
+
219
+		foreach ($tokenNames as $name) {
220
+			if ($this->getStoredData($name)) {
221
+				$tokens[$name] = $this->getStoredData($name);
222
+			}
223
+		}
224
+
225
+		return $tokens;
226
+	}
227
+
228
+	/**
229
+	 * {@inheritdoc}
230
+	 */
231
+	public function setAccessToken($tokens = [])
232
+	{
233
+		$this->clearStoredData();
234
+
235
+		foreach ($tokens as $token => $value) {
236
+			$this->storeData($token, $value);
237
+		}
238
+
239
+		// Re-initialize token parameters.
240
+		$this->initialize();
241
+	}
242
+
243
+	/**
244
+	 * {@inheritdoc}
245
+	 */
246
+	public function setHttpClient(HttpClientInterface $httpClient = null)
247
+	{
248
+		$this->httpClient = $httpClient ?: new HttpClient();
249
+
250
+		if ($this->config->exists('curl_options') && method_exists($this->httpClient, 'setCurlOptions')) {
251
+			$this->httpClient->setCurlOptions($this->config->get('curl_options'));
252
+		}
253
+	}
254
+
255
+	/**
256
+	 * {@inheritdoc}
257
+	 */
258
+	public function getHttpClient()
259
+	{
260
+		return $this->httpClient;
261
+	}
262
+
263
+	/**
264
+	 * {@inheritdoc}
265
+	 */
266
+	public function setStorage(StorageInterface $storage = null)
267
+	{
268
+		$this->storage = $storage ?: new Session();
269
+	}
270
+
271
+	/**
272
+	 * {@inheritdoc}
273
+	 */
274
+	public function getStorage()
275
+	{
276
+		return $this->storage;
277
+	}
278
+
279
+	/**
280
+	 * {@inheritdoc}
281
+	 */
282
+	public function setLogger(LoggerInterface $logger = null)
283
+	{
284
+		$this->logger = $logger ?: new Logger(
285
+			$this->config->get('debug_mode'),
286
+			$this->config->get('debug_file')
287
+		);
288
+
289
+		if (method_exists($this->httpClient, 'setLogger')) {
290
+			$this->httpClient->setLogger($this->logger);
291
+		}
292
+	}
293
+
294
+	/**
295
+	 * {@inheritdoc}
296
+	 */
297
+	public function getLogger()
298
+	{
299
+		return $this->logger;
300
+	}
301
+
302
+	/**
303
+	 * Set Adapter's API callback url
304
+	 *
305
+	 * @param string $callback
306
+	 *
307
+	 * @throws InvalidArgumentException
308
+	 */
309
+	protected function setCallback($callback)
310
+	{
311
+		if (!filter_var($callback, FILTER_VALIDATE_URL)) {
312
+			throw new InvalidArgumentException('A valid callback url is required.');
313
+		}
314
+
315
+		$this->callback = $callback;
316
+	}
317
+
318
+	/**
319
+	 * Overwrite Adapter's API endpoints
320
+	 *
321
+	 * @param array|Data\Collection $endpoints
322
+	 */
323
+	protected function setApiEndpoints($endpoints = null)
324
+	{
325
+		if (empty($endpoints)) {
326
+			return;
327
+		}
328
+
329
+		$collection = is_array($endpoints) ? new Data\Collection($endpoints) : $endpoints;
330
+
331
+		$this->apiBaseUrl = $collection->get('api_base_url') ?: $this->apiBaseUrl;
332
+		$this->authorizeUrl = $collection->get('authorize_url') ?: $this->authorizeUrl;
333
+		$this->accessTokenUrl = $collection->get('access_token_url') ?: $this->accessTokenUrl;
334
+	}
335
+
336
+
337
+	/**
338
+	 * Validate signed API responses Http status code.
339
+	 *
340
+	 * Since the specifics of error responses is beyond the scope of RFC6749 and OAuth Core specifications,
341
+	 * Hybridauth will consider any HTTP status code that is different than '200 OK' as an ERROR.
342
+	 *
343
+	 * @param string $error String to pre append to message thrown in exception
344
+	 *
345
+	 * @throws HttpClientFailureException
346
+	 * @throws HttpRequestFailedException
347
+	 */
348
+	protected function validateApiResponse($error = '')
349
+	{
350
+		$error .= !empty($error) ? '. ' : '';
351
+
352
+		if ($this->httpClient->getResponseClientError()) {
353
+			throw new HttpClientFailureException(
354
+				$error . 'HTTP client error: ' . $this->httpClient->getResponseClientError() . '.'
355
+			);
356
+		}
357
+
358
+		// if validateApiResponseHttpCode is set to false, we by pass verification of http status code
359
+		if (!$this->validateApiResponseHttpCode) {
360
+			return;
361
+		}
362
+
363
+		$status = $this->httpClient->getResponseHttpCode();
364
+
365
+		if ($status < 200 || $status > 299) {
366
+			throw new HttpRequestFailedException(
367
+				$error . 'HTTP error ' . $this->httpClient->getResponseHttpCode() .
368
+				'. Raw Provider API response: ' . $this->httpClient->getResponseBody() . '.'
369
+			);
370
+		}
371
+	}
372 372
 }
Please login to merge, or discard this patch.
src/Adapter/DataStoreTrait.php 2 patches
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -12,63 +12,63 @@
 block discarded – undo
12 12
  */
13 13
 trait DataStoreTrait
14 14
 {
15
-    /**
16
-     * Returns storage instance
17
-     *
18
-     * @return \Hybridauth\Storage\StorageInterface
19
-     */
20
-    abstract public function getStorage();
15
+	/**
16
+	 * Returns storage instance
17
+	 *
18
+	 * @return \Hybridauth\Storage\StorageInterface
19
+	 */
20
+	abstract public function getStorage();
21 21
 
22
-    /**
23
-     * Store a piece of data in storage.
24
-     *
25
-     * This method is mainly used for OAuth tokens (access, secret, refresh, and whatnot), but it
26
-     * can be also used by providers to store any other useful data (i.g., user_id, auth_nonce, etc.)
27
-     *
28
-     * @param string $name
29
-     * @param mixed $value
30
-     */
31
-    protected function storeData($name, $value = null)
32
-    {
33
-        // if empty, we simply delete the thing as we'd want to only store necessary data
34
-        if (empty($value)) {
35
-            $this->deleteStoredData($name);
36
-        }
22
+	/**
23
+	 * Store a piece of data in storage.
24
+	 *
25
+	 * This method is mainly used for OAuth tokens (access, secret, refresh, and whatnot), but it
26
+	 * can be also used by providers to store any other useful data (i.g., user_id, auth_nonce, etc.)
27
+	 *
28
+	 * @param string $name
29
+	 * @param mixed $value
30
+	 */
31
+	protected function storeData($name, $value = null)
32
+	{
33
+		// if empty, we simply delete the thing as we'd want to only store necessary data
34
+		if (empty($value)) {
35
+			$this->deleteStoredData($name);
36
+		}
37 37
 
38
-        $this->getStorage()->set($this->providerId . '.' . $name, $value);
39
-    }
38
+		$this->getStorage()->set($this->providerId . '.' . $name, $value);
39
+	}
40 40
 
41
-    /**
42
-     * Retrieve a piece of data from storage.
43
-     *
44
-     * This method is mainly used for OAuth tokens (access, secret, refresh, and whatnot), but it
45
-     * can be also used by providers to retrieve from store any other useful data (i.g., user_id,
46
-     * auth_nonce, etc.)
47
-     *
48
-     * @param string $name
49
-     *
50
-     * @return mixed
51
-     */
52
-    protected function getStoredData($name)
53
-    {
54
-        return $this->getStorage()->get($this->providerId . '.' . $name);
55
-    }
41
+	/**
42
+	 * Retrieve a piece of data from storage.
43
+	 *
44
+	 * This method is mainly used for OAuth tokens (access, secret, refresh, and whatnot), but it
45
+	 * can be also used by providers to retrieve from store any other useful data (i.g., user_id,
46
+	 * auth_nonce, etc.)
47
+	 *
48
+	 * @param string $name
49
+	 *
50
+	 * @return mixed
51
+	 */
52
+	protected function getStoredData($name)
53
+	{
54
+		return $this->getStorage()->get($this->providerId . '.' . $name);
55
+	}
56 56
 
57
-    /**
58
-     * Delete a stored piece of data.
59
-     *
60
-     * @param string $name
61
-     */
62
-    protected function deleteStoredData($name)
63
-    {
64
-        $this->getStorage()->delete($this->providerId . '.' . $name);
65
-    }
57
+	/**
58
+	 * Delete a stored piece of data.
59
+	 *
60
+	 * @param string $name
61
+	 */
62
+	protected function deleteStoredData($name)
63
+	{
64
+		$this->getStorage()->delete($this->providerId . '.' . $name);
65
+	}
66 66
 
67
-    /**
68
-     * Delete all stored data of the instantiated adapter
69
-     */
70
-    protected function clearStoredData()
71
-    {
72
-        $this->getStorage()->deleteMatch($this->providerId . '.');
73
-    }
67
+	/**
68
+	 * Delete all stored data of the instantiated adapter
69
+	 */
70
+	protected function clearStoredData()
71
+	{
72
+		$this->getStorage()->deleteMatch($this->providerId . '.');
73
+	}
74 74
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
             $this->deleteStoredData($name);
36 36
         }
37 37
 
38
-        $this->getStorage()->set($this->providerId . '.' . $name, $value);
38
+        $this->getStorage()->set($this->providerId.'.'.$name, $value);
39 39
     }
40 40
 
41 41
     /**
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
      */
52 52
     protected function getStoredData($name)
53 53
     {
54
-        return $this->getStorage()->get($this->providerId . '.' . $name);
54
+        return $this->getStorage()->get($this->providerId.'.'.$name);
55 55
     }
56 56
 
57 57
     /**
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
      */
62 62
     protected function deleteStoredData($name)
63 63
     {
64
-        $this->getStorage()->delete($this->providerId . '.' . $name);
64
+        $this->getStorage()->delete($this->providerId.'.'.$name);
65 65
     }
66 66
 
67 67
     /**
@@ -69,6 +69,6 @@  discard block
 block discarded – undo
69 69
      */
70 70
     protected function clearStoredData()
71 71
     {
72
-        $this->getStorage()->deleteMatch($this->providerId . '.');
72
+        $this->getStorage()->deleteMatch($this->providerId.'.');
73 73
     }
74 74
 }
Please login to merge, or discard this patch.
src/Data/Parser.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -29,10 +29,10 @@  discard block
 block discarded – undo
29 29
     {
30 30
         $data = $this->parseJson($raw);
31 31
 
32
-        if (!$data) {
32
+        if ( ! $data) {
33 33
             $data = $this->parseXml($raw);
34 34
 
35
-            if (!$data) {
35
+            if ( ! $data) {
36 36
                 $data = $this->parseQueryString($raw);
37 37
             }
38 38
         }
@@ -68,11 +68,11 @@  discard block
 block discarded – undo
68 68
 
69 69
         libxml_use_internal_errors(false);
70 70
 
71
-        if (!$xml) {
71
+        if ( ! $xml) {
72 72
             return [];
73 73
         }
74 74
 
75
-        $arr = json_decode(json_encode((array)$xml), true);
75
+        $arr = json_decode(json_encode((array) $xml), true);
76 76
         $arr = array($xml->getName() => $arr);
77 77
 
78 78
         return $arr;
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
     {
90 90
         parse_str($result, $output);
91 91
 
92
-        if (!is_array($output)) {
92
+        if ( ! is_array($output)) {
93 93
             return $result;
94 94
         }
95 95
 
Please login to merge, or discard this patch.
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -15,104 +15,104 @@
 block discarded – undo
15 15
  */
16 16
 final class Parser
17 17
 {
18
-    /**
19
-     * Decodes a string into an object.
20
-     *
21
-     * This method will first attempt to parse data as a JSON string (since most providers use this format)
22
-     * then XML and parse_str.
23
-     *
24
-     * @param string $raw
25
-     *
26
-     * @return mixed
27
-     */
28
-    public function parse($raw = null)
29
-    {
30
-        $data = $this->parseJson($raw);
31
-
32
-        if (!$data) {
33
-            $data = $this->parseXml($raw);
34
-
35
-            if (!$data) {
36
-                $data = $this->parseQueryString($raw);
37
-            }
38
-        }
39
-
40
-        return $data;
41
-    }
42
-
43
-    /**
44
-     * Decodes a JSON string
45
-     *
46
-     * @param $result
47
-     *
48
-     * @return mixed
49
-     */
50
-    public function parseJson($result)
51
-    {
52
-        return json_decode($result);
53
-    }
54
-
55
-    /**
56
-     * Decodes a XML string
57
-     *
58
-     * @param $result
59
-     *
60
-     * @return mixed
61
-     */
62
-    public function parseXml($result)
63
-    {
64
-        libxml_use_internal_errors(true);
65
-
66
-        $result = preg_replace('/([<\/])([a-z0-9-]+):/i', '$1', $result);
67
-        $xml = simplexml_load_string($result);
68
-
69
-        libxml_use_internal_errors(false);
70
-
71
-        if (!$xml) {
72
-            return [];
73
-        }
74
-
75
-        $arr = json_decode(json_encode((array)$xml), true);
76
-        $arr = array($xml->getName() => $arr);
77
-
78
-        return $arr;
79
-    }
80
-
81
-    /**
82
-     * Parses a string into variables
83
-     *
84
-     * @param $result
85
-     *
86
-     * @return \StdClass
87
-     */
88
-    public function parseQueryString($result)
89
-    {
90
-        parse_str($result, $output);
91
-
92
-        if (!is_array($output)) {
93
-            return $result;
94
-        }
95
-
96
-        $result = new \StdClass();
97
-
98
-        foreach ($output as $k => $v) {
99
-            $result->$k = $v;
100
-        }
101
-
102
-        return $result;
103
-    }
104
-
105
-    /**
106
-     * needs to be improved
107
-     *
108
-     * @param $birthday
109
-     *
110
-     * @return array
111
-     */
112
-    public function parseBirthday($birthday)
113
-    {
114
-        $birthday = date_parse((string) $birthday);
115
-
116
-        return [$birthday['year'], $birthday['month'], $birthday['day']];
117
-    }
18
+	/**
19
+	 * Decodes a string into an object.
20
+	 *
21
+	 * This method will first attempt to parse data as a JSON string (since most providers use this format)
22
+	 * then XML and parse_str.
23
+	 *
24
+	 * @param string $raw
25
+	 *
26
+	 * @return mixed
27
+	 */
28
+	public function parse($raw = null)
29
+	{
30
+		$data = $this->parseJson($raw);
31
+
32
+		if (!$data) {
33
+			$data = $this->parseXml($raw);
34
+
35
+			if (!$data) {
36
+				$data = $this->parseQueryString($raw);
37
+			}
38
+		}
39
+
40
+		return $data;
41
+	}
42
+
43
+	/**
44
+	 * Decodes a JSON string
45
+	 *
46
+	 * @param $result
47
+	 *
48
+	 * @return mixed
49
+	 */
50
+	public function parseJson($result)
51
+	{
52
+		return json_decode($result);
53
+	}
54
+
55
+	/**
56
+	 * Decodes a XML string
57
+	 *
58
+	 * @param $result
59
+	 *
60
+	 * @return mixed
61
+	 */
62
+	public function parseXml($result)
63
+	{
64
+		libxml_use_internal_errors(true);
65
+
66
+		$result = preg_replace('/([<\/])([a-z0-9-]+):/i', '$1', $result);
67
+		$xml = simplexml_load_string($result);
68
+
69
+		libxml_use_internal_errors(false);
70
+
71
+		if (!$xml) {
72
+			return [];
73
+		}
74
+
75
+		$arr = json_decode(json_encode((array)$xml), true);
76
+		$arr = array($xml->getName() => $arr);
77
+
78
+		return $arr;
79
+	}
80
+
81
+	/**
82
+	 * Parses a string into variables
83
+	 *
84
+	 * @param $result
85
+	 *
86
+	 * @return \StdClass
87
+	 */
88
+	public function parseQueryString($result)
89
+	{
90
+		parse_str($result, $output);
91
+
92
+		if (!is_array($output)) {
93
+			return $result;
94
+		}
95
+
96
+		$result = new \StdClass();
97
+
98
+		foreach ($output as $k => $v) {
99
+			$result->$k = $v;
100
+		}
101
+
102
+		return $result;
103
+	}
104
+
105
+	/**
106
+	 * needs to be improved
107
+	 *
108
+	 * @param $birthday
109
+	 *
110
+	 * @return array
111
+	 */
112
+	public function parseBirthday($birthday)
113
+	{
114
+		$birthday = date_parse((string) $birthday);
115
+
116
+		return [$birthday['year'], $birthday['month'], $birthday['day']];
117
+	}
118 118
 }
Please login to merge, or discard this patch.