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.
Test Failed
Pull Request — master (#33)
by
unknown
03:34
created

DomainWhitelisting::validateDomains()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.2
c 0
b 0
f 0
cc 4
eloc 6
nc 4
nop 1
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
	public function __construct($domains, $action = DomainWhitelisting::TYPE_ADD)
33
	{
34
		self::validateAction($action);
35
		self::validateDomains($domains);
36
		
37
		$this->action = $action;
38
		$this->domains = $domains;
39
	}
40
	
41
	/**
42
	 * 
43
	 * @param string $action
44
	 * 
45
	 * @throws \InvalidArgumentException
46
	 */
47
	public static function validateAction($action)
48
	{
49
		if(!in_array($action, [DomainWhitelisting::TYPE_ADD, DomainWhitelisting::TYPE_REMOVE])) {
50
			throw new \InvalidArgumentException('The action must be type: "add" or "remove".');
51
		}
52
	}
53
	
54
	/**
55
	 * 
56
	 * @param array $domains
57
	 * 
58
	 * @throws \InvalidArgumentException
59
	 */
60
	public static function validateDomains($domains)
61
	{
62
		if(!is_array($domains)) {
63
			throw new \InvalidArgumentException('$domains must be a array.');
64
		}
65
		
66
		//https://developers.facebook.com/docs/messenger-platform/thread-settings/domain-whitelisting
67
		foreach($domains as $domain) {
68
			if(!preg_match('#^https:\/\/#', $domain)) {
69
				throw new \InvalidArgumentException('Each domain must be a "https" protocol.');
70
			}
71
		}
72
	}
73
	
74
	/**
75
	 * @inheritdoc
76
	 */
77
	public function jsonSerialize()
78
	{
79
		return [
80
			DomainWhitelisting::WHITELISTED_DOMAINS => $this->domains,
81
			DomainWhitelisting::DOMAIN_ACTION_TYPE => $this->action
82
		];
83
	}
84
}
85
86