Passed
Push — master ( 138fdf...3b155c )
by Morris
21:50 queued 11s
created
lib/public/Encryption/IManager.php 1 patch
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -34,67 +34,67 @@
 block discarded – undo
34 34
  */
35 35
 interface IManager {
36 36
 
37
-	/**
38
-	 * Check if encryption is available (at least one encryption module needs to be enabled)
39
-	 *
40
-	 * @return bool true if enabled, false if not
41
-	 * @since 8.1.0
42
-	 */
43
-	public function isEnabled();
37
+    /**
38
+     * Check if encryption is available (at least one encryption module needs to be enabled)
39
+     *
40
+     * @return bool true if enabled, false if not
41
+     * @since 8.1.0
42
+     */
43
+    public function isEnabled();
44 44
 
45
-	/**
46
-	 * Registers an callback function which must return an encryption module instance
47
-	 *
48
-	 * @param string $id
49
-	 * @param string $displayName
50
-	 * @param callable $callback
51
-	 * @throws ModuleAlreadyExistsException
52
-	 * @since 8.1.0
53
-	 */
54
-	public function registerEncryptionModule($id, $displayName, callable $callback);
45
+    /**
46
+     * Registers an callback function which must return an encryption module instance
47
+     *
48
+     * @param string $id
49
+     * @param string $displayName
50
+     * @param callable $callback
51
+     * @throws ModuleAlreadyExistsException
52
+     * @since 8.1.0
53
+     */
54
+    public function registerEncryptionModule($id, $displayName, callable $callback);
55 55
 
56
-	/**
57
-	 * Unregisters an encryption module
58
-	 *
59
-	 * @param string $moduleId
60
-	 * @since 8.1.0
61
-	 */
62
-	public function unregisterEncryptionModule($moduleId);
56
+    /**
57
+     * Unregisters an encryption module
58
+     *
59
+     * @param string $moduleId
60
+     * @since 8.1.0
61
+     */
62
+    public function unregisterEncryptionModule($moduleId);
63 63
 
64
-	/**
65
-	 * get a list of all encryption modules
66
-	 *
67
-	 * @return array [id => ['id' => $id, 'displayName' => $displayName, 'callback' => callback]]
68
-	 * @since 8.1.0
69
-	 */
70
-	public function getEncryptionModules();
64
+    /**
65
+     * get a list of all encryption modules
66
+     *
67
+     * @return array [id => ['id' => $id, 'displayName' => $displayName, 'callback' => callback]]
68
+     * @since 8.1.0
69
+     */
70
+    public function getEncryptionModules();
71 71
 
72 72
 
73
-	/**
74
-	 * get a specific encryption module
75
-	 *
76
-	 * @param string $moduleId Empty to get the default module
77
-	 * @return IEncryptionModule
78
-	 * @throws ModuleDoesNotExistsException
79
-	 * @since 8.1.0
80
-	 */
81
-	public function getEncryptionModule($moduleId = '');
73
+    /**
74
+     * get a specific encryption module
75
+     *
76
+     * @param string $moduleId Empty to get the default module
77
+     * @return IEncryptionModule
78
+     * @throws ModuleDoesNotExistsException
79
+     * @since 8.1.0
80
+     */
81
+    public function getEncryptionModule($moduleId = '');
82 82
 
83
-	/**
84
-	 * get default encryption module Id
85
-	 *
86
-	 * @return string
87
-	 * @since 8.1.0
88
-	 */
89
-	public function getDefaultEncryptionModuleId();
83
+    /**
84
+     * get default encryption module Id
85
+     *
86
+     * @return string
87
+     * @since 8.1.0
88
+     */
89
+    public function getDefaultEncryptionModuleId();
90 90
 
91
-	/**
92
-	 * set default encryption module Id
93
-	 *
94
-	 * @param string $moduleId
95
-	 * @return string
96
-	 * @since 8.1.0
97
-	 */
98
-	public function setDefaultEncryptionModule($moduleId);
91
+    /**
92
+     * set default encryption module Id
93
+     *
94
+     * @param string $moduleId
95
+     * @return string
96
+     * @since 8.1.0
97
+     */
98
+    public function setDefaultEncryptionModule($moduleId);
99 99
 
100 100
 }
Please login to merge, or discard this patch.
lib/public/Encryption/Keys/IStorage.php 1 patch
Indentation   +135 added lines, -135 removed lines patch added patch discarded remove patch
@@ -33,151 +33,151 @@
 block discarded – undo
33 33
  */
34 34
 interface IStorage {
35 35
 
36
-	/**
37
-	 * get user specific key
38
-	 *
39
-	 * @param string $uid ID if the user for whom we want the key
40
-	 * @param string $keyId id of the key
41
-	 * @param string $encryptionModuleId
42
-	 *
43
-	 * @return mixed key
44
-	 * @since 8.1.0
45
-	 */
46
-	public function getUserKey($uid, $keyId, $encryptionModuleId);
36
+    /**
37
+     * get user specific key
38
+     *
39
+     * @param string $uid ID if the user for whom we want the key
40
+     * @param string $keyId id of the key
41
+     * @param string $encryptionModuleId
42
+     *
43
+     * @return mixed key
44
+     * @since 8.1.0
45
+     */
46
+    public function getUserKey($uid, $keyId, $encryptionModuleId);
47 47
 
48
-	/**
49
-	 * get file specific key
50
-	 *
51
-	 * @param string $path path to file
52
-	 * @param string $keyId id of the key
53
-	 * @param string $encryptionModuleId
54
-	 *
55
-	 * @return mixed key
56
-	 * @since 8.1.0
57
-	 */
58
-	public function getFileKey($path, $keyId, $encryptionModuleId);
48
+    /**
49
+     * get file specific key
50
+     *
51
+     * @param string $path path to file
52
+     * @param string $keyId id of the key
53
+     * @param string $encryptionModuleId
54
+     *
55
+     * @return mixed key
56
+     * @since 8.1.0
57
+     */
58
+    public function getFileKey($path, $keyId, $encryptionModuleId);
59 59
 
60
-	/**
61
-	 * get system-wide encryption keys not related to a specific user,
62
-	 * e.g something like a key for public link shares
63
-	 *
64
-	 * @param string $keyId id of the key
65
-	 * @param string $encryptionModuleId
66
-	 *
67
-	 * @return mixed key
68
-	 * @since 8.1.0
69
-	 */
70
-	public function getSystemUserKey($keyId, $encryptionModuleId);
60
+    /**
61
+     * get system-wide encryption keys not related to a specific user,
62
+     * e.g something like a key for public link shares
63
+     *
64
+     * @param string $keyId id of the key
65
+     * @param string $encryptionModuleId
66
+     *
67
+     * @return mixed key
68
+     * @since 8.1.0
69
+     */
70
+    public function getSystemUserKey($keyId, $encryptionModuleId);
71 71
 
72
-	/**
73
-	 * set user specific key
74
-	 *
75
-	 * @param string $uid ID if the user for whom we want the key
76
-	 * @param string $keyId id of the key
77
-	 * @param mixed $key
78
-	 * @param string $encryptionModuleId
79
-	 * @since 8.1.0
80
-	 */
81
-	public function setUserKey($uid, $keyId, $key, $encryptionModuleId);
72
+    /**
73
+     * set user specific key
74
+     *
75
+     * @param string $uid ID if the user for whom we want the key
76
+     * @param string $keyId id of the key
77
+     * @param mixed $key
78
+     * @param string $encryptionModuleId
79
+     * @since 8.1.0
80
+     */
81
+    public function setUserKey($uid, $keyId, $key, $encryptionModuleId);
82 82
 
83
-	/**
84
-	 * set file specific key
85
-	 *
86
-	 * @param string $path path to file
87
-	 * @param string $keyId id of the key
88
-	 * @param mixed $key
89
-	 * @param string $encryptionModuleId
90
-	 * @since 8.1.0
91
-	 */
92
-	public function setFileKey($path, $keyId, $key, $encryptionModuleId);
83
+    /**
84
+     * set file specific key
85
+     *
86
+     * @param string $path path to file
87
+     * @param string $keyId id of the key
88
+     * @param mixed $key
89
+     * @param string $encryptionModuleId
90
+     * @since 8.1.0
91
+     */
92
+    public function setFileKey($path, $keyId, $key, $encryptionModuleId);
93 93
 
94
-	/**
95
-	 * set system-wide encryption keys not related to a specific user,
96
-	 * e.g something like a key for public link shares
97
-	 *
98
-	 * @param string $keyId id of the key
99
-	 * @param mixed $key
100
-	 * @param string $encryptionModuleId
101
-	 *
102
-	 * @return mixed key
103
-	 * @since 8.1.0
104
-	 */
105
-	public function setSystemUserKey($keyId, $key, $encryptionModuleId);
94
+    /**
95
+     * set system-wide encryption keys not related to a specific user,
96
+     * e.g something like a key for public link shares
97
+     *
98
+     * @param string $keyId id of the key
99
+     * @param mixed $key
100
+     * @param string $encryptionModuleId
101
+     *
102
+     * @return mixed key
103
+     * @since 8.1.0
104
+     */
105
+    public function setSystemUserKey($keyId, $key, $encryptionModuleId);
106 106
 
107
-	/**
108
-	 * delete user specific key
109
-	 *
110
-	 * @param string $uid ID if the user for whom we want to delete the key
111
-	 * @param string $keyId id of the key
112
-	 * @param string $encryptionModuleId
113
-	 *
114
-	 * @return boolean False when the key could not be deleted
115
-	 * @since 8.1.0
116
-	 */
117
-	public function deleteUserKey($uid, $keyId, $encryptionModuleId);
107
+    /**
108
+     * delete user specific key
109
+     *
110
+     * @param string $uid ID if the user for whom we want to delete the key
111
+     * @param string $keyId id of the key
112
+     * @param string $encryptionModuleId
113
+     *
114
+     * @return boolean False when the key could not be deleted
115
+     * @since 8.1.0
116
+     */
117
+    public function deleteUserKey($uid, $keyId, $encryptionModuleId);
118 118
 
119
-	/**
120
-	 * delete file specific key
121
-	 *
122
-	 * @param string $path path to file
123
-	 * @param string $keyId id of the key
124
-	 * @param string $encryptionModuleId
125
-	 *
126
-	 * @return boolean False when the key could not be deleted
127
-	 * @since 8.1.0
128
-	 */
129
-	public function deleteFileKey($path, $keyId, $encryptionModuleId);
119
+    /**
120
+     * delete file specific key
121
+     *
122
+     * @param string $path path to file
123
+     * @param string $keyId id of the key
124
+     * @param string $encryptionModuleId
125
+     *
126
+     * @return boolean False when the key could not be deleted
127
+     * @since 8.1.0
128
+     */
129
+    public function deleteFileKey($path, $keyId, $encryptionModuleId);
130 130
 
131
-	/**
132
-	 * delete all file keys for a given file
133
-	 *
134
-	 * @param string $path to the file
135
-	 *
136
-	 * @return boolean False when the keys could not be deleted
137
-	 * @since 8.1.0
138
-	 */
139
-	public function deleteAllFileKeys($path);
131
+    /**
132
+     * delete all file keys for a given file
133
+     *
134
+     * @param string $path to the file
135
+     *
136
+     * @return boolean False when the keys could not be deleted
137
+     * @since 8.1.0
138
+     */
139
+    public function deleteAllFileKeys($path);
140 140
 
141
-	/**
142
-	 * delete system-wide encryption keys not related to a specific user,
143
-	 * e.g something like a key for public link shares
144
-	 *
145
-	 * @param string $keyId id of the key
146
-	 * @param string $encryptionModuleId
147
-	 *
148
-	 * @return boolean False when the key could not be deleted
149
-	 * @since 8.1.0
150
-	 */
151
-	public function deleteSystemUserKey($keyId, $encryptionModuleId);
141
+    /**
142
+     * delete system-wide encryption keys not related to a specific user,
143
+     * e.g something like a key for public link shares
144
+     *
145
+     * @param string $keyId id of the key
146
+     * @param string $encryptionModuleId
147
+     *
148
+     * @return boolean False when the key could not be deleted
149
+     * @since 8.1.0
150
+     */
151
+    public function deleteSystemUserKey($keyId, $encryptionModuleId);
152 152
 
153
-	/**
154
-	 * copy keys if a file was renamed
155
-	 *
156
-	 * @param string $source
157
-	 * @param string $target
158
-	 * @return boolean
159
-	 * @since 8.1.0
160
-	 */
161
-	public function renameKeys($source, $target);
153
+    /**
154
+     * copy keys if a file was renamed
155
+     *
156
+     * @param string $source
157
+     * @param string $target
158
+     * @return boolean
159
+     * @since 8.1.0
160
+     */
161
+    public function renameKeys($source, $target);
162 162
 
163
-	/**
164
-	 * move keys if a file was renamed
165
-	 *
166
-	 * @param string $source
167
-	 * @param string $target
168
-	 * @return boolean
169
-	 * @since 8.1.0
170
-	 */
171
-	public function copyKeys($source, $target);
163
+    /**
164
+     * move keys if a file was renamed
165
+     *
166
+     * @param string $source
167
+     * @param string $target
168
+     * @return boolean
169
+     * @since 8.1.0
170
+     */
171
+    public function copyKeys($source, $target);
172 172
 
173
-	/**
174
-	 * backup keys of a given encryption module
175
-	 *
176
-	 * @param string $encryptionModuleId
177
-	 * @param string $purpose
178
-	 * @param string $uid
179
-	 * @return bool
180
-	 * @since 12.0.0
181
-	 */
182
-	public function backupUserKeys($encryptionModuleId, $purpose, $uid);
173
+    /**
174
+     * backup keys of a given encryption module
175
+     *
176
+     * @param string $encryptionModuleId
177
+     * @param string $purpose
178
+     * @param string $uid
179
+     * @return bool
180
+     * @since 12.0.0
181
+     */
182
+    public function backupUserKeys($encryptionModuleId, $purpose, $uid);
183 183
 }
