Passed
Push — master ( 9b803d...bcd4f7 )
by Goffy
03:19
created
class/Github/OAuth/Token.php 1 patch
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -12,97 +12,97 @@
 block discarded – undo
12 12
  */
13 13
 class Token extends Github\Sanity
14 14
 {
15
-	/** @var string */
16
-	private $value;
17
-
18
-	/** @var string */
19
-	private $type;
20
-
21
-	/** @var string[] */
22
-	private $scopes;
23
-
24
-
25
-	/**
26
-	 * @param  string
27
-	 * @param  string
28
-	 * @param  string[]
29
-	 */
30
-	public function __construct($value, $type = '', array $scopes = [])
31
-	{
32
-		$this->value = $value;
33
-		$this->type = $type;
34
-		$this->scopes = $scopes;
35
-	}
36
-
37
-
38
-	/**
39
-	 * @return string
40
-	 */
41
-	public function getValue()
42
-	{
43
-		return $this->value;
44
-	}
45
-
46
-
47
-	/**
48
-	 * @return string
49
-	 */
50
-	public function getType()
51
-	{
52
-		return $this->type;
53
-	}
54
-
55
-
56
-	/**
57
-	 * @return string[]
58
-	 */
59
-	public function getScopes()
60
-	{
61
-		return $this->scopes;
62
-	}
63
-
64
-
65
-	/**
66
-	 * @see https://developer.github.com/v3/oauth/#scopes
67
-	 *
68
-	 * @param  string
69
-	 * @return bool
70
-	 */
71
-	public function hasScope($scope)
72
-	{
73
-		if (in_array($scope, $this->scopes, TRUE)) {
74
-			return TRUE;
75
-		}
76
-
77
-		static $superiors = [
78
-			'user:email' => 'user',
79
-			'user:follow' => 'user',
80
-			'notifications' => 'repo',
81
-		];
82
-
83
-		if (array_key_exists($scope, $superiors) && in_array($superiors[$scope], $this->scopes, TRUE)) {
84
-			return TRUE;
85
-		}
86
-
87
-		return FALSE;
88
-	}
89
-
90
-
91
-	/** @internal */
92
-	public function toArray()
93
-	{
94
-		return [
95
-			'value' => $this->value,
96
-			'type' => $this->type,
97
-			'scopes' => $this->scopes,
98
-		];
99
-	}
100
-
101
-
102
-	/** @internal */
103
-	public static function createFromArray(array $data)
104
-	{
105
-		return new static($data['value'], $data['type'], $data['scopes']);
106
-	}
15
+    /** @var string */
16
+    private $value;
17
+
18
+    /** @var string */
19
+    private $type;
20
+
21
+    /** @var string[] */
22
+    private $scopes;
23
+
24
+
25
+    /**
26
+     * @param  string
27
+     * @param  string
28
+     * @param  string[]
29
+     */
30
+    public function __construct($value, $type = '', array $scopes = [])
31
+    {
32
+        $this->value = $value;
33
+        $this->type = $type;
34
+        $this->scopes = $scopes;
35
+    }
36
+
37
+
38
+    /**
39
+     * @return string
40
+     */
41
+    public function getValue()
42
+    {
43
+        return $this->value;
44
+    }
45
+
46
+
47
+    /**
48
+     * @return string
49
+     */
50
+    public function getType()
51
+    {
52
+        return $this->type;
53
+    }
54
+
55
+
56
+    /**
57
+     * @return string[]
58
+     */
59
+    public function getScopes()
60
+    {
61
+        return $this->scopes;
62
+    }
63
+
64
+
65
+    /**
66
+     * @see https://developer.github.com/v3/oauth/#scopes
67
+     *
68
+     * @param  string
69
+     * @return bool
70
+     */
71
+    public function hasScope($scope)
72
+    {
73
+        if (in_array($scope, $this->scopes, TRUE)) {
74
+            return TRUE;
75
+        }
76
+
77
+        static $superiors = [
78
+            'user:email' => 'user',
79
+            'user:follow' => 'user',
80
+            'notifications' => 'repo',
81
+        ];
82
+
83
+        if (array_key_exists($scope, $superiors) && in_array($superiors[$scope], $this->scopes, TRUE)) {
84
+            return TRUE;
85
+        }
86
+
87
+        return FALSE;
88
+    }
89
+
90
+
91
+    /** @internal */
92
+    public function toArray()
93
+    {
94
+        return [
95
+            'value' => $this->value,
96
+            'type' => $this->type,
97
+            'scopes' => $this->scopes,
98
+        ];
99
+    }
100
+
101
+
102
+    /** @internal */
103
+    public static function createFromArray(array $data)
104
+    {
105
+        return new static($data['value'], $data['type'], $data['scopes']);
106
+    }
107 107
 
108 108
 }
Please login to merge, or discard this patch.
class/Github/OAuth/Configuration.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -12,35 +12,35 @@
 block discarded – undo
12 12
  */
13 13
 class Configuration extends Github\Sanity
