Passed
Push — master ( 225a9b...122a16 )
by Daniel
01:45
created

Configurable::mapScopes()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 2
nop 0
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Dacastro4\LaravelGmail\Traits;
4
5
use Google_Service_Gmail;
6
use Illuminate\Support\Facades\Storage;
7
8
trait Configurable
9
{
10
11
	public function config( $string = null, $email = null )
12
	{
13
		$email = $email ?: $this->emailAddress;
0 ignored issues
show
Bug Best Practice introduced by
The property emailAddress does not exist on Dacastro4\LaravelGmail\Traits\Configurable. Did you maybe forget to declare it?
Loading history...
14
		$fileName = $this->getFileName( $email );
0 ignored issues
show
Unused Code introduced by
The call to Dacastro4\LaravelGmail\T...igurable::getFileName() has too many arguments starting with $email. ( Ignorable by Annotation )

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

14
		/** @scrutinizer ignore-call */ 
15
  $fileName = $this->getFileName( $email );

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
15
		$file = "gmail/tokens/{$fileName}.json";
16
17
		if ( Storage::exists( $file ) ) {
18
			$config = json_decode(
19
				Storage::get( $file ),
0 ignored issues
show
Bug introduced by
Illuminate\Support\Facades\Storage::get($file) of type Illuminate\Contracts\Filesystem\Filesystem is incompatible with the type string expected by parameter $json of json_decode(). ( Ignorable by Annotation )

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

19
				/** @scrutinizer ignore-type */ Storage::get( $file ),
Loading history...
20
				true
21
			);
22
23
			if ( $string ) {
24
				if ( isset( $config[ $string ] ) ) {
25
					return $config[ $string ];
26
				}
27
			} else {
28
				return $config;
29
			}
30
31
		}
32
33
		return null;
34
	}
35
36
	/**
37
	 * @return array
38
	 */
39
	public function getConfigs()
40
	{
41
		return [
42
			'client_secret' => $this->configuration[ 'gmail.client_secret' ],
0 ignored issues
show
Bug Best Practice introduced by
The property configuration does not exist on Dacastro4\LaravelGmail\Traits\Configurable. Did you maybe forget to declare it?
Loading history...
43
			'client_id'     => $this->configuration[ 'gmail.client_id' ],
44
			'redirect_uri'  => url( $this->configuration[ 'gmail.redirect_url' ] ),
45
		];
46
	}
47
48
	private function getUserScopes()
49
	{
50
		return array_merge( [
51
			                    Google_Service_Gmail::GMAIL_READONLY,
52
		                    ], $this->mapScopes() );
53
	}
54
55
	private function configApi()
56
	{
57
		$type = $this->configuration[ 'gmail.access_type' ];
0 ignored issues
show
Bug Best Practice introduced by
The property configuration does not exist on Dacastro4\LaravelGmail\Traits\Configurable. Did you maybe forget to declare it?
Loading history...
58
		$approval_prompt = $this->configuration[ 'gmail.approval_prompt' ];
59
60
		$this->setScopes( $this->getUserScopes() );
0 ignored issues
show
Bug introduced by
It seems like setScopes() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

60
		$this->/** @scrutinizer ignore-call */ 
61
         setScopes( $this->getUserScopes() );
Loading history...
61
62
		$this->setAccessType( $type );
0 ignored issues
show
Bug introduced by
It seems like setAccessType() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

62
		$this->/** @scrutinizer ignore-call */ 
63
         setAccessType( $type );
Loading history...
63
64
		$this->setApprovalPrompt( $approval_prompt );
0 ignored issues
show
Bug introduced by
It seems like setApprovalPrompt() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

64
		$this->/** @scrutinizer ignore-call */ 
65
         setApprovalPrompt( $approval_prompt );
Loading history...
65
	}
66
67
	private function getFileName()
68
	{
69
		return $this->configuration[ 'gmail.credentials_file_name' ];
0 ignored issues
show
Bug Best Practice introduced by
The property configuration does not exist on Dacastro4\LaravelGmail\Traits\Configurable. Did you maybe forget to declare it?
Loading history...
70
	}
71
72
	private function mapScopes()
73
	{
74
		$scopes = $this->configuration[ 'gmail.scopes' ];
0 ignored issues
show
Bug Best Practice introduced by
The property configuration does not exist on Dacastro4\LaravelGmail\Traits\Configurable. Did you maybe forget to declare it?
Loading history...
75
		$mappedScopes = [];
76
77
		if ( ! empty( $scopes ) ) {
78
			foreach ( $scopes as $scope ) {
79
				$mappedScopes[] = $this->scopeMap( $scope );
80
			}
81
		}
82
83
		return $mappedScopes;
84
	}
85
86
	private function scopeMap( $scope )
87
	{
88
		switch ( $scope ) {
89
			case 'all':
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
90
				{
91
					return Google_Service_Gmail::MAIL_GOOGLE_COM;
92
				}
93
			case 'compose':
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
94
				{
95
					return Google_Service_Gmail::GMAIL_COMPOSE;
96
				}
97
			case 'insert':
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
98
				{
99
					return Google_Service_Gmail::GMAIL_INSERT;
100
				}
101
			case 'labels':
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
102
				{
103
					return Google_Service_Gmail::GMAIL_LABELS;
104
				}
105
			case 'metadata':
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
106
				{
107
					return Google_Service_Gmail::GMAIL_METADATA;
108
				}
109
			case 'modify':
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
110
				{
111
					return Google_Service_Gmail::GMAIL_MODIFY;
112
				}
113
			case 'readonly':
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
114
				{
115
					return Google_Service_Gmail::GMAIL_READONLY;
116
				}
117
			case 'send':
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
118
				{
119
					return Google_Service_Gmail::GMAIL_SEND;
120
				}
121
			case 'settings_basic':
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
122
				{
123
					return Google_Service_Gmail::GMAIL_SETTINGS_BASIC;
124
				}
125
			case 'settings_sharing':
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
126
				{
127
					return Google_Service_Gmail::GMAIL_SETTINGS_SHARING;
128
				}
129
		}
130
	}
131
132
}