Please login to merge, or discard this patch.
lib/private/Authentication/LoginCredentials/Credentials.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -28,45 +28,45 @@
 block discarded – undo
28 28
 
29 29
 class Credentials implements ICredentials {
30 30
 
31
-	/** @var string */
32
-	private $uid;
31
+    /** @var string */
32
+    private $uid;
33 33
 
34
-	/** @var string */
35
-	private $loginName;
34
+    /** @var string */
35
+    private $loginName;
36 36
 
37
-	/** @var string */
38
-	private $password;
37
+    /** @var string */
38
+    private $password;
39 39
 
40
-	/**
41
-	 * @param string $uid
42
-	 * @param string $loginName
43
-	 * @param string $password
44
-	 */
45
-	public function __construct($uid, $loginName, $password) {
46
-		$this->uid = $uid;
47
-		$this->loginName = $loginName;
48
-		$this->password = $password;
49
-	}
40
+    /**
41
+     * @param string $uid
42
+     * @param string $loginName
43
+     * @param string $password
44
+     */
45
+    public function __construct($uid, $loginName, $password) {
46
+        $this->uid = $uid;
47
+        $this->loginName = $loginName;
48
+        $this->password = $password;
49
+    }
50 50
 
51
-	/**
52
-	 * @return string
53
-	 */
54
-	public function getUID() {
55
-		return $this->uid;
56
-	}
51
+    /**
52
+     * @return string
53
+     */
54
+    public function getUID() {
55
+        return $this->uid;
56
+    }
57 57
 
58
-	/**
59
-	 * @return string
60
-	 */
61
-	public function getLoginName() {
62
-		return $this->loginName;
63
-	}
58
+    /**
59
+     * @return string
60
+     */
61
+    public function getLoginName() {
62
+        return $this->loginName;
63
+    }
64 64
 
65
-	/**
66
-	 * @return string
67
-	 */
68
-	public function getPassword() {
69
-		return $this->password;
70
-	}
65
+    /**
66
+     * @return string
67
+     */
68
+    public function getPassword() {
69
+        return $this->password;
70
+    }
71 71
 
72 72
 }
Please login to merge, or discard this patch.
lib/private/Authentication/LoginCredentials/Store.php 1 patch
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -37,84 +37,84 @@
 block discarded – undo
37 37
 
38 38
 class Store implements IStore {
39 39
 
40
-	/** @var ISession */
41
-	private $session;
42
-
43
-	/** @var ILogger */
44
-	private $logger;
45
-
46
-	/** @var IProvider|null */
47
-	private $tokenProvider;
48
-
49
-	/**
50
-	 * @param ISession $session
51
-	 * @param ILogger $logger
52
-	 * @param IProvider $tokenProvider
53
-	 */
54
-	public function __construct(ISession $session, ILogger $logger, IProvider $tokenProvider = null) {
55
-		$this->session = $session;
56
-		$this->logger = $logger;
57
-		$this->tokenProvider = $tokenProvider;
58
-
59
-		Util::connectHook('OC_User', 'post_login', $this, 'authenticate');
60
-	}
61
-
62
-	/**
63
-	 * Hook listener on post login
64
-	 *
65
-	 * @param array $params
66
-	 */
67
-	public function authenticate(array $params) {
68
-		$this->session->set('login_credentials', json_encode($params));
69
-	}
70
-
71
-	/**
72
-	 * Replace the session implementation
73
-	 *
74
-	 * @param ISession $session
75
-	 */
76
-	public function setSession(ISession $session) {
77
-		$this->session = $session;
78
-	}
79
-
80
-	/**
81
-	 * @since 12
82
-	 *
83
-	 * @return ICredentials the login credentials of the current user
84
-	 * @throws CredentialsUnavailableException
85
-	 */
86
-	public function getLoginCredentials() {
87
-		if (is_null($this->tokenProvider)) {
88
-			throw new CredentialsUnavailableException();
89
-		}
90
-
91
-		$trySession = false;
92
-		try {
93
-			$sessionId = $this->session->getId();
94
-			$token = $this->tokenProvider->getToken($sessionId);
95
-
96
-			$uid = $token->getUID();
97
-			$user = $token->getLoginName();
98
-			$password = $this->tokenProvider->getPassword($token, $sessionId);
99
-
100
-			return new Credentials($uid, $user, $password);
101
-		} catch (SessionNotAvailableException $ex) {
102
-			$this->logger->debug('could not get login credentials because session is unavailable', ['app' => 'core']);
103
-		} catch (InvalidTokenException $ex) {
104
-			$this->logger->debug('could not get login credentials because the token is invalid', ['app' => 'core']);
105
-			$trySession = true;
106
-		} catch (PasswordlessTokenException $ex) {
107
-			$this->logger->debug('could not get login credentials because the token has no password', ['app' => 'core']);
108
-			$trySession = true;
109
-		}
110
-
111
-		if ($trySession && $this->session->exists('login_credentials')) {
112
-			$creds = json_decode($this->session->get('login_credentials'));
113
-			return new Credentials($creds->uid, $creds->uid, $creds->password);
114
-		}
115
-
116
-		// If we reach this line, an exception was thrown.
117
-		throw new CredentialsUnavailableException();
118
-	}
40
+    /** @var ISession */
41
+    private $session;
42
+
43
+    /** @var ILogger */
44
+    private $logger;
45
+
46
+    /** @var IProvider|null */
47
+    private $tokenProvider;
48
+
49
+    /**
50
+     * @param ISession $session
51
+     * @param ILogger $logger
52
+     * @param IProvider $tokenProvider
53
+     */
54
+    public function __construct(ISession $session, ILogger $logger, IProvider $tokenProvider = null) {
55
+        $this->session = $session;
56
+        $this->logger = $logger;
57
+        $this->tokenProvider = $tokenProvider;
58
+
59
+        Util::connectHook('OC_User', 'post_login', $this, 'authenticate');
60
+    }
61
+
62
+    /**
63
+     * Hook listener on post login
64
+     *
65
+     * @param array $params
66
+     */
67
+    public function authenticate(array $params) {
68
+        $this->session->set('login_credentials', json_encode($params));
69
+    }
70
+
71
+    /**
72
+     * Replace the session implementation
73
+     *
74
+     * @param ISession $session
75
+     */
76
+    public function setSession(ISession $session) {
77
+        $this->session = $session;
78
+    }
79
+
80
+    /**
81
+     * @since 12
82
+     *
83
+     * @return ICredentials the login credentials of the current user
84
+     * @throws CredentialsUnavailableException
85
+     */
86
+    public function getLoginCredentials() {
87
+        if (is_null($this->tokenProvider)) {
88
+            throw new CredentialsUnavailableException();
89
+        }
90
+
91
+        $trySession = false;
92
+        try {
93
+            $sessionId = $this->session->getId();
94
+            $token = $this->tokenProvider->getToken($sessionId);
95
+
96
+            $uid = $token->getUID();
97
+            $user = $token->getLoginName();
98
+            $password = $this->tokenProvider->getPassword($token, $sessionId);
99
+
100
+            return new Credentials($uid, $user, $password);
101
+        } catch (SessionNotAvailableException $ex) {
102
+            $this->logger->debug('could not get login credentials because session is unavailable', ['app' => 'core']);
103
+        } catch (InvalidTokenException $ex) {
104
+            $this->logger->debug('could not get login credentials because the token is invalid', ['app' => 'core']);
105
+            $trySession = true;
106
+        } catch (PasswordlessTokenException $ex) {
107
+            $this->logger->debug('could not get login credentials because the token has no password', ['app' => 'core']);
108
+            $trySession = true;
109
+        }
110
+
111
+        if ($trySession && $this->session->exists('login_credentials')) {
112
+            $creds = json_decode($this->session->get('login_credentials'));
113
+            return new Credentials($creds->uid, $creds->uid, $creds->password);
114
+        }
115
+
116
+        // If we reach this line, an exception was thrown.
117
+        throw new CredentialsUnavailableException();
118
+    }
119 119
 
120 120
 }
