LaravelGmailClass   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 14
c 2
b 0
f 0
dl 0
loc 64
rs 10
wmc 9

7 Methods

Rating   Name   Duplication   Size   Complexity  
A user() 0 3 1
A message() 0 7 2
A redirect() 0 3 1
A logout() 0 4 1
A getAuthUrl() 0 3 1
A __construct() 0 7 2
A setUserId() 0 4 1
1
<?php
2
3
namespace Dacastro4\LaravelGmail;
4
5
use Dacastro4\LaravelGmail\Exceptions\AuthException;
6
use Dacastro4\LaravelGmail\Services\Message;
7
use Illuminate\Support\Facades\Redirect;
8
9
class LaravelGmailClass extends GmailConnection
10
{
11
	public function __construct($config, $userId = null)
12
	{
13
		if (class_basename($config) === 'Application') {
14
			$config = $config['config'];
15
		}
16
17
		parent::__construct($config, $userId);
18
	}
19
20
	/**
21
	 * @return Message
22
	 * @throws AuthException
23
	 */
24
	public function message()
25
	{
26
		if (!$this->getToken()) {
27
			throw new AuthException('No credentials found.');
28
		}
29
30
		return new Message($this);
31
	}
32
33
	/**
34
	 * Returns the Gmail user email
35
	 *
36
	 * @return \Google_Service_Gmail_Profile
37
	 */
38
	public function user()
39
	{
40
		return $this->config('email');
41
	}
42
43
	/**
44
	 * Updates / sets the current userId for the service
45
	 *
46
	 * @return \Google_Service_Gmail_Profile
47
	 */
48
	public function setUserId($userId)
49
	{
50
		$this->userId = $userId;
51
		return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Dacastro4\LaravelGmail\LaravelGmailClass which is incompatible with the documented return type Google_Service_Gmail_Profile.
Loading history...
52
	}
53
54
	public function redirect()
55
	{
56
		return Redirect::to($this->getAuthUrl());
57
	}
58
59
	/**
60
	 * Gets the URL to authorize the user
61
	 *
62
	 * @return string
63
	 */
64
	public function getAuthUrl()
65
	{
66
		return $this->createAuthUrl();
67
	}
68
69
	public function logout()
70
	{
71
		$this->revokeToken();
72
		$this->deleteAccessToken();
73
	}
74
75
}
76