14 14
 {
15
-	/** @var string */
16
-	public $clientId;
17
-
18
-	/** @var string */
19
-	public $clientSecret;
20
-
21
-	/** @var string[] */
22
-	public $scopes;
23
-
24
-
25
-	/**
26
-	 * @param  string
27
-	 * @param  string
28
-	 * @param  string[]
29
-	 */
30
-	public function __construct($clientId, $clientSecret, array $scopes = [])
31
-	{
32
-		$this->clientId = $clientId;
33
-		$this->clientSecret = $clientSecret;
34
-		$this->scopes = $scopes;
15
+    /** @var string */
16
+    public $clientId;
17
+
18
+    /** @var string */
19
+    public $clientSecret;
20
+
21
+    /** @var string[] */
22
+    public $scopes;
23
+
24
+
25
+    /**
26
+     * @param  string
27
+     * @param  string
28
+     * @param  string[]
29
+     */
30
+    public function __construct($clientId, $clientSecret, array $scopes = [])
31
+    {
32
+        $this->clientId = $clientId;
33
+        $this->clientSecret = $clientSecret;
34
+        $this->scopes = $scopes;
35 35
     }
36 36
 
37 37
 
38
-	/**
39
-	 * @return Configuration
40
-	 */
41
-	public static function fromArray(array $conf)
42
-	{
43
-		return new static($conf['clientId'], $conf['clientSecret'], isset($conf['scopes']) ? $conf['scopes'] : []);
44
-	}
38
+    /**
39
+     * @return Configuration
40
+     */
41
+    public static function fromArray(array $conf)
42
+    {
43
+        return new static($conf['clientId'], $conf['clientSecret'], isset($conf['scopes']) ? $conf['scopes'] : []);
44
+    }
45 45
 
46 46
 }
Please login to merge, or discard this patch.
class/Github/OAuth/Login.php 2 patches
Indentation   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -14,158 +14,158 @@
 block discarded – undo
14 14
  */
15 15
 class Login extends Github\Sanity
16 16
 {
17
-	/** @var string */
18
-	private $authUrl = 'https://github.com/login/oauth/authorize';
19
-
20
-	/** @var string */
21
-	private $tokenUrl = 'https://github.com/login/oauth/access_token';
22
-
23
-	/** @var Configuration */
24
-	private $conf;
25
-
26
-	/** @var Storages\ISessionStorage */
27
-	private $storage;
28
-
29
-	/** @var Http\IClient */
30
-	private $client;
31
-
32
-
33
-	public function __construct(Configuration $conf, Storages\ISessionStorage $storage = NULL, Http\IClient $client = NULL)
34
-	{
35
-		$this->conf = $conf;
36
-		$this->storage = $storage ?: new Storages\SessionStorage;
37
-		$this->client = $client ?: Github\Helpers::createDefaultClient();
38
-	}
39
-
40
-
41
-	/**
42
-	 * @return Http\IClient
43
-	 */
44
-	public function getClient()
45
-	{
46
-		return $this->client;
47
-	}
48
-
49
-
50
-	/**
51
-	 * @param  string  URL to redirect back from Github when user approves the permissions request
52
-	 * @param  callable function($githubUrl)  makes HTTP redirect to Github
53
-	 */
54
-	public function askPermissions($backUrl, $redirectCb = NULL)
55
-	{
56
-		/** @todo Something more safe? */
57
-		$state = sha1(uniqid(microtime(TRUE), TRUE));
58
-		$params = [
59
-			'client_id' => $this->conf->clientId,
60
-			'redirect_uri' => $backUrl,
61
-			'scope' => implode(',', $this->conf->scopes),
62
-			'state' => $state,
63
-		];
64
-
65
-		$this->storage->set('auth.state', $state);
66
-
67
-		$url = $this->authUrl . '?' . http_build_query($params);
68
-		if ($redirectCb === NULL) {
69
-			header("Location: $url");
70
-			die();
71
-		} else {
72
-			call_user_func($redirectCb, $url);
73
-		}
74
-	}
75
-
76
-
77
-	/**
78
-	 * @param  string
79
-	 * @param  string
80
-	 * @return Token
81
-	 *
82
-	 * @throws LoginException
83
-	 */
84
-	public function obtainToken($code, $state)
85
-	{
86
-		if ($state !== $this->storage->get('auth.state')) {
87
-			throw new LoginException('OAuth security state does not match.');
88
-		}
89
-
90
-		$params = [
91
-			'client_id' => $this->conf->clientId,
92
-			'client_secret' => $this->conf->clientSecret,
93
-			'code' => $code,
94
-		];
95
-
96
-		$headers = [
97
-			'Accept' => 'application/json',
98
-			'Content-Type' => 'application/x-www-form-urlencoded',
99
-		];
100
-
101
-		$request = new Http\Request(Http\Request::POST, $this->tokenUrl, $headers, http_build_query($params));
102
-		try {
103
-			$response = $this->client->request($request);
104
-		} catch (Http\BadResponseException $e) {
105
-			throw new LoginException('HTTP request failed.', 0, $e);
106
-		}
107
-
108
-		try {
109
-			/** @var $json \stdClass */
110
-			if ($response->isCode(Http\Response::S404_NOT_FOUND)) {
111
-				$json = Github\Helpers::jsonDecode($response->getContent());
112
-				throw new LoginException($json->error, $response->getCode());
113
-
114
-			} elseif (!$response->isCode(Http\Response::S200_OK)) {
115
-				throw new LoginException('Unexpected response.', $response->getCode());
116
-			}
117
-
118
-			$json = Github\Helpers::jsonDecode($response->getContent());
119
-
120
-		} catch (Github\JsonException $e) {
121
-			throw new LoginException('Bad JSON in response.', 0, $e);
122
-		}
123
-
124
-		$token = new Token($json->access_token, $json->token_type, strlen($json->scope) ? explode(',', $json->scope) : []);
125
-		$this->storage->set('auth.token', $token->toArray());
126
-		$this->storage->remove('auth.state');
127
-
128
-		return $token;
129
-	}
130
-
131
-
132
-	/**
133
-	 * @return bool
134
-	 */
135
-	public function hasToken()
136
-	{
137
-		return $this->storage->get('auth.token') !== NULL;
138
-	}
139
-
140
-
141
-	/**
142
-	 * @return Token
143
-	 *
144
-	 * @throws Github\LogicException  when token has not been obtained yet
145
-	 */
146
-	public function getToken()
147
-	{
148
-		$token = $this->storage->get('auth.token');
149
-		if ($token === NULL) {
150
-			throw new Github\LogicException('Token has not been obtained yet.');
151
-
152
-		} elseif ($token instanceof Token) {
153
-			/** @deprecated */
154
-			$token = $token->toArray();
155
-			$this->storage->set('auth.token', $token);
156
-		}
157
-
158
-		return Token::createFromArray($token);
159
-	}
160
-
161
-
162
-	/**
163
-	 * @return self
164
-	 */
165
-	public function dropToken()
166
-	{
167
-		$this->storage->remove('auth.token');
168
-		return $this;
169
-	}
17
+    /** @var string */
18
+    private $authUrl = 'https://github.com/login/oauth/authorize';
19
+
20
+    /** @var string */
21
+    private $tokenUrl = 'https://github.com/login/oauth/access_token';
22
+
23
+    /** @var Configuration */
24
+    private $conf;
25
+
26
+    /** @var Storages\ISessionStorage */
27
+    private $storage;
28
+
29
+    /** @var Http\IClient */
30
+    private $client;
31
+
32
+
33
+    public function __construct(Configuration $conf, Storages\ISessionStorage $storage = NULL, Http\IClient $client = NULL)
34
+    {
35
+        $this->conf = $conf;
36
+        $this->storage = $storage ?: new Storages\SessionStorage;
37
+        $this->client = $client ?: Github\Helpers::createDefaultClient();
38
+    }
39
+
40
+
41
+    /**
42
+     * @return Http\IClient
43
+     */
44
+    public function getClient()
45
+    {
46
+        return $this->client;
47
+    }
48
+
49
+
50
+    /**
51
+     * @param  string  URL to redirect back from Github when user approves the permissions request
52
+     * @param  callable function($githubUrl)  makes HTTP redirect to Github
53
+     */
54
+    public function askPermissions($backUrl, $redirectCb = NULL)
55
+    {
56
+        /** @todo Something more safe? */
57
+        $state = sha1(uniqid(microtime(TRUE), TRUE));
58
+        $params = [
59
+            'client_id' => $this->conf->clientId,
60
+            'redirect_uri' => $backUrl,
61
+            'scope' => implode(',', $this->conf->scopes),
62
+            'state' => $state,
63
+        ];
64
+
65
+        $this->storage->set('auth.state', $state);
66
+
67
+        $url = $this->authUrl . '?' . http_build_query($params);
68
+        if ($redirectCb === NULL) {
69
+            header("Location: $url");
70
+            die();
71
+        } else {
72
+            call_user_func($redirectCb, $url);
73
+        }
74
+    }
75
+
76
+
77
+    /**
78
+     * @param  string
79
+     * @param  string
80
+     * @return Token
81
+     *
82
+     * @throws LoginException
83
+     */
84
+    public function obtainToken($code, $state)
85
+    {
86
+        if ($state !== $this->storage->get('auth.state')) {
87
+            throw new LoginException('OAuth security state does not match.');
88
+        }
89
+
90
+        $params = [
91
+            'client_id' => $this->conf->clientId,
92
+            'client_secret' => $this->conf->clientSecret,
93
+            'code' => $code,
94
+        ];
95
+
96
+        $headers = [
97
+            'Accept' => 'application/json',
98
+            'Content-Type' => 'application/x-www-form-urlencoded',
99
+        ];
100
+
101
+        $request = new Http\Request(Http\Request::POST, $this->tokenUrl, $headers, http_build_query($params));
102
+        try {
103
+            $response = $this->client->request($request);
104
+        } catch (Http\BadResponseException $e) {
105
+            throw new LoginException('HTTP request failed.', 0, $e);
106
+        }
107
+
108
+        try {
109
+            /** @var $json \stdClass */
110
+            if ($response->isCode(Http\Response::S404_NOT_FOUND)) {
111
+                $json = Github\Helpers::jsonDecode($response->getContent());
112
+                throw new LoginException($json->error, $response->getCode());
113
+
114
+            } elseif (!$response->isCode(Http\Response::S200_OK)) {
115
+                throw new LoginException('Unexpected response.', $response->getCode());
116
+            }
117
+
118
+            $json = Github\Helpers::jsonDecode($response->getContent());
119
+
120
+        } catch (Github\JsonException $e) {
121
+            throw new LoginException('Bad JSON in response.', 0, $e);
122
+        }
123
+
124
+        $token = new Token($json->access_token, $json->token_type, strlen($json->scope) ? explode(',', $json->scope) : []);
125
+        $this->storage->set('auth.token', $token->toArray());
126
+        $this->storage->remove('auth.state');
127
+
128
+        return $token;
129
+    }
130
+
131
+
132
+    /**
133
+     * @return bool
134
+     */
135
+    public function hasToken()
136
+    {
137
+        return $this->storage->get('auth.token') !== NULL;
138
+    }
139
+
140
+
141
+    /**
142
+     * @return Token
143
+     *
144
+     * @throws Github\LogicException  when token has not been obtained yet
145
+     */
146
+    public function getToken()
147
+    {
148
+        $token = $this->storage->get('auth.token');
149
+        if ($token === NULL) {
150
+            throw new Github\LogicException('Token has not been obtained yet.');
151
+
152
+        } elseif ($token instanceof Token) {
153
+            /** @deprecated */
154
+            $token = $token->toArray();
155
+            $this->storage->set('auth.token', $token);
156
+        }
157
+
158
+        return Token::createFromArray($token);
159
+    }
160
+
161
+
162
+    /**
163
+     * @return self
164
+     */
165
+    public function dropToken()
166
+    {
167
+        $this->storage->remove('auth.token');
168
+        return $this;
169
+    }
170 170
 
171 171
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@
 block discarded – undo
64 64
 
65 65
 		$this->storage->set('auth.state', $state);
66 66
 
67
-		$url = $this->authUrl . '?' . http_build_query($params);
67
+		$url = $this->authUrl.'?'.http_build_query($params);
68 68
 		if ($redirectCb === NULL) {
69 69
 			header("Location: $url");
70 70
 			die();
Please login to merge, or discard this patch.
class/Github/Storages/FileCache.php 2 patches
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -12,86 +12,86 @@
 block discarded – undo
12 12
  */
13 13
 class FileCache extends Github\Sanity implements ICache
14 14
 {
15
-	/** @var string */
16
-	private $dir;
17
-
18
-
19
-	/**
20
-	 * @param  string  temporary directory
21
-	 *
22
-	 * @throws MissingDirectoryException
23
-	 */
24
-	public function __construct($tempDir)
25
-	{
26
-		if (!is_dir($tempDir)) {
27
-			throw new MissingDirectoryException("Directory '$tempDir' is missing.");
28
-		}
29
-
30
-		$dir = $tempDir . DIRECTORY_SEPARATOR . 'milo.github-api';
31
-
32
-		if (!is_dir($dir)) {
33
-			set_error_handler(function($severity, $message, $file, $line) use ($dir, & $valid) {
34
-				restore_error_handler();
35
-				if (!is_dir($dir)) {
36
-					throw new MissingDirectoryException("Cannot create '$dir' directory.", 0, new \ErrorException($message, 0, $severity, $file, $line));
37
-				}
38
-			});
39
-			mkdir($dir);
40
-			restore_error_handler();
41
-		}
42
-
43
-		$this->dir = $dir;
44
-	}
45
-
46
-
47
-	/**
48
-	 * @param  string
49
-	 * @param  mixed
50
-	 * @return mixed  stored value
51
-	 */
52
-	public function save($key, $value)
53
-	{
54
-		file_put_contents(
55
-			$this->filePath($key),
56
-			serialize($value),
57
-			LOCK_EX
58
-		);
59
-
60
-		return $value;
61
-	}
62
-
63
-
64
-	/**
65
-	 * @param  string
66
-	 * @return mixed|NULL
67
-	 */
68
-	public function load($key)
69
-	{
70
-		$path = $this->filePath($key);
71
-		if (is_file($path) && ($fd = fopen($path, 'rb')) && flock($fd, LOCK_SH)) {
72
-			$cached = stream_get_contents($fd);
73
-			flock($fd, LOCK_UN);
74
-			fclose($fd);
75
-
76
-			$success = TRUE;
77
-			set_error_handler(function() use (& $success) { return $success = FALSE; }, E_NOTICE);
78
-			$cached = unserialize($cached);
79
-			restore_error_handler();
80
-
81
-			if ($success) {
82
-				return $cached;
83
-			}
84
-		}
85
-	}
86
-
87
-
88
-	/**
89
-	 * @param  string
90
-	 * @return string
91
-	 */
92
-	private function filePath($key)
93
-	{
94
-		return $this->dir . DIRECTORY_SEPARATOR . sha1($key) . '.php';
95
-	}
15
+    /** @var string */
16
+    private $dir;
17
+
18
+
19
+    /**
20
+     * @param  string  temporary directory
21
+     *
22
+     * @throws MissingDirectoryException
23
+     */
24
+    public function __construct($tempDir)
25
+    {
26
+        if (!is_dir($tempDir)) {
27
+            throw new MissingDirectoryException("Directory '$tempDir' is missing.");
28
+        }
29
+
30
+        $dir = $tempDir . DIRECTORY_SEPARATOR . 'milo.github-api';
31
+
32
+        if (!is_dir($dir)) {
33
+            set_error_handler(function($severity, $message, $file, $line) use ($dir, & $valid) {
34
+                restore_error_handler();
35
+                if (!is_dir($dir)) {
36
+                    throw new MissingDirectoryException("Cannot create '$dir' directory.", 0, new \ErrorException($message, 0, $severity, $file, $line));
37
+                }
38
+            });
39
+            mkdir($dir);
40
+            restore_error_handler();
41
+        }
42
+
43
+        $this->dir = $dir;
44
+    }
45
+
46
+
47
+    /**
48
+     * @param  string
49
+     * @param  mixed
50
+     * @return mixed  stored value
51
+     */
52
+    public function save($key, $value)
53
+    {
54
+        file_put_contents(
55
+            $this->filePath($key),
56
+            serialize($value),
57
+            LOCK_EX
58
+        );
59
+
60
+        return $value;
61
+    }
62
+
63
+
64
+    /**
65
+     * @param  string
66
+     * @return mixed|NULL
67
+     */
68
+    public function load($key)
69
+    {
70
+        $path = $this->filePath($key);
71
+        if (is_file($path) && ($fd = fopen($path, 'rb')) && flock($fd, LOCK_SH)) {
72
+            $cached = stream_get_contents($fd);
73
+            flock($fd, LOCK_UN);
74
+            fclose($fd);
75
+
76
+            $success = TRUE;
77
+            set_error_handler(function() use (& $success) { return $success = FALSE; }, E_NOTICE);
78
+            $cached = unserialize($cached);
79
+            restore_error_handler();
80
+
81
+            if ($success) {
82
+                return $cached;
83
+            }
84
+        }
85
+    }
86
+
87
+
88
+    /**
89
+     * @param  string
90
+     * @return string
91
+     */
92
+    private function filePath($key)
93
+    {
94
+        return $this->dir . DIRECTORY_SEPARATOR . sha1($key) . '.php';
95
+    }
96 96
 
97 97
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 			throw new MissingDirectoryException("Directory '$tempDir' is missing.");
28 28
 		}
29 29
 
30
-		$dir = $tempDir . DIRECTORY_SEPARATOR . 'milo.github-api';
30
+		$dir = $tempDir.DIRECTORY_SEPARATOR.'milo.github-api';
31 31
 
32 32
 		if (!is_dir($dir)) {
33 33
 			set_error_handler(function($severity, $message, $file, $line) use ($dir, & $valid) {
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 	 */
92 92
 	private function filePath($key)
93 93
 	{
94
-		return $this->dir . DIRECTORY_SEPARATOR . sha1($key) . '.php';
94
+		return $this->dir.DIRECTORY_SEPARATOR.sha1($key).'.php';
95 95
 	}
96 96
 
97 97
 }
Please login to merge, or discard this patch.
class/Github/Storages/ICache.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -5,18 +5,18 @@
 block discarded – undo
5 5
 
6 6
 interface ICache
7 7
 {
8
-	/**
9
-	 * @param  string
10
-	 * @param  mixed
11
-	 * @return mixed  stored value
12
-	 */
13
-	function save($key, $value);
8
+    /**
9
+     * @param  string
10
+     * @param  mixed
11
+     * @return mixed  stored value
12
+     */
13
+    function save($key, $value);
14 14
 
15 15
 
16
-	/**
17
-	 * @param  string
18
-	 * @return mixed|NULL
19
-	 */
20
-	function load($key);
16
+    /**
17
+     * @param  string
18
+     * @return mixed|NULL
19
+     */
20
+    function load($key);
21 21
 
22 22
 }
Please login to merge, or discard this patch.
class/Github/Storages/ISessionStorage.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -8,25 +8,25 @@
 block discarded – undo
8 8
  */
9 9
 interface ISessionStorage
10 10
 {
11
-	/**
12
-	 * @param  string
13
-	 * @param  mixed
14
-	 * @return self
15
-	 */
16
-	function set($name, $value);
17
-
18
-
19
-	/**
20
-	 * @param  string
21
-	 * @return mixed
22
-	 */
23
-	function get($name);
24
-
25
-
26
-	/**
27
-	 * @param  string
28
-	 * @return self
29
-	 */
30
-	function remove($name);
11
+    /**
12
+     * @param  string
13
+     * @param  mixed
14
+     * @return self
15
+     */
16
+    function set($name, $value);
17
+
18
+
19
+    /**
20
+     * @param  string
21
+     * @return mixed
22
+     */
23
+    function get($name);
24
+
25
+
26
+    /**
27
+     * @param  string
28
+     * @return self
29
+     */
30
+    function remove($name);
31 31
 
32 32
 }
Please login to merge, or discard this patch.
class/Github/Storages/SessionStorage.php 1 patch
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -12,75 +12,75 @@
 block discarded – undo
12 12
  */
13 13
 class SessionStorage extends Github\Sanity implements ISessionStorage
14 14
 {
15
-	const SESSION_KEY = 'milo.github-api';
16
-
17
-	/** @var string */
18
-	private $sessionKey;
19
-
20
-
21
-	/**
22
-	 * @param  string
23
-	 */
24
-	public function __construct($sessionKey = self::SESSION_KEY)
25
-	{
26
-		$this->sessionKey = $sessionKey;
27
-	}
28
-
29
-
30
-	/**
31
-	 * @param  string
32
-	 * @param  mixed
33
-	 * @return self
34
-	 */
35
-	public function set($name, $value)
36
-	{
37
-		if ($value === NULL) {
38
-			return $this->remove($name);
39
-		}
40
-
41
-		$this->check(__METHOD__);
42
-		$_SESSION[$this->sessionKey][$name] = $value;
43
-
44
-		return $this;
45
-	}
46
-
47
-
48
-	/**
49
-	 * @param  string
50
-	 * @return mixed
51
-	 */
52
-	public function get($name)
53
-	{
54
-		$this->check(__METHOD__);
55
-
56
-		return isset($_SESSION[$this->sessionKey][$name])
57
-			? $_SESSION[$this->sessionKey][$name]
58
-			: NULL;
59
-	}
60
-
61
-
62
-	/**
63
-	 * @param  string
64
-	 * @return self
65
-	 */
66
-	public function remove($name)
67
-	{
68
-		$this->check(__METHOD__);
69
-
70
-		unset($_SESSION[$this->sessionKey][$name]);
71
-
72
-		return $this;
73
-	}
74
-
75
-
76
-	/**
77
-	 * @param  string
78
-	 */
79
-	private function check($method)
80
-	{
81
-		if (!isset($_SESSION)) {
82
-			trigger_error("Start session before using $method().", E_USER_WARNING);
83
-		}
84
-	}
15
+    const SESSION_KEY = 'milo.github-api';
16
+
17
+    /** @var string */
18
+    private $sessionKey;
19
+
20
+
21
+    /**
22
+     * @param  string
23
+     */
24
+    public function __construct($sessionKey = self::SESSION_KEY)
25
+    {
26
+        $this->sessionKey = $sessionKey;
27
+    }
28
+
29
+
30
+    /**
31
+     * @param  string
32
+     * @param  mixed
33
+     * @return self
34
+     */
35
+    public function set($name, $value)
36
+    {
37
+        if ($value === NULL) {
38
+            return $this->remove($name);
39
+        }
40
+
41
+        $this->check(__METHOD__);
42
+        $_SESSION[$this->sessionKey][$name] = $value;
43
+
44
+        return $this;
45
+    }
46
+
47
+
48
+    /**
49
+     * @param  string
50
+     * @return mixed
51
+     */
52
+    public function get($name)
53
+    {
54
+        $this->check(__METHOD__);
55
+
56
+        return isset($_SESSION[$this->sessionKey][$name])
57
+            ? $_SESSION[$this->sessionKey][$name]
58
+            : NULL;
59
+    }
60
+
61
+
62
+    /**
63
+     * @param  string
64
+     * @return self
65
+     */
66
+    public function remove($name)
67
+    {
68
+        $this->check(__METHOD__);
69
+
70
+        unset($_SESSION[$this->sessionKey][$name]);
71
+
72
+        return $this;
73
+    }
74
+
75
+
76
+    /**
77
+     * @param  string
78
+     */
79
+    private function check($method)
80
+    {
81
+        if (!isset($_SESSION)) {
82
+            trigger_error("Start session before using $method().", E_USER_WARNING);
83
+        }
84
+    }
85 85
 
86 86
 }
Please login to merge, or discard this patch.
class/Github/Helpers.php 1 patch
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -13,89 +13,89 @@
 block discarded – undo
13 13
  */
14 14
 class Helpers
15 15
 {
16
-	private static $jsonMessages = [
17
-		JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded',
18
-		JSON_ERROR_STATE_MISMATCH => 'Syntax error, malformed JSON',
19
-		JSON_ERROR_CTRL_CHAR => 'Unexpected control character found',
20
-		JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON',
21
-		JSON_ERROR_UTF8 => 'Invalid UTF-8 sequence',
22
-	];
23
-
24
-
25
-	/** @var Http\IClient */
26
-	private static $client;
27
-
28
-
29
-	/**
30
-	 * @param  mixed
31
-	 * @return string
32
-	 *
33
-	 * @throws JsonException
34
-	 */
35
-	public static function jsonEncode($value)
36
-	{
37
-		if (PHP_VERSION_ID < 50500) {
38
-			set_error_handler(function($severity, $message) { // needed to receive 'recursion detected' error
39
-				restore_error_handler();
40
-				throw new JsonException($message);
41
-			});
42
-		}
43
-
44
-		$json = json_encode($value, JSON_UNESCAPED_UNICODE);
45
-
46
-		if (PHP_VERSION_ID < 50500) {
47
-			restore_error_handler();
48
-		}
49
-
50
-		if ($error = json_last_error()) {
51
-			$message = isset(static::$jsonMessages[$error])
52
-				? static::$jsonMessages[$error]
53
-				: (PHP_VERSION_ID >= 50500 ? json_last_error_msg() : 'Unknown error');
54
-
55
-			throw new JsonException($message, $error);
56
-		}
57
-
58
-		$json = str_replace(array("\xe2\x80\xa8", "\xe2\x80\xa9"), array('\u2028', '\u2029'), $json);
59
-		return $json;
60
-	}
61
-
62
-
63
-	/**
64
-	 * @param  mixed
65
-	 * @return string
66
-	 *
67
-	 * @throws JsonException
68
-	 */
69
-	public static function jsonDecode($json, $assoc = false)
70
-	{
71
-		$json = (string) $json;
72
-		if (!preg_match('##u', $json)) {
73
-			throw new JsonException('Invalid UTF-8 sequence', 5); // PECL JSON-C
74
-		}
75
-
76
-		$value = json_decode($json, $assoc, 512, (defined('JSON_C_VERSION') && PHP_INT_SIZE > 4) ? 0 : JSON_BIGINT_AS_STRING);
77
-
78
-		if ($value === NULL && $json !== '' && strcasecmp($json, 'null')) { // '' does not clear json_last_error()
79
-			$error = json_last_error();
80
-			throw new JsonException(isset(static::$jsonMessages[$error]) ? static::$jsonMessages[$error] : 'Unknown error', $error);
81
-		}
82
-		return $value;
83
-	}
84
-
85
-
86
-	/**
87
-	 * @param  bool
88
-	 * @return Http\IClient
89
-	 */
90
-	public static function createDefaultClient($newInstance = FALSE)
91
-	{
92
-		if (self::$client === NULL || $newInstance) {
93
-			self::$client = extension_loaded('curl')
94
-				? new Http\CurlClient
95
-				: new Http\StreamClient;
96
-		}
97
-
98
-		return self::$client;
99
-	}
16
+    private static $jsonMessages = [
17
+        JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded',
18
+        JSON_ERROR_STATE_MISMATCH => 'Syntax error, malformed JSON',
19
+        JSON_ERROR_CTRL_CHAR => 'Unexpected control character found',
20
+        JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON',
21
+        JSON_ERROR_UTF8 => 'Invalid UTF-8 sequence',
22
+    ];
23
+
24
+
25
+    /** @var Http\IClient */
26
+    private static $client;
27
+
28
+
29
+    /**
30
+     * @param  mixed
31
+     * @return string
32
+     *
33
+     * @throws JsonException
34
+     */
35
+    public static function jsonEncode($value)
36
+    {
37
+        if (PHP_VERSION_ID < 50500) {
38
+            set_error_handler(function($severity, $message) { // needed to receive 'recursion detected' error
39
+                restore_error_handler();
40
+                throw new JsonException($message);
41
+            });
42
+        }
43
+
44
+        $json = json_encode($value, JSON_UNESCAPED_UNICODE);
45
+
46
+        if (PHP_VERSION_ID < 50500) {
47
+            restore_error_handler();
48
+        }
49
+
50
+        if ($error = json_last_error()) {
51
+            $message = isset(static::$jsonMessages[$error])
52
+                ? static::$jsonMessages[$error]
53
+                : (PHP_VERSION_ID >= 50500 ? json_last_error_msg() : 'Unknown error');
54
+
55
+            throw new JsonException($message, $error);
56
+        }
57
+
58
+        $json = str_replace(array("\xe2\x80\xa8", "\xe2\x80\xa9"), array('\u2028', '\u2029'), $json);
59
+        return $json;
60
+    }
61
+
62
+
63
+    /**
64
+     * @param  mixed
65
+     * @return string
66
+     *
67
+     * @throws JsonException
68
+     */
69
+    public static function jsonDecode($json, $assoc = false)
70
+    {
71
+        $json = (string) $json;
72
+        if (!preg_match('##u', $json)) {
73
+            throw new JsonException('Invalid UTF-8 sequence', 5); // PECL JSON-C
74
+        }
75
+
76
+        $value = json_decode($json, $assoc, 512, (defined('JSON_C_VERSION') && PHP_INT_SIZE > 4) ? 0 : JSON_BIGINT_AS_STRING);
77
+
78
+        if ($value === NULL && $json !== '' && strcasecmp($json, 'null')) { // '' does not clear json_last_error()
79
+            $error = json_last_error();
80
+            throw new JsonException(isset(static::$jsonMessages[$error]) ? static::$jsonMessages[$error] : 'Unknown error', $error);
81
+        }
82
+        return $value;
83
+    }
84
+
85
+
86
+    /**
87
+     * @param  bool
88
+     * @return Http\IClient
89
+     */
90
+    public static function createDefaultClient($newInstance = FALSE)
91
+    {
92
+        if (self::$client === NULL || $newInstance) {
93
+            self::$client = extension_loaded('curl')
94
+                ? new Http\CurlClient
95
+                : new Http\StreamClient;
96
+        }
97
+
98
+        return self::$client;
99
+    }
100 100
 
101 101
 }
Please login to merge, or discard this patch.
class/RepositoriesHandler.php 1 patch
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -31,96 +31,96 @@
 block discarded – undo
31 31
  */
32 32
 class RepositoriesHandler extends \XoopsPersistableObjectHandler
33 33
 {
34
-	/**
35
-	 * Constructor
36
-	 *
37
-	 * @param \XoopsDatabase $db
38
-	 */
39
-	public function __construct(\XoopsDatabase $db)
40
-	{
41
-		parent::__construct($db, 'wggithub_repositories', Repositories::class, 'repo_id', 'repo_name');
42
-	}
43
-
44
-	/**
45
-	 * @param bool $isNew
46
-	 *
47
-	 * @return object
48
-	 */
49
-	public function create($isNew = true)
50
-	{
51
-		return parent::create($isNew);
52
-	}
53
-
54
-	/**
55
-	 * retrieve a field
56
-	 *
57
-	 * @param int $i field id
58
-	 * @param null fields
59
-	 * @return mixed reference to the {@link Get} object
60
-	 */
61
-	public function get($i = null, $fields = null)
62
-	{
63
-		return parent::get($i, $fields);
64
-	}
65
-
66
-	/**
67
-	 * get inserted id
68
-	 *
69
-	 * @param null
70
-	 * @return int reference to the {@link Get} object
71
-	 */
72
-	public function getInsertId()
73
-	{
74
-		return $this->db->getInsertId();
75
-	}
76
-
77
-	/**
78
-	 * Get Count Repositories in the database
79
-	 * @param int    $start
80
-	 * @param int    $limit
81
-	 * @param string $sort
82
-	 * @param string $order
83
-	 * @return int
84
-	 */
85
-	public function getCountRepositories($start = 0, $limit = 0, $sort = 'repo_id ASC, repo_name', $order = 'ASC')
86
-	{
87
-		$crCountRepositories = new \CriteriaCompo();
88
-		$crCountRepositories = $this->getRepositoriesCriteria($crCountRepositories, $start, $limit, $sort, $order);
89
-		return $this->getCount($crCountRepositories);
90
-	}
91
-
92
-	/**
93
-	 * Get All Repositories in the database
94
-	 * @param int    $start
95
-	 * @param int    $limit
96
-	 * @param string $sort
97
-	 * @param string $order
98
-	 * @return array
99
-	 */
100
-	public function getAllRepositories($start = 0, $limit = 0, $sort = 'repo_id ASC, repo_name', $order = 'ASC')
101
-	{
102
-		$crAllRepositories = new \CriteriaCompo();
103
-		$crAllRepositories = $this->getRepositoriesCriteria($crAllRepositories, $start, $limit, $sort, $order);
104
-		return $this->getAll($crAllRepositories);
105
-	}
106
-
107
-	/**
108
-	 * Get Criteria Repositories
109
-	 * @param        $crRepositories
110
-	 * @param int    $start
111
-	 * @param int    $limit
112
-	 * @param string $sort
113
-	 * @param string $order
114
-	 * @return int
115
-	 */
116
-	private function getRepositoriesCriteria($crRepositories, $start, $limit, $sort, $order)
117
-	{
118
-		$crRepositories->setStart($start);
119
-		$crRepositories->setLimit($limit);
120
-		$crRepositories->setSort($sort);
121
-		$crRepositories->setOrder($order);
122
-		return $crRepositories;
123
-	}
34
+    /**
35
+     * Constructor
36
+     *
37
+     * @param \XoopsDatabase $db
38
+     */
39
+    public function __construct(\XoopsDatabase $db)
40
+    {
41
+        parent::__construct($db, 'wggithub_repositories', Repositories::class, 'repo_id', 'repo_name');
42
+    }
43
+
44
+    /**
45
+     * @param bool $isNew
46
+     *
47
+     * @return object
48
+     */
49
+    public function create($isNew = true)
50
+    {
51
+        return parent::create($isNew);
52
+    }
53
+
54
+    /**
55
+     * retrieve a field
56
+     *
57
+     * @param int $i field id
58
+     * @param null fields
59
+     * @return mixed reference to the {@link Get} object
60
+     */
61
+    public function get($i = null, $fields = null)
62
+    {
63
+        return parent::get($i, $fields);
64
+    }
65
+
66
+    /**
67
+     * get inserted id
68
+     *
69
+     * @param null
70
+     * @return int reference to the {@link Get} object
71
+     */
72
+    public function getInsertId()
73
+    {
74
+        return $this->db->getInsertId();
75
+    }
76
+
77
+    /**
78
+     * Get Count Repositories in the database
79
+     * @param int    $start
80
+     * @param int    $limit
81
+     * @param string $sort
82
+     * @param string $order
83
+     * @return int
84
+     */
85
+    public function getCountRepositories($start = 0, $limit = 0, $sort = 'repo_id ASC, repo_name', $order = 'ASC')
86
+    {
87
+        $crCountRepositories = new \CriteriaCompo();
88
+        $crCountRepositories = $this->getRepositoriesCriteria($crCountRepositories, $start, $limit, $sort, $order);
89
+        return $this->getCount($crCountRepositories);
90
+    }
91
+
92
+    /**
93
+     * Get All Repositories in the database
94
+     * @param int    $start
95
+     * @param int    $limit
96
+     * @param string $sort
97
+     * @param string $order
98
+     * @return array
99
+     */
100
+    public function getAllRepositories($start = 0, $limit = 0, $sort = 'repo_id ASC, repo_name', $order = 'ASC')
101
+    {
102
+        $crAllRepositories = new \CriteriaCompo();
103
+        $crAllRepositories = $this->getRepositoriesCriteria($crAllRepositories, $start, $limit, $sort, $order);
104
+        return $this->getAll($crAllRepositories);
105
+    }
106
+
107
+    /**
108
+     * Get Criteria Repositories
109
+     * @param        $crRepositories
110
+     * @param int    $start
111
+     * @param int    $limit
112
+     * @param string $sort
113
+     * @param string $order
114
+     * @return int
115
+     */
116
+    private function getRepositoriesCriteria($crRepositories, $start, $limit, $sort, $order)
117
+    {
118
+        $crRepositories->setStart($start);
119
+        $crRepositories->setLimit($limit);
120
+        $crRepositories->setSort($sort);
121
+        $crRepositories->setOrder($order);
122
+        return $crRepositories;
123
+    }
124 124
 
125 125
     /**
126 126
      * Update table repositories
Please login to merge, or discard this patch.