Please login to merge, or discard this patch.
lib/private/Security/CredentialsManager.php 1 patch
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -34,93 +34,93 @@
 block discarded – undo
34 34
  */
35 35
 class CredentialsManager implements ICredentialsManager {
36 36
 
37
-	const DB_TABLE = 'credentials';
37
+    const DB_TABLE = 'credentials';
38 38
 
39
-	/** @var ICrypto */
40
-	protected $crypto;
39
+    /** @var ICrypto */
40
+    protected $crypto;
41 41
 
42
-	/** @var IDBConnection */
43
-	protected $dbConnection;
42
+    /** @var IDBConnection */
43
+    protected $dbConnection;
44 44
 
45
-	/**
46
-	 * @param ICrypto $crypto
47
-	 * @param IDBConnection $dbConnection
48
-	 */
49
-	public function __construct(ICrypto $crypto, IDBConnection $dbConnection) {
50
-		$this->crypto = $crypto;
51
-		$this->dbConnection = $dbConnection;
52
-	}
45
+    /**
46
+     * @param ICrypto $crypto
47
+     * @param IDBConnection $dbConnection
48
+     */
49
+    public function __construct(ICrypto $crypto, IDBConnection $dbConnection) {
50
+        $this->crypto = $crypto;
51
+        $this->dbConnection = $dbConnection;
52
+    }
53 53
 
54
-	/**
55
-	 * Store a set of credentials
56
-	 *
57
-	 * @param string|null $userId Null for system-wide credentials
58
-	 * @param string $identifier
59
-	 * @param mixed $credentials
60
-	 */
61
-	public function store($userId, $identifier, $credentials) {
62
-		$value = $this->crypto->encrypt(json_encode($credentials));
54
+    /**
55
+     * Store a set of credentials
56
+     *
57
+     * @param string|null $userId Null for system-wide credentials
58
+     * @param string $identifier
59
+     * @param mixed $credentials
60
+     */
61
+    public function store($userId, $identifier, $credentials) {
62
+        $value = $this->crypto->encrypt(json_encode($credentials));
63 63
 
64
-		$this->dbConnection->setValues(self::DB_TABLE, [
65
-			'user' => $userId,
66
-			'identifier' => $identifier,
67
-		], [
68
-			'credentials' => $value,
69
-		]);
70
-	}
64
+        $this->dbConnection->setValues(self::DB_TABLE, [
65
+            'user' => $userId,
66
+            'identifier' => $identifier,
67
+        ], [
68
+            'credentials' => $value,
69
+        ]);
70
+    }
71 71
 
72
-	/**
73
-	 * Retrieve a set of credentials
74
-	 *
75
-	 * @param string|null $userId Null for system-wide credentials
76
-	 * @param string $identifier
77
-	 * @return mixed
78
-	 */
79
-	public function retrieve($userId, $identifier) {
80
-		$qb = $this->dbConnection->getQueryBuilder();
81
-		$qb->select('credentials')
82
-			->from(self::DB_TABLE)
83
-			->where($qb->expr()->eq('user', $qb->createNamedParameter($userId)))
84
-			->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier)))
85
-		;
86
-		$result = $qb->execute()->fetch();
72
+    /**
73
+     * Retrieve a set of credentials
74
+     *
75
+     * @param string|null $userId Null for system-wide credentials
76
+     * @param string $identifier
77
+     * @return mixed
78
+     */
79
+    public function retrieve($userId, $identifier) {
80
+        $qb = $this->dbConnection->getQueryBuilder();
81
+        $qb->select('credentials')
82
+            ->from(self::DB_TABLE)
83
+            ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId)))
84
+            ->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier)))
85
+        ;
86
+        $result = $qb->execute()->fetch();
87 87
 
88
-		if (!$result) {
89
-			return null;
90
-		}
91
-		$value = $result['credentials'];
88
+        if (!$result) {
89
+            return null;
90
+        }
91
+        $value = $result['credentials'];
92 92
 
93
-		return json_decode($this->crypto->decrypt($value), true);
94
-	}
93
+        return json_decode($this->crypto->decrypt($value), true);
94
+    }
95 95
 
96
-	/**
97
-	 * Delete a set of credentials
98
-	 *
99
-	 * @param string|null $userId Null for system-wide credentials
100
-	 * @param string $identifier
101
-	 * @return int rows removed
102
-	 */
103
-	public function delete($userId, $identifier) {
104
-		$qb = $this->dbConnection->getQueryBuilder();
105
-		$qb->delete(self::DB_TABLE)
106
-			->where($qb->expr()->eq('user', $qb->createNamedParameter($userId)))
107
-			->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier)))
108
-		;
109
-		return $qb->execute();
110
-	}
96
+    /**
97
+     * Delete a set of credentials
98
+     *
99
+     * @param string|null $userId Null for system-wide credentials
100
+     * @param string $identifier
101
+     * @return int rows removed
102
+     */
103
+    public function delete($userId, $identifier) {
104
+        $qb = $this->dbConnection->getQueryBuilder();
105
+        $qb->delete(self::DB_TABLE)
106
+            ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId)))
107
+            ->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier)))
108
+        ;
109
+        return $qb->execute();
110
+    }
111 111
 
112
-	/**
113
-	 * Erase all credentials stored for a user
114
-	 *
115
-	 * @param string $userId
116
-	 * @return int rows removed
117
-	 */
118
-	public function erase($userId) {
119
-		$qb = $this->dbConnection->getQueryBuilder();
120
-		$qb->delete(self::DB_TABLE)
121
-			->where($qb->expr()->eq('user', $qb->createNamedParameter($userId)))
122
-		;
123
-		return $qb->execute();
124
-	}
112
+    /**
113
+     * Erase all credentials stored for a user
114
+     *
115
+     * @param string $userId
116
+     * @return int rows removed
117
+     */
118
+    public function erase($userId) {
119
+        $qb = $this->dbConnection->getQueryBuilder();
120
+        $qb->delete(self::DB_TABLE)
121
+            ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId)))
122
+        ;
123
+        return $qb->execute();
124
+    }
125 125
 
126 126
 }
Please login to merge, or discard this patch.
lib/private/Security/Certificate.php 1 patch
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -27,104 +27,104 @@
 block discarded – undo
27 27
 use OCP\ICertificate;
28 28
 
