Passed
Push — master ( 1230d1...ab986e )
by Francis
01:11
created

GMail   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 6
eloc 16
c 4
b 0
f 0
dl 0
loc 51
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 2 1
A __construct() 0 3 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 $clientId;
13
14
  function __construct($params=null) {
15
    get_instance()->load->splint('francis94c/ci-gmail', '%curl');
0 ignored issues
show
Bug introduced by
The function get_instance 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

15
    /** @scrutinizer ignore-call */ 
16
    get_instance()->load->splint('francis94c/ci-gmail', '%curl');
Loading history...
16
    $this->clientId = $params['client_id'] ?? $this->clientId;
17
  }
18
  /**
19
   * [init Initialize library with cofigs. Can be called multiple times to set
20
   *       config items]
21
   * @param array $config Associative Config Array.
22
   */
23
  public function init(array $config=null):void {
24
    $this->clientId = $config['client_id'] ?? $this->clientId;
25
  }
26
  /**
27
   * [getAuthorizeUrl Gets/composes the authorize url to direct users to so they
28
   *                  can give your application access to their GMail accounts
29
   *                  based on the given scopes.]
30
   * @param  string $scope        Access Scope.
31
   * @param  string $redirectUri  URL to redirect to after access is granted.
32
   * @param  string $responseType Response type. 'code' by default.
33
   * @return string               Authorize URL
34
   */
35
  public function getAuthorizeUrl(string $scope, string $redirectUri='urn:ietf:wg:oauth:2.0:oob', string $responseType='code', string $accessType='offline'):string {
36
    if ($scope == null) throw new Exception("GMail scope cannot be null");
37
    return self::AUTH_URL . build_url_query([
38
      'client_id'     => $this->clientId,
39
      'redirect_uri'  => $redirectUri,
40
      'scope'         => $scope,
41
      'response_type' => $responseType,
42
      'access_type'   => $accessType
43
    ], false);
44
  }
45
  /**
46
   * [getToken description]
47
   * @param  string $code [description]
48
   * @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...
49
   */
50
  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

50
  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...
51
52
  }
53
  /**
54
   * [getClientId Get Client ID.]
55
   * @return null|string Client ID.
56
   */
57
  public function getClientId():?string {
58
    return $this->clientId;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->clientId could return the type mixed which is incompatible with the type-hinted return null|string. Consider adding an additional type-check to rule them out.
Loading history...
59
  }
60
}
61
?>
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...
62