GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — master (#44)
by
unknown
03:43
created

DomainWhitelisting   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 96
ccs 26
cts 26
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A validateAction() 0 6 2
A jsonSerialize() 0 7 1
A getDomains() 0 4 1
A getAction() 0 4 1
A validateDomains() 0 13 4
1
<?php
2
3
namespace Tgallice\FBMessenger\Model\ThreadSetting;
4
5
use Tgallice\FBMessenger\Model\ThreadSetting;
6
7
class DomainWhitelisting implements ThreadSetting, \JsonSerializable
8
{
9
	const TYPE_ADD = 'add';
10
	const TYPE_REMOVE = 'remove';
11
	
12
	const WHITELISTED_DOMAINS = 'whitelisted_domains';
13
	const DOMAIN_ACTION_TYPE = 'domain_action_type';
14
	
15
	/**
16
	 * @var string
17
	 */
18
	private $action;
19
	
20
	/**
21
	 * @var array
22
	 */
23
	private $domains = [];
24
	
25
	/**
26
	 * 
27
	 * @param string $action
28
	 * @param array $domains
29
	 * 
30
	 * @throws \InvalidArgumentException
31
	 */
32 9
	public function __construct($domains, $action = DomainWhitelisting::TYPE_ADD)
33
	{
34 9
		self::validateAction($action);
35 8
		self::validateDomains($domains);
36
		
37 6
		$this->action = $action;
38 6
		$this->domains = $domains;
39 6
	}
40
	
41
	/**
42
	 * 
43
	 * @return array
44
	 */
45 1
	public function getDomains()
46
	{
47 1
		return $this->domains;
48
	}
49
	
50
	/**
51
	 * 
52
	 * @return string
53
	 */
54 2
	public function getAction()
55
	{
56 2
		return $this->action;
57
	}
58
	
59
	/**
60
	 * 
61
	 * @param string $action
62
	 * 
63
	 * @throws \InvalidArgumentException
64
	 */
65 9
	public static function validateAction($action)
66
	{
67 9
		if(!in_array($action, [DomainWhitelisting::TYPE_ADD, DomainWhitelisting::TYPE_REMOVE])) {
68 1
			throw new \InvalidArgumentException('The action must be type: "add" or "remove".');
69
		}
70 8
	}
71
	
72
	/**
73
	 * 
74
	 * @param array $domains
75
	 * 
76
	 * @throws \InvalidArgumentException
77
	 */
78 8
	public static function validateDomains($domains)
79
	{
80 8
		if(!is_array($domains)) {
81 1
			throw new \InvalidArgumentException('Domains must be a array.');
82
		}
83
		
84
		//https://developers.facebook.com/docs/messenger-platform/thread-settings/domain-whitelisting
85 7
		foreach($domains as $domain) {
86 7
			if(!preg_match('#^https:\/\/#', $domain)) {
87 1
				throw new \InvalidArgumentException('Each domain must be a "https" protocol.');
88
			}
89 7
		}
90 6
	}
91
	
92
	/**
93
	 * @inheritdoc
94
	 */
95 2
	public function jsonSerialize()
96
	{
97
		return [
98 2
			DomainWhitelisting::WHITELISTED_DOMAINS => $this->domains,
99 2
			DomainWhitelisting::DOMAIN_ACTION_TYPE => $this->action
100 2
		];
101
	}
102
}
103
104