29 29
 class Certificate implements ICertificate {
30
-	protected $name;
31
-
32
-	protected $commonName;
33
-
34
-	protected $organization;
35
-
36
-	protected $serial;
37
-
38
-	protected $issueDate;
39
-
40
-	protected $expireDate;
41
-
42
-	protected $issuerName;
43
-
44
-	protected $issuerOrganization;
45
-
46
-	/**
47
-	 * @param string $data base64 encoded certificate
48
-	 * @param string $name
49
-	 * @throws \Exception If the certificate could not get parsed
50
-	 */
51
-	public function __construct($data, $name) {
52
-		$this->name = $name;
53
-		$gmt = new \DateTimeZone('GMT');
54
-
55
-		// If string starts with "file://" ignore the certificate
56
-		$query = 'file://';
57
-		if(strtolower(substr($data, 0, strlen($query))) === $query) {
58
-			throw new \Exception('Certificate could not get parsed.');
59
-		}
60
-
61
-		$info = openssl_x509_parse($data);
62
-		if(!is_array($info)) {
63
-			throw new \Exception('Certificate could not get parsed.');
64
-		}
65
-
66
-		$this->commonName = isset($info['subject']['CN']) ? $info['subject']['CN'] : null;
67
-		$this->organization = isset($info['subject']['O']) ? $info['subject']['O'] : null;
68
-		$this->issueDate = new \DateTime('@' . $info['validFrom_time_t'], $gmt);
69
-		$this->expireDate = new \DateTime('@' . $info['validTo_time_t'], $gmt);
70
-		$this->issuerName = isset($info['issuer']['CN']) ? $info['issuer']['CN'] : null;
71
-		$this->issuerOrganization = isset($info['issuer']['O']) ? $info['issuer']['O'] : null;
72
-	}
73
-
74
-	/**
75
-	 * @return string
76
-	 */
77
-	public function getName() {
78
-		return $this->name;
79
-	}
80
-
81
-	/**
82
-	 * @return string|null
83
-	 */
84
-	public function getCommonName() {
85
-		return $this->commonName;
86
-	}
87
-
88
-	/**
89
-	 * @return string
90
-	 */
91
-	public function getOrganization() {
92
-		return $this->organization;
93
-	}
94
-
95
-	/**
96
-	 * @return \DateTime
97
-	 */
98
-	public function getIssueDate() {
99
-		return $this->issueDate;
100
-	}
101
-
102
-	/**
103
-	 * @return \DateTime
104
-	 */
105
-	public function getExpireDate() {
106
-		return $this->expireDate;
107
-	}
108
-
109
-	/**
110
-	 * @return bool
111
-	 */
112
-	public function isExpired() {
113
-		$now = new \DateTime();
114
-		return $this->issueDate > $now or $now > $this->expireDate;
115
-	}
116
-
117
-	/**
118
-	 * @return string|null
119
-	 */
120
-	public function getIssuerName() {
121
-		return $this->issuerName;
122
-	}
123
-
124
-	/**
125
-	 * @return string|null
126
-	 */
127
-	public function getIssuerOrganization() {
128
-		return $this->issuerOrganization;
129
-	}
30
+    protected $name;
31
+
32
+    protected $commonName;
33
+
34
+    protected $organization;
35
+
36
+    protected $serial;
37
+
38
+    protected $issueDate;
39
+
40
+    protected $expireDate;
41
+
42
+    protected $issuerName;
43
+
44
+    protected $issuerOrganization;
45
+
46
+    /**
47
+     * @param string $data base64 encoded certificate
48
+     * @param string $name
49
+     * @throws \Exception If the certificate could not get parsed
50
+     */
51
+    public function __construct($data, $name) {
52
+        $this->name = $name;
53
+        $gmt = new \DateTimeZone('GMT');
54
+
55
+        // If string starts with "file://" ignore the certificate
56
+        $query = 'file://';
57
+        if(strtolower(substr($data, 0, strlen($query))) === $query) {
58
+            throw new \Exception('Certificate could not get parsed.');
59
+        }
60
+
61
+        $info = openssl_x509_parse($data);
62
+        if(!is_array($info)) {
63
+            throw new \Exception('Certificate could not get parsed.');
64
+        }
65
+
66
+        $this->commonName = isset($info['subject']['CN']) ? $info['subject']['CN'] : null;
67
+        $this->organization = isset($info['subject']['O']) ? $info['subject']['O'] : null;
68
+        $this->issueDate = new \DateTime('@' . $info['validFrom_time_t'], $gmt);
69
+        $this->expireDate = new \DateTime('@' . $info['validTo_time_t'], $gmt);
70
+        $this->issuerName = isset($info['issuer']['CN']) ? $info['issuer']['CN'] : null;
71
+        $this->issuerOrganization = isset($info['issuer']['O']) ? $info['issuer']['O'] : null;
72
+    }
73
+
74
+    /**
75
+     * @return string
76
+     */
77
+    public function getName() {
78
+        return $this->name;
79
+    }
80
+
81
+    /**
82
+     * @return string|null
83
+     */
84
+    public function getCommonName() {
85
+        return $this->commonName;
86
+    }
87
+
88
+    /**
89
+     * @return string
90
+     */
91
+    public function getOrganization() {
92
+        return $this->organization;
93
+    }
94
+
95
+    /**
96
+     * @return \DateTime
97
+     */
98
+    public function getIssueDate() {
99
+        return $this->issueDate;
100
+    }
101
+
102
+    /**
103
+     * @return \DateTime
104
+     */
105
+    public function getExpireDate() {
106
+        return $this->expireDate;
107
+    }
108
+
109
+    /**
110
+     * @return bool
111
+     */
112
+    public function isExpired() {
113
+        $now = new \DateTime();
114
+        return $this->issueDate > $now or $now > $this->expireDate;
115
+    }
116
+
117
+    /**
118
+     * @return string|null
119
+     */
120
+    public function getIssuerName() {
121
+        return $this->issuerName;
122
+    }
123
+
124
+    /**
125
+     * @return string|null
126
+     */
127
+    public function getIssuerOrganization() {
128
+        return $this->issuerOrganization;
129
+    }
130 130
 }
Please login to merge, or discard this patch.
lib/private/Log/ErrorHandler.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -28,74 +28,74 @@
 block discarded – undo
28 28
 use OCP\ILogger;
29 29
 
30 30
 class ErrorHandler {
31
-	/** @var ILogger */
32
-	private static $logger;
31
+    /** @var ILogger */
32
+    private static $logger;
33 33
 
34
-	/**
35
-	 * remove password in URLs
36
-	 * @param string $msg
37
-	 * @return string
38
-	 */
39
-	protected static function removePassword($msg) {
40
-		return preg_replace('/\/\/(.*):(.*)@/', '//xxx:xxx@', $msg);
41
-	}
34
+    /**
35
+     * remove password in URLs
36
+     * @param string $msg
37
+     * @return string
38
+     */
39
+    protected static function removePassword($msg) {
40
+        return preg_replace('/\/\/(.*):(.*)@/', '//xxx:xxx@', $msg);
41
+    }
42 42
 
43
-	public static function register($debug=false) {
44
-		$handler = new ErrorHandler();
43
+    public static function register($debug=false) {
44
+        $handler = new ErrorHandler();
45 45
 
46
-		if ($debug) {
47
-			set_error_handler(array($handler, 'onAll'), E_ALL);
48
-			if (\OC::$CLI) {
49
-				set_exception_handler(array('OC_Template', 'printExceptionErrorPage'));
50
-			}
51
-		} else {
52
-			set_error_handler(array($handler, 'onError'));
53
-		}
54
-		register_shutdown_function(array($handler, 'onShutdown'));
55
-		set_exception_handler(array($handler, 'onException'));
56
-	}
46
+        if ($debug) {
47
+            set_error_handler(array($handler, 'onAll'), E_ALL);
48
+            if (\OC::$CLI) {
49
+                set_exception_handler(array('OC_Template', 'printExceptionErrorPage'));
50
+            }
51
+        } else {
52
+            set_error_handler(array($handler, 'onError'));
53
+        }
54
+        register_shutdown_function(array($handler, 'onShutdown'));
55
+        set_exception_handler(array($handler, 'onException'));
56
+    }
57 57
 
58
-	public static function setLogger(ILogger $logger) {
59
-		self::$logger = $logger;
60
-	}
58
+    public static function setLogger(ILogger $logger) {
59
+        self::$logger = $logger;
60
+    }
61 61
 
62
-	//Fatal errors handler
63
-	public static function onShutdown() {
64
-		$error = error_get_last();
65
-		if($error && self::$logger) {
66
-			//ob_end_clean();
67
-			$msg = $error['message'] . ' at ' . $error['file'] . '#' . $error['line'];
68
-			self::$logger->critical(self::removePassword($msg), array('app' => 'PHP'));
69
-		}
70
-	}
62
+    //Fatal errors handler
63
+    public static function onShutdown() {
64
+        $error = error_get_last();
65
+        if($error && self::$logger) {
66
+            //ob_end_clean();
67
+            $msg = $error['message'] . ' at ' . $error['file'] . '#' . $error['line'];
68
+            self::$logger->critical(self::removePassword($msg), array('app' => 'PHP'));
69
+        }
70
+    }
71 71
 
72
-	/**
73
-	 * 	Uncaught exception handler
74
-	 *
75
-	 * @param \Exception $exception
76
-	 */
77
-	public static function onException($exception) {
78
-		$class = get_class($exception);
79
-		$msg = $exception->getMessage();
80
-		$msg = "$class: $msg at " . $exception->getFile() . '#' . $exception->getLine();
81
-		self::$logger->critical(self::removePassword($msg), ['app' => 'PHP']);
82
-	}
72
+    /**
73
+     * 	Uncaught exception handler
74
+     *
75
+     * @param \Exception $exception
76
+     */
77
+    public static function onException($exception) {
78
+        $class = get_class($exception);
79
+        $msg = $exception->getMessage();
80
+        $msg = "$class: $msg at " . $exception->getFile() . '#' . $exception->getLine();
81
+        self::$logger->critical(self::removePassword($msg), ['app' => 'PHP']);
82
+    }
83 83
 
84
-	//Recoverable errors handler
85
-	public static function onError($number, $message, $file, $line) {
86
-		if (error_reporting() === 0) {
87
-			return;
88
-		}
89
-		$msg = $message . ' at ' . $file . '#' . $line;
90
-		self::$logger->error(self::removePassword($msg), array('app' => 'PHP'));
84
+    //Recoverable errors handler
85
+    public static function onError($number, $message, $file, $line) {
86
+        if (error_reporting() === 0) {
87
+            return;
88
+        }
89
+        $msg = $message . ' at ' . $file . '#' . $line;
90
+        self::$logger->error(self::removePassword($msg), array('app' => 'PHP'));
91 91
 
92
-	}
92
+    }
93 93
 
94
-	//Recoverable handler which catch all errors, warnings and notices
95
-	public static function onAll($number, $message, $file, $line) {
96
-		$msg = $message . ' at ' . $file . '#' . $line;
97
-		self::$logger->debug(self::removePassword($msg), array('app' => 'PHP'));
94
+    //Recoverable handler which catch all errors, warnings and notices
95
+    public static function onAll($number, $message, $file, $line) {
96
+        $msg = $message . ' at ' . $file . '#' . $line;
97
+        self::$logger->debug(self::removePassword($msg), array('app' => 'PHP'));
98 98
 
99
-	}
99
+    }
100 100
 
101 101
 }
Please login to merge, or discard this patch.
lib/private/Notification/Notification.php 1 patch
Indentation   +551 added lines, -551 removed lines patch added patch discarded remove patch
@@ -31,555 +31,555 @@
 block discarded – undo
31 31
 
