Completed
Push — master ( a212ae...265042 )
by Francis
06:52
created

GMail   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 5
eloc 15
c 3
b 0
f 0
dl 0
loc 48
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 2 1
A getToken() 0 1 1
A getAuthorizeUrl() 0 9 2
A getClientId() 0 2 1
1
<?php
2
declare(strict_types=1);
3
defined('BASEPATH') OR exit('No direct script access allowed');
4
5
require_once('GMailScopes.php');
6
require_once('GMailUtil.php');
7
8
class GMail {
9
10
  const AUTH_URL  = 'https://accounts.google.com/o/oauth2/auth';
11
  const TOKEN_URL = 'https://accounts.google.com/o/oauth2/token';
12
  private $ci;
0 ignored issues
show
introduced by
The private property $ci is not used, and could be removed.
Loading history...
13
  private $clientId;
14
15
  /**
16
   * [init Initialize library with cofigs. Can be called multiple times to set
17
   *       config items]
18
   * @param array $config Associative Config Array.
19
   */
20
  public function init(array $config=null):void {
21
    $this->clientId = $config['client_id'] ?? $this->clientId;
22
  }
23
  /**
24
   * [getAuthorizeUrl Gets/composes the authorize url to direct users to so they
25
   *                  can give your application access to their GMail accounts
26
   *                  based on the given scopes.]
27
   * @param  string $scope        Access Scope.
28
   * @param  string $redirectUri  URL to redirect to after access is granted.
29
   * @param  string $responseType Response type. 'code' by default.
30
   * @return string               Authorize URL
31
   */
32
  public function getAuthorizeUrl(string $scope, string $redirectUri='urn:ietf:wg:oauth:2.0:oob', string $responseType='code', string $accessType='offline'):string {
33
    if ($scope == null) throw new Exception("GMail scope cannot be null");
34
    return self::AUTH_URL . new URLQueryBuilder([
0 ignored issues
show
Bug introduced by
Are you sure new URLQueryBuilder(arra..._type' => $accessType)) of type URLQueryBuilder can be used in concatenation? Consider adding a __toString()-method. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

34
    return self::AUTH_URL . /** @scrutinizer ignore-type */ new URLQueryBuilder([
Loading history...
35
      'client_id'     => $this->clientId,
36
      'redirect_uri'  => $redirectUri,
37
      'scope'         => $scope,
38
      'response_type' => $responseType,
39
      'access_type'   => $accessType
40
    ]).build();
0 ignored issues
show
Bug introduced by
The function build was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

40
    ])./** @scrutinizer ignore-call */ build();
Loading history...
41
  }
42
  /**
43
   * [getToken description]
44
   * @param  string $code [description]
45
   * @return [type]       [description]
0 ignored issues
show
Documentation Bug introduced by
The doc comment [type] at position 0 could not be parsed: Unknown type name '[' at position 0 in [type].
Loading history...
46
   */
47
  public function getToken(string $code):?array {
0 ignored issues
show
Unused Code introduced by
The parameter $code is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

47
  public function getToken(/** @scrutinizer ignore-unused */ string $code):?array {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
48
49
  }
50
  /**
51
   * [getClientId Get Client ID.]
52
   * @return null|string Client ID.
53
   */
54
  public function getClientId():?string {
55
    return $this->clientId;
56
  }
57
}
58
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
59