32 32
 class Notification implements INotification {
33 33
 
34
-	/** @var IValidator */
35
-	protected $richValidator;
36
-
37
-	/** @var string */
38
-	protected $app;
39
-
40
-	/** @var string */
41
-	protected $user;
42
-
43
-	/** @var \DateTime */
44
-	protected $dateTime;
45
-
46
-	/** @var string */
47
-	protected $objectType;
48
-
49
-	/** @var string */
50
-	protected $objectId;
51
-
52
-	/** @var string */
53
-	protected $subject;
54
-
55
-	/** @var array */
56
-	protected $subjectParameters;
57
-
58
-	/** @var string */
59
-	protected $subjectParsed;
60
-
61
-	/** @var string */
62
-	protected $subjectRich;
63
-
64
-	/** @var array */
65
-	protected $subjectRichParameters;
66
-
67
-	/** @var string */
68
-	protected $message;
69
-
70
-	/** @var array */
71
-	protected $messageParameters;
72
-
73
-	/** @var string */
74
-	protected $messageParsed;
75
-
76
-	/** @var string */
77
-	protected $messageRich;
78
-
79
-	/** @var array */
80
-	protected $messageRichParameters;
81
-
82
-	/** @var string */
83
-	protected $link;
84
-
85
-	/** @var string */
86
-	protected $icon;
87
-
88
-	/** @var array */
89
-	protected $actions;
90
-
91
-	/** @var array */
92
-	protected $actionsParsed;
93
-
94
-	/** @var bool */
95
-	protected $hasPrimaryAction;
96
-
97
-	/** @var bool */
98
-	protected $hasPrimaryParsedAction;
99
-
100
-	/**
101
-	 * Constructor
102
-	 *
103
-	 * @param IValidator $richValidator
104
-	 */
105
-	public function __construct(IValidator $richValidator) {
106
-		$this->richValidator = $richValidator;
107
-		$this->app = '';
108
-		$this->user = '';
109
-		$this->dateTime = new \DateTime();
110
-		$this->dateTime->setTimestamp(0);
111
-		$this->objectType = '';
112
-		$this->objectId = '';
113
-		$this->subject = '';
114
-		$this->subjectParameters = [];
115
-		$this->subjectParsed = '';
116
-		$this->subjectRich = '';
117
-		$this->subjectRichParameters = [];
118
-		$this->message = '';
119
-		$this->messageParameters = [];
120
-		$this->messageParsed = '';
121
-		$this->messageRich = '';
122
-		$this->messageRichParameters = [];
123
-		$this->link = '';
124
-		$this->icon = '';
125
-		$this->actions = [];
126
-		$this->actionsParsed = [];
127
-	}
128
-
129
-	/**
130
-	 * @param string $app
131
-	 * @return $this
132
-	 * @throws \InvalidArgumentException if the app id is invalid
133
-	 * @since 8.2.0
134
-	 */
135
-	public function setApp($app) {
136
-		if (!is_string($app) || $app === '' || isset($app[32])) {
137
-			throw new \InvalidArgumentException('The given app name is invalid');
138
-		}
139
-		$this->app = $app;
140
-		return $this;
141
-	}
142
-
143
-	/**
144
-	 * @return string
145
-	 * @since 8.2.0
146
-	 */
147
-	public function getApp() {
148
-		return $this->app;
149
-	}
150
-
151
-	/**
152
-	 * @param string $user
153
-	 * @return $this
154
-	 * @throws \InvalidArgumentException if the user id is invalid
155
-	 * @since 8.2.0
156
-	 */
157
-	public function setUser($user) {
158
-		if (!is_string($user) || $user === '' || isset($user[64])) {
159
-			throw new \InvalidArgumentException('The given user id is invalid');
160
-		}
161
-		$this->user = $user;
162
-		return $this;
163
-	}
164
-
165
-	/**
166
-	 * @return string
167
-	 * @since 8.2.0
168
-	 */
169
-	public function getUser() {
170
-		return $this->user;
171
-	}
172
-
173
-	/**
174
-	 * @param \DateTime $dateTime
175
-	 * @return $this
176
-	 * @throws \InvalidArgumentException if the $dateTime is invalid
177
-	 * @since 9.0.0
178
-	 */
179
-	public function setDateTime(\DateTime $dateTime) {
180
-		if ($dateTime->getTimestamp() === 0) {
181
-			throw new \InvalidArgumentException('The given date time is invalid');
182
-		}
183
-		$this->dateTime = $dateTime;
184
-		return $this;
185
-	}
186
-
187
-	/**
188
-	 * @return \DateTime
189
-	 * @since 9.0.0
190
-	 */
191
-	public function getDateTime() {
192
-		return $this->dateTime;
193
-	}
194
-
195
-	/**
196
-	 * @param string $type
197
-	 * @param string $id
198
-	 * @return $this
199
-	 * @throws \InvalidArgumentException if the object type or id is invalid
200
-	 * @since 8.2.0 - 9.0.0: Type of $id changed to string
201
-	 */
202
-	public function setObject($type, $id) {
203
-		if (!is_string($type) || $type === '' || isset($type[64])) {
204
-			throw new \InvalidArgumentException('The given object type is invalid');
205
-		}
206
-		$this->objectType = $type;
207
-
208
-		if (!is_int($id) && (!is_string($id) || $id === '' || isset($id[64]))) {
209
-			throw new \InvalidArgumentException('The given object id is invalid');
210
-		}
211
-		$this->objectId = (string) $id;
212
-		return $this;
213
-	}
214
-
215
-	/**
216
-	 * @return string
217
-	 * @since 8.2.0
218
-	 */
219
-	public function getObjectType() {
220
-		return $this->objectType;
221
-	}
222
-
223
-	/**
224
-	 * @return string
225
-	 * @since 8.2.0 - 9.0.0: Return type changed to string
226
-	 */
227
-	public function getObjectId() {
228
-		return $this->objectId;
229
-	}
230
-
231
-	/**
232
-	 * @param string $subject
233
-	 * @param array $parameters
234
-	 * @return $this
235
-	 * @throws \InvalidArgumentException if the subject or parameters are invalid
236
-	 * @since 8.2.0
237
-	 */
238
-	public function setSubject($subject, array $parameters = []) {
239
-		if (!is_string($subject) || $subject === '' || isset($subject[64])) {
240
-			throw new \InvalidArgumentException('The given subject is invalid');
241
-		}
242
-
243
-		$this->subject = $subject;
244
-		$this->subjectParameters = $parameters;
245
-
246
-		return $this;
247
-	}
248
-
249
-	/**
250
-	 * @return string
251
-	 * @since 8.2.0
252
-	 */
253
-	public function getSubject() {
254
-		return $this->subject;
255
-	}
256
-
257
-	/**
258
-	 * @return string[]
259
-	 * @since 8.2.0
260
-	 */
261
-	public function getSubjectParameters() {
262
-		return $this->subjectParameters;
263
-	}
264
-
265
-	/**
266
-	 * @param string $subject
267
-	 * @return $this
268
-	 * @throws \InvalidArgumentException if the subject is invalid
269
-	 * @since 8.2.0
270
-	 */
271
-	public function setParsedSubject($subject) {
272
-		if (!is_string($subject) || $subject === '') {
273
-			throw new \InvalidArgumentException('The given parsed subject is invalid');
274
-		}
275
-		$this->subjectParsed = $subject;
276
-		return $this;
277
-	}
278
-
279
-	/**
280
-	 * @return string
281
-	 * @since 8.2.0
282
-	 */
283
-	public function getParsedSubject() {
284
-		return $this->subjectParsed;
285
-	}
286
-
287
-	/**
288
-	 * @param string $subject
289
-	 * @param array $parameters
290
-	 * @return $this
291
-	 * @throws \InvalidArgumentException if the subject or parameters are invalid
292
-	 * @since 11.0.0
293
-	 */
294
-	public function setRichSubject($subject, array $parameters = []) {
295
-		if (!is_string($subject) || $subject === '') {
296
-			throw new \InvalidArgumentException('The given parsed subject is invalid');
297
-		}
298
-
299
-		$this->subjectRich = $subject;
300
-		$this->subjectRichParameters = $parameters;
301
-
302
-		return $this;
303
-	}
304
-
305
-	/**
306
-	 * @return string
307
-	 * @since 11.0.0
308
-	 */
309
-	public function getRichSubject() {
310
-		return $this->subjectRich;
311
-	}
312
-
313
-	/**
314
-	 * @return array[]
315
-	 * @since 11.0.0
316
-	 */
317
-	public function getRichSubjectParameters() {
318
-		return $this->subjectRichParameters;
319
-	}
320
-
321
-	/**
322
-	 * @param string $message
323
-	 * @param array $parameters
324
-	 * @return $this
325
-	 * @throws \InvalidArgumentException if the message or parameters are invalid
326
-	 * @since 8.2.0
327
-	 */
328
-	public function setMessage($message, array $parameters = []) {
329
-		if (!is_string($message) || $message === '' || isset($message[64])) {
330
-			throw new \InvalidArgumentException('The given message is invalid');
331
-		}
332
-
333
-		$this->message = $message;
334
-		$this->messageParameters = $parameters;
335
-
336
-		return $this;
337
-	}
338
-
339
-	/**
340
-	 * @return string
341
-	 * @since 8.2.0
342
-	 */
343
-	public function getMessage() {
344
-		return $this->message;
345
-	}
346
-
347
-	/**
348
-	 * @return string[]
349
-	 * @since 8.2.0
350
-	 */
351
-	public function getMessageParameters() {
352
-		return $this->messageParameters;
353
-	}
354
-
355
-	/**
356
-	 * @param string $message
357
-	 * @return $this
358
-	 * @throws \InvalidArgumentException if the message is invalid
359
-	 * @since 8.2.0
360
-	 */
361
-	public function setParsedMessage($message) {
362
-		if (!is_string($message) || $message === '') {
363
-			throw new \InvalidArgumentException('The given parsed message is invalid');
364
-		}
365
-		$this->messageParsed = $message;
366
-		return $this;
367
-	}
368
-
369
-	/**
370
-	 * @return string
371
-	 * @since 8.2.0
372
-	 */
373
-	public function getParsedMessage() {
374
-		return $this->messageParsed;
375
-	}
376
-
377
-	/**
378
-	 * @param string $message
379
-	 * @param array $parameters
380
-	 * @return $this
381
-	 * @throws \InvalidArgumentException if the message or parameters are invalid
382
-	 * @since 11.0.0
383
-	 */
384
-	public function setRichMessage($message, array $parameters = []) {
385
-		if (!is_string($message) || $message === '') {
386
-			throw new \InvalidArgumentException('The given parsed message is invalid');
387
-		}
388
-
389
-		$this->messageRich = $message;
390
-		$this->messageRichParameters = $parameters;
391
-
392
-		return $this;
393
-	}
394
-
395
-	/**
396
-	 * @return string
397
-	 * @since 11.0.0
398
-	 */
399
-	public function getRichMessage() {
400
-		return $this->messageRich;
401
-	}
402
-
403
-	/**
404
-	 * @return array[]
405
-	 * @since 11.0.0
406
-	 */
407
-	public function getRichMessageParameters() {
408
-		return $this->messageRichParameters;
409
-	}
410
-
411
-	/**
412
-	 * @param string $link
413
-	 * @return $this
414
-	 * @throws \InvalidArgumentException if the link is invalid
415
-	 * @since 8.2.0
416
-	 */
417
-	public function setLink($link) {
418
-		if (!is_string($link) || $link === '' || isset($link[4000])) {
419
-			throw new \InvalidArgumentException('The given link is invalid');
420
-		}
421
-		$this->link = $link;
422
-		return $this;
423
-	}
424
-
425
-	/**
426
-	 * @return string
427
-	 * @since 8.2.0
428
-	 */
429
-	public function getLink() {
430
-		return $this->link;
431
-	}
432
-
433
-	/**
434
-	 * @param string $icon
435
-	 * @return $this
436
-	 * @throws \InvalidArgumentException if the icon is invalid
437
-	 * @since 11.0.0
438
-	 */
439
-	public function setIcon($icon) {
440
-		if (!is_string($icon) || $icon === '' || isset($icon[4000])) {
441
-			throw new \InvalidArgumentException('The given icon is invalid');
442
-		}
443
-		$this->icon = $icon;
444
-		return $this;
445
-	}
446
-
447
-	/**
448
-	 * @return string
449
-	 * @since 11.0.0
450
-	 */
451
-	public function getIcon() {
452
-		return $this->icon;
453
-	}
454
-
455
-	/**
456
-	 * @return IAction
457
-	 * @since 8.2.0
458
-	 */
459
-	public function createAction() {
460
-		return new Action();
461
-	}
462
-
463
-	/**
464
-	 * @param IAction $action
465
-	 * @return $this
466
-	 * @throws \InvalidArgumentException if the action is invalid
467
-	 * @since 8.2.0
468
-	 */
469
-	public function addAction(IAction $action) {
470
-		if (!$action->isValid()) {
471
-			throw new \InvalidArgumentException('The given action is invalid');
472
-		}
473
-
474
-		if ($action->isPrimary()) {
475
-			if ($this->hasPrimaryAction) {
476
-				throw new \InvalidArgumentException('The notification already has a primary action');
477
-			}
478
-
479
-			$this->hasPrimaryAction = true;
480
-		}
481
-
482
-		$this->actions[] = $action;
483
-		return $this;
484
-	}
485
-
486
-	/**
487
-	 * @return IAction[]
488
-	 * @since 8.2.0
489
-	 */
490
-	public function getActions() {
491
-		return $this->actions;
492
-	}
493
-
494
-	/**
495
-	 * @param IAction $action
496
-	 * @return $this
497
-	 * @throws \InvalidArgumentException if the action is invalid
498
-	 * @since 8.2.0
499
-	 */
500
-	public function addParsedAction(IAction $action) {
501
-		if (!$action->isValidParsed()) {
502
-			throw new \InvalidArgumentException('The given parsed action is invalid');
503
-		}
504
-
505
-		if ($action->isPrimary()) {
506
-			if ($this->hasPrimaryParsedAction) {
507
-				throw new \InvalidArgumentException('The notification already has a primary action');
508
-			}
509
-
510
-			$this->hasPrimaryParsedAction = true;
511
-
512
-			// Make sure the primary action is always the first one
513
-			array_unshift($this->actionsParsed, $action);
514
-		} else {
515
-			$this->actionsParsed[] = $action;
516
-		}
517
-
518
-		return $this;
519
-	}
520
-
521
-	/**
522
-	 * @return IAction[]
523
-	 * @since 8.2.0
524
-	 */
525
-	public function getParsedActions() {
526
-		return $this->actionsParsed;
527
-	}
528
-
529
-	/**
530
-	 * @return bool
531
-	 * @since 8.2.0
532
-	 */
533
-	public function isValid() {
534
-		return
535
-			$this->isValidCommon()
536
-			&&
537
-			$this->getSubject() !== ''
538
-		;
539
-	}
540
-
541
-	/**
542
-	 * @return bool
543
-	 * @since 8.2.0
544
-	 */
545
-	public function isValidParsed() {
546
-		if ($this->getRichSubject() !== '' || !empty($this->getRichSubjectParameters())) {
547
-			try {
548
-				$this->richValidator->validate($this->getRichSubject(), $this->getRichSubjectParameters());
549
-			} catch (InvalidObjectExeption $e) {
550
-				return false;
551
-			}
552
-		}
553
-
554
-		if ($this->getRichMessage() !== '' || !empty($this->getRichMessageParameters())) {
555
-			try {
556
-				$this->richValidator->validate($this->getRichMessage(), $this->getRichMessageParameters());
557
-			} catch (InvalidObjectExeption $e) {
558
-				return false;
559
-			}
560
-		}
561
-
562
-		return
563
-			$this->isValidCommon()
564
-			&&
565
-			$this->getParsedSubject() !== ''
566
-		;
567
-	}
568
-
569
-	/**
570
-	 * @return bool
571
-	 */
572
-	protected function isValidCommon() {
573
-		return
574
-			$this->getApp() !== ''
575
-			&&
576
-			$this->getUser() !== ''
577
-			&&
578
-			$this->getDateTime()->getTimestamp() !== 0
579
-			&&
580
-			$this->getObjectType() !== ''
581
-			&&
582
-			$this->getObjectId() !== ''
583
-		;
584
-	}
34
+    /** @var IValidator */
35
+    protected $richValidator;
36
+
37
+    /** @var string */
38
+    protected $app;
39
+
40
+    /** @var string */
41
+    protected $user;
42
+
43
+    /** @var \DateTime */
44
+    protected $dateTime;
45
+
46
+    /** @var string */
47
+    protected $objectType;
48
+
49
+    /** @var string */
50
+    protected $objectId;
51
+
52
+    /** @var string */
53
+    protected $subject;
54
+
55
+    /** @var array */
56
+    protected $subjectParameters;
57
+
58
+    /** @var string */
59
+    protected $subjectParsed;
60
+
61
+    /** @var string */
62
+    protected $subjectRich;
63
+
64
+    /** @var array */
65
+    protected $subjectRichParameters;
66
+
67
+    /** @var string */
68
+    protected $message;
69
+
70
+    /** @var array */
71
+    protected $messageParameters;
72
+
73
+    /** @var string */
74
+    protected $messageParsed;
75
+
76
+    /** @var string */
77
+    protected $messageRich;
78
+
79
+    /** @var array */
80
+    protected $messageRichParameters;
81
+
82
+    /** @var string */
83
+    protected $link;
84
+
85
+    /** @var string */
86
+    protected $icon;
87
+
88
+    /** @var array */
89
+    protected $actions;
90
+
91
+    /** @var array */
92
+    protected $actionsParsed;
93
+
94
+    /** @var bool */
95
+    protected $hasPrimaryAction;
96
+
97
+    /** @var bool */
98
+    protected $hasPrimaryParsedAction;
99
+
100
+    /**
101
+     * Constructor
102
+     *
103
+     * @param IValidator $richValidator
104
+     */
105
+    public function __construct(IValidator $richValidator) {
106
+        $this->richValidator = $richValidator;
107
+        $this->app = '';
108
+        $this->user = '';
109
+        $this->dateTime = new \DateTime();
110
+        $this->dateTime->setTimestamp(0);
111
+        $this->objectType = '';
112
+        $this->objectId = '';
113
+        $this->subject = '';
114
+        $this->subjectParameters = [];
115
+        $this->subjectParsed = '';
116
+        $this->subjectRich = '';
117
+        $this->subjectRichParameters = [];
118
+        $this->message = '';
119
+        $this->messageParameters = [];
120
+        $this->messageParsed = '';
121
+        $this->messageRich = '';
122
+        $this->messageRichParameters = [];
123
+        $this->link = '';
124
+        $this->icon = '';
125
+        $this->actions = [];
126
+        $this->actionsParsed = [];
127
+    }
128
+
129
+    /**
130
+     * @param string $app
131
+     * @return $this
132
+     * @throws \InvalidArgumentException if the app id is invalid
133
+     * @since 8.2.0
134
+     */
135
+    public function setApp($app) {
136
+        if (!is_string($app) || $app === '' || isset($app[32])) {
137
+            throw new \InvalidArgumentException('The given app name is invalid');
138
+        }
139
+        $this->app = $app;
140
+        return $this;
141
+    }
142
+
143
+    /**
144
+     * @return string
145
+     * @since 8.2.0
146
+     */
147
+    public function getApp() {
148
+        return $this->app;
149
+    }
150
+
151
+    /**
152
+     * @param string $user
153
+     * @return $this
154
+     * @throws \InvalidArgumentException if the user id is invalid
155
+     * @since 8.2.0
156
+     */
157
+    public function setUser($user) {
158
+        if (!is_string($user) || $user === '' || isset($user[64])) {
159
+            throw new \InvalidArgumentException('The given user id is invalid');
160
+        }
161
+        $this->user = $user;
162
+        return $this;
163
+    }
164
+
165
+    /**
166
+     * @return string
167
+     * @since 8.2.0
168
+     */
169
+    public function getUser() {
170
+        return $this->user;
171
+    }
172
+
173
+    /**
174
+     * @param \DateTime $dateTime
175
+     * @return $this
176
+     * @throws \InvalidArgumentException if the $dateTime is invalid
177
+     * @since 9.0.0
178
+     */
179
+    public function setDateTime(\DateTime $dateTime) {
180
+        if ($dateTime->getTimestamp() === 0) {
181
+            throw new \InvalidArgumentException('The given date time is invalid');
182
+        }
183
+        $this->dateTime = $dateTime;
184
+        return $this;
185
+    }
186
+
187
+    /**
188
+     * @return \DateTime
189
+     * @since 9.0.0
190
+     */
191
+    public function getDateTime() {
192
+        return $this->dateTime;
193
+    }
194
+
195
+    /**
196
+     * @param string $type
197
+     * @param string $id
198
+     * @return $this
199
+     * @throws \InvalidArgumentException if the object type or id is invalid
200
+     * @since 8.2.0 - 9.0.0: Type of $id changed to string
201
+     */
202
+    public function setObject($type, $id) {
203
+        if (!is_string($type) || $type === '' || isset($type[64])) {
204
+            throw new \InvalidArgumentException('The given object type is invalid');
205
+        }
206
+        $this->objectType = $type;
207
+
208
+        if (!is_int($id) && (!is_string($id) || $id === '' || isset($id[64]))) {
209
+            throw new \InvalidArgumentException('The given object id is invalid');
210
+        }
211
+        $this->objectId = (string) $id;
212
+        return $this;
213
+    }
214
+
215
+    /**
216
+     * @return string
217
+     * @since 8.2.0
218
+     */
219
+    public function getObjectType() {
220
+        return $this->objectType;
221
+    }
222
+
223
+    /**
224
+     * @return string
225
+     * @since 8.2.0 - 9.0.0: Return type changed to string
226
+     */
227
+    public function getObjectId() {
228
+        return $this->objectId;
229
+    }
230
+
231
+    /**
232
+     * @param string $subject
233
+     * @param array $parameters
234
+     * @return $this
235
+     * @throws \InvalidArgumentException if the subject or parameters are invalid
236
+     * @since 8.2.0
237
+     */
238
+    public function setSubject($subject, array $parameters = []) {
239
+        if (!is_string($subject) || $subject === '' || isset($subject[64])) {
240
+            throw new \InvalidArgumentException('The given subject is invalid');
241
+        }
242
+
243
+        $this->subject = $subject;
244
+        $this->subjectParameters = $parameters;
245
+
246
+        return $this;
247
+    }
248
+
249
+    /**
250
+     * @return string
251
+     * @since 8.2.0
252
+     */
253
+    public function getSubject() {
254
+        return $this->subject;
255
+    }
256
+
257
+    /**
258
+     * @return string[]
259
+     * @since 8.2.0
260
+     */
261
+    public function getSubjectParameters() {
262
+        return $this->subjectParameters;
263
+    }
264
+
265
+    /**
266
+     * @param string $subject
267
+     * @return $this
268
+     * @throws \InvalidArgumentException if the subject is invalid
269
+     * @since 8.2.0
270
+     */
271
+    public function setParsedSubject($subject) {
272
+        if (!is_string($subject) || $subject === '') {
273
+            throw new \InvalidArgumentException('The given parsed subject is invalid');
274
+        }
275
+        $this->subjectParsed = $subject;
276
+        return $this;
277
+    }
278
+
279
+    /**
280
+     * @return string
281
+     * @since 8.2.0
282
+     */
283
+    public function getParsedSubject() {
284
+        return $this->subjectParsed;
285
+    }
286
+
287
+    /**
288
+     * @param string $subject
289
+     * @param array $parameters
290
+     * @return $this
291
+     * @throws \InvalidArgumentException if the subject or parameters are invalid
292
+     * @since 11.0.0
293
+     */
294
+    public function setRichSubject($subject, array $parameters = []) {
295
+        if (!is_string($subject) || $subject === '') {
296
+            throw new \InvalidArgumentException('The given parsed subject is invalid');
297
+        }
298
+
299
+        $this->subjectRich = $subject;
300
+        $this->subjectRichParameters = $parameters;
301
+
302
+        return $this;
303
+    }
304
+
305
+    /**
306
+     * @return string
307
+     * @since 11.0.0
308
+     */
309
+    public function getRichSubject() {
310
+        return $this->subjectRich;
311
+    }
312
+
313
+    /**
314
+     * @return array[]
315
+     * @since 11.0.0
316
+     */
317
+    public function getRichSubjectParameters() {
318
+        return $this->subjectRichParameters;
319
+    }
320
+
321
+    /**
322
+     * @param string $message
323
+     * @param array $parameters
324
+     * @return $this
325
+     * @throws \InvalidArgumentException if the message or parameters are invalid
326
+     * @since 8.2.0
327
+     */
328
+    public function setMessage($message, array $parameters = []) {
329
+        if (!is_string($message) || $message === '' || isset($message[64])) {
330
+            throw new \InvalidArgumentException('The given message is invalid');
331
+        }
332
+
333
+        $this->message = $message;
334
+        $this->messageParameters = $parameters;
335
+
336
+        return $this;
337
+    }
338
+
339
+    /**
340
+     * @return string
341
+     * @since 8.2.0
342
+     */
343
+    public function getMessage() {
344
+        return $this->message;
345
+    }
346
+
347
+    /**
348
+     * @return string[]
349
+     * @since 8.2.0
350
+     */
351
+    public function getMessageParameters() {
352
+        return $this->messageParameters;
353
+    }
354
+
355
+    /**
356
+     * @param string $message
357
+     * @return $this
358
+     * @throws \InvalidArgumentException if the message is invalid
359
+     * @since 8.2.0
360
+     */
361
+    public function setParsedMessage($message) {
362
+        if (!is_string($message) || $message === '') {
363
+            throw new \InvalidArgumentException('The given parsed message is invalid');
364
+        }
365
+        $this->messageParsed = $message;
366
+        return $this;
367
+    }
368
+
369
+    /**
370
+     * @return string
371
+     * @since 8.2.0
372
+     */
373
+    public function getParsedMessage() {
374
+        return $this->messageParsed;
375
+    }
376
+
377
+    /**
378
+     * @param string $message
379
+     * @param array $parameters
380
+     * @return $this
381
+     * @throws \InvalidArgumentException if the message or parameters are invalid
382
+     * @since 11.0.0
383
+     */
384
+    public function setRichMessage($message, array $parameters = []) {
385
+        if (!is_string($message) || $message === '') {
386
+            throw new \InvalidArgumentException('The given parsed message is invalid');
387
+        }
388
+
389
+        $this->messageRich = $message;
390
+        $this->messageRichParameters = $parameters;
391
+
392
+        return $this;
393
+    }
394
+
395
+    /**
396
+     * @return string
397
+     * @since 11.0.0
398
+     */
399
+    public function getRichMessage() {
400
+        return $this->messageRich;
401
+    }
402
+
403
+    /**
404
+     * @return array[]
405
+     * @since 11.0.0
406
+     */
407
+    public function getRichMessageParameters() {
408
+        return $this->messageRichParameters;
409
+    }
410
+
411
+    /**
412
+     * @param string $link
413
+     * @return $this
414
+     * @throws \InvalidArgumentException if the link is invalid
415
+     * @since 8.2.0
416
+     */
417
+    public function setLink($link) {
418
+        if (!is_string($link) || $link === '' || isset($link[4000])) {
419
+            throw new \InvalidArgumentException('The given link is invalid');
420
+        }
421
+        $this->link = $link;
422
+        return $this;
423
+    }
424
+
425
+    /**
426
+     * @return string
427
+     * @since 8.2.0
428
+     */
429
+    public function getLink() {
430
+        return $this->link;
431
+    }
432
+
433
+    /**
434
+     * @param string $icon
435
+     * @return $this
436
+     * @throws \InvalidArgumentException if the icon is invalid
437
+     * @since 11.0.0
438
+     */
439
+    public function setIcon($icon) {
440
+        if (!is_string($icon) || $icon === '' || isset($icon[4000])) {
441
+            throw new \InvalidArgumentException('The given icon is invalid');
442
+        }
443
+        $this->icon = $icon;
444
+        return $this;
445
+    }
446
+
447
+    /**
448
+     * @return string
449
+     * @since 11.0.0
450
+     */
451
+    public function getIcon() {
452
+        return $this->icon;
453
+    }
454
+
455
+    /**
456
+     * @return IAction
457
+     * @since 8.2.0
458
+     */
459
+    public function createAction() {
460
+        return new Action();
461
+    }
462
+
463
+    /**
464
+     * @param IAction $action
465
+     * @return $this
466
+     * @throws \InvalidArgumentException if the action is invalid
467
+     * @since 8.2.0
468
+     */
469
+    public function addAction(IAction $action) {
470
+        if (!$action->isValid()) {
471
+            throw new \InvalidArgumentException('The given action is invalid');
472
+        }
473
+
474
+        if ($action->isPrimary()) {
475
+            if ($this->hasPrimaryAction) {
476
+                throw new \InvalidArgumentException('The notification already has a primary action');
477
+            }
478
+
479
+            $this->hasPrimaryAction = true;
480
+        }
481
+
482
+        $this->actions[] = $action;
483
+        return $this;
484
+    }
485
+
486
+    /**
487
+     * @return IAction[]
488
+     * @since 8.2.0
489
+     */
490
+    public function getActions() {
491
+        return $this->actions;
492
+    }
493
+
494
+    /**
495
+     * @param IAction $action
496
+     * @return $this
497
+     * @throws \InvalidArgumentException if the action is invalid
498
+     * @since 8.2.0
499
+     */
500
+    public function addParsedAction(IAction $action) {
501
+        if (!$action->isValidParsed()) {
502
+            throw new \InvalidArgumentException('The given parsed action is invalid');
503
+        }
504
+
505
+        if ($action->isPrimary()) {
506
+            if ($this->hasPrimaryParsedAction) {
507
+                throw new \InvalidArgumentException('The notification already has a primary action');
508
+            }
509
+
510
+            $this->hasPrimaryParsedAction = true;
511
+
512
+            // Make sure the primary action is always the first one
513
+            array_unshift($this->actionsParsed, $action);
514
+        } else {
515
+            $this->actionsParsed[] = $action;
516
+        }
517
+
518
+        return $this;
519
+    }
520
+
521
+    /**
522
+     * @return IAction[]
523
+     * @since 8.2.0
524
+     */
525
+    public function getParsedActions() {
526
+        return $this->actionsParsed;
527
+    }
528
+
529
+    /**
530
+     * @return bool
531
+     * @since 8.2.0
532
+     */
533
+    public function isValid() {
534
+        return
535
+            $this->isValidCommon()
536
+            &&
537
+            $this->getSubject() !== ''
538
+        ;
539
+    }
540
+
541
+    /**
542
+     * @return bool
543
+     * @since 8.2.0
544
+     */
545
+    public function isValidParsed() {
546
+        if ($this->getRichSubject() !== '' || !empty($this->getRichSubjectParameters())) {
547
+            try {
548
+                $this->richValidator->validate($this->getRichSubject(), $this->getRichSubjectParameters());
549
+            } catch (InvalidObjectExeption $e) {
550
+                return false;
551
+            }
552
+        }
553
+
554
+        if ($this->getRichMessage() !== '' || !empty($this->getRichMessageParameters())) {
555
+            try {
556
+                $this->richValidator->validate($this->getRichMessage(), $this->getRichMessageParameters());
557
+            } catch (InvalidObjectExeption $e) {
558
+                return false;
559
+            }
560
+        }
561
+
562
+        return
563
+            $this->isValidCommon()
564
+            &&
565
+            $this->getParsedSubject() !== ''
566
+        ;
567
+    }
568
+
569
+    /**
570
+     * @return bool
571
+     */
572
+    protected function isValidCommon() {
573
+        return
574
+            $this->getApp() !== ''
575
+            &&
576
+            $this->getUser() !== ''
577
+            &&
578
+            $this->getDateTime()->getTimestamp() !== 0
579
+            &&
580
+            $this->getObjectType() !== ''
581
+            &&
582
+            $this->getObjectId() !== ''
583
+        ;
584
+    }
585 585
 }
Please login to merge, or discard this patch.
lib/private/Notification/Action.php 1 patch
Indentation   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -27,148 +27,148 @@
 block discarded – undo
27 27
 
28 28
 class Action implements IAction {
29 29
 
30
-	/** @var string */
31
-	protected $label;
32
-
33
-	/** @var string */
34
-	protected $labelParsed;
35
-
36
-	/** @var string */
37
-	protected $link;
38
-
39
-	/** @var string */
40
-	protected $requestType;
41
-
42
-	/** @var string */
43
-	protected $icon;
44
-
45
-	/** @var bool */
46
-	protected $primary;
47
-
48
-	/**
49
-	 * Constructor
50
-	 */
51
-	public function __construct() {
52
-		$this->label = '';
53
-		$this->labelParsed = '';
54
-		$this->link = '';
55
-		$this->requestType = '';
56
-		$this->primary = false;
57
-	}
58
-
59
-	/**
60
-	 * @param string $label
61
-	 * @return $this
62
-	 * @throws \InvalidArgumentException if the label is invalid
63
-	 * @since 8.2.0
64
-	 */
65
-	public function setLabel($label) {
66
-		if (!is_string($label) || $label === '' || isset($label[32])) {
67
-			throw new \InvalidArgumentException('The given label is invalid');
68
-		}
69
-		$this->label = $label;
70
-		return $this;
71
-	}
72
-
73
-	/**
74
-	 * @return string
75
-	 * @since 8.2.0
76
-	 */
77
-	public function getLabel() {
78
-		return $this->label;
79
-	}
80
-
81
-	/**
82
-	 * @param string $label
83
-	 * @return $this
84
-	 * @throws \InvalidArgumentException if the label is invalid
85
-	 * @since 8.2.0
86
-	 */
87
-	public function setParsedLabel($label) {
88
-		if (!is_string($label) || $label === '') {
89
-			throw new \InvalidArgumentException('The given parsed label is invalid');
90
-		}
91
-		$this->labelParsed = $label;
92
-		return $this;
93
-	}
94
-
95
-	/**
96
-	 * @return string
97
-	 * @since 8.2.0
98
-	 */
99
-	public function getParsedLabel() {
100
-		return $this->labelParsed;
101
-	}
102
-
103
-	/**
104
-	 * @param $primary bool
105
-	 * @return $this
106
-	 * @throws \InvalidArgumentException if $primary is invalid
107
-	 * @since 9.0.0
108
-	 */
109
-	public function setPrimary($primary) {
110
-		if (!is_bool($primary)) {
111
-			throw new \InvalidArgumentException('The given primary option is invalid');
112
-		}
113
-
114
-		$this->primary = $primary;
115
-		return $this;
116
-	}
117
-
118
-	/**
119
-	 * @return bool
120
-	 * @since 9.0.0
121
-	 */
122
-	public function isPrimary() {
123
-		return $this->primary;
124
-	}
125
-
126
-	/**
127
-	 * @param string $link
128
-	 * @param string $requestType
129
-	 * @return $this
130
-	 * @throws \InvalidArgumentException if the link is invalid
131
-	 * @since 8.2.0
132
-	 */
133
-	public function setLink($link, $requestType) {
134
-		if (!is_string($link) || $link === '' || isset($link[256])) {
135
-			throw new \InvalidArgumentException('The given link is invalid');
136
-		}
137
-		if (!in_array($requestType, ['GET', 'POST', 'PUT', 'DELETE'], true)) {
138
-			throw new \InvalidArgumentException('The given request type is invalid');
139
-		}
140
-		$this->link = $link;
141
-		$this->requestType = $requestType;
142
-		return $this;
143
-	}
144
-
145
-	/**
146
-	 * @return string
147
-	 * @since 8.2.0
148
-	 */
149
-	public function getLink() {
150
-		return $this->link;
151
-	}
152
-
153
-	/**
154
-	 * @return string
155
-	 * @since 8.2.0
156
-	 */
157
-	public function getRequestType() {
158
-		return $this->requestType;
159
-	}
160
-
161
-	/**
162
-	 * @return bool
163
-	 */
164
-	public function isValid() {
165
-		return $this->label !== '' && $this->link !== '';
166
-	}
167
-
168
-	/**
169
-	 * @return bool
170
-	 */
171
-	public function isValidParsed() {
172
-		return $this->labelParsed !== '' && $this->link !== '';
173
-	}
30
+    /** @var string */
31
+    protected $label;
32
+
33
+    /** @var string */
34
+    protected $labelParsed;
35
+
36
+    /** @var string */
37
+    protected $link;
38
+
39
+    /** @var string */
40
+    protected $requestType;
41
+
42
+    /** @var string */
43
+    protected $icon;
44
+
45
+    /** @var bool */
46
+    protected $primary;
47
+
48
+    /**
49
+     * Constructor
50
+     */
51
+    public function __construct() {
52
+        $this->label = '';
53
+        $this->labelParsed = '';
54
+        $this->link = '';
55
+        $this->requestType = '';
56
+        $this->primary = false;
57
+    }
58
+
59
+    /**
60
+     * @param string $label
61
+     * @return $this
62
+     * @throws \InvalidArgumentException if the label is invalid
63
+     * @since 8.2.0
64
+     */
65
+    public function setLabel($label) {
66
+        if (!is_string($label) || $label === '' || isset($label[32])) {
67
+            throw new \InvalidArgumentException('The given label is invalid');
68
+        }
69
+        $this->label = $label;
70
+        return $this;
71
+    }
72
+
73
+    /**
74
+     * @return string
75
+     * @since 8.2.0
76
+     */
77
+    public function getLabel() {
78
+        return $this->label;
79
+    }
80
+
81
+    /**
82
+     * @param string $label
83
+     * @return $this
84
+     * @throws \InvalidArgumentException if the label is invalid
85
+     * @since 8.2.0
86
+     */
87
+    public function setParsedLabel($label) {
88
+        if (!is_string($label) || $label === '') {
89
+            throw new \InvalidArgumentException('The given parsed label is invalid');
90
+        }
91
+        $this->labelParsed = $label;
92
+        return $this;
93
+    }
94
+
95
+    /**
96
+     * @return string
97
+     * @since 8.2.0
98
+     */
99
+    public function getParsedLabel() {
100
+        return $this->labelParsed;
101
+    }
102
+
103
+    /**
104
+     * @param $primary bool
105
+     * @return $this
106
+     * @throws \InvalidArgumentException if $primary is invalid
107
+     * @since 9.0.0
108
+     */
109
+    public function setPrimary($primary) {
110
+        if (!is_bool($primary)) {
111
+            throw new \InvalidArgumentException('The given primary option is invalid');
112
+        }
113
+
114
+        $this->primary = $primary;
115
+        return $this;
116
+    }
117
+
118
+    /**
119
+     * @return bool
120
+     * @since 9.0.0
121
+     */
122
+    public function isPrimary() {
123
+        return $this->primary;
124
+    }
125
+
126
+    /**
127
+     * @param string $link
128
+     * @param string $requestType
129
+     * @return $this
130
+     * @throws \InvalidArgumentException if the link is invalid
131
+     * @since 8.2.0
132
+     */
133
+    public function setLink($link, $requestType) {
134
+        if (!is_string($link) || $link === '' || isset($link[256])) {
135
+            throw new \InvalidArgumentException('The given link is invalid');
136
+        }
137
+        if (!in_array($requestType, ['GET', 'POST', 'PUT', 'DELETE'], true)) {
138
+            throw new \InvalidArgumentException('The given request type is invalid');
139
+        }
140
+        $this->link = $link;
141
+        $this->requestType = $requestType;
142
+        return $this;
143
+    }
144
+
145
+    /**
146
+     * @return string
147
+     * @since 8.2.0
148
+     */
149
+    public function getLink() {
150
+        return $this->link;
151
+    }
152
+
153
+    /**
154
+     * @return string
155
+     * @since 8.2.0
156
+     */
157
+    public function getRequestType() {
158
+        return $this->requestType;
159
+    }
160
+
161
+    /**
162
+     * @return bool
163
+     */
164
+    public function isValid() {
165
+        return $this->label !== '' && $this->link !== '';
166
+    }
167
+
168
+    /**
169
+     * @return bool
170
+     */
171
+    public function isValidParsed() {
172
+        return $this->labelParsed !== '' && $this->link !== '';
173
+    }
174 174
 }
Please login to merge, or discard this patch.