Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/notifications.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2018-01-30 16:53:35 +0300
committerJoas Schilling <coding@schilljs.com>2018-02-20 13:18:04 +0300
commit8e0b465a6ef81437a5f14c53453bb80e5d17646c (patch)
tree4a97bfba06b1f4af70b1ea1d8de8df8cccc41c0d /lib/Controller/PushController.php
parent2a9dcdc766dabe4340484ca7704c773455d8a70e (diff)
Add return types and type hints in the code
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Controller/PushController.php')
-rw-r--r--lib/Controller/PushController.php23
1 files changed, 12 insertions, 11 deletions
diff --git a/lib/Controller/PushController.php b/lib/Controller/PushController.php
index 36d0237..4678e70 100644
--- a/lib/Controller/PushController.php
+++ b/lib/Controller/PushController.php
@@ -79,7 +79,7 @@ class PushController extends OCSController {
* @param string $proxyServer
* @return DataResponse
*/
- public function registerDevice($pushTokenHash, $devicePublicKey, $proxyServer) {
+ public function registerDevice(string $pushTokenHash, string $devicePublicKey, string $proxyServer): DataResponse {
$user = $this->userSession->getUser();
if (!$user instanceof IUser) {
return new DataResponse([], Http::STATUS_UNAUTHORIZED);
@@ -90,16 +90,17 @@ class PushController extends OCSController {
}
if (
- ((strlen($devicePublicKey) !== 450 || strpos($devicePublicKey, "\n" . '-----END PUBLIC KEY-----') !== 425) &&
- (strlen($devicePublicKey) !== 451 || strpos($devicePublicKey, "\n" . '-----END PUBLIC KEY-----' . "\n") !== 425)) ||
- strpos($devicePublicKey, '-----BEGIN PUBLIC KEY-----' . "\n") !== 0) {
+ strpos($devicePublicKey, '-----BEGIN PUBLIC KEY-----' . "\n") !== 0 ||
+ ((\strlen($devicePublicKey) !== 450 || strpos($devicePublicKey, "\n" . '-----END PUBLIC KEY-----') !== 425) &&
+ (\strlen($devicePublicKey) !== 451 || strpos($devicePublicKey, "\n" . '-----END PUBLIC KEY-----' . "\n") !== 425))
+ ) {
return new DataResponse(['message' => 'INVALID_DEVICE_KEY'], Http::STATUS_BAD_REQUEST);
}
if (
!filter_var($proxyServer, FILTER_VALIDATE_URL) ||
- strlen($proxyServer) > 256 ||
- !preg_match('/^(https\:\/\/|http\:\/\/localhost(\:[0-9]{0,5})?\/)/', $proxyServer)
+ \strlen($proxyServer) > 256 ||
+ !preg_match('/^(https\:\/\/|http\:\/\/localhost(\:\d{0,5})?\/)/', $proxyServer)
) {
return new DataResponse(['message' => 'INVALID_PROXY_SERVER'], Http::STATUS_BAD_REQUEST);
}
@@ -144,7 +145,7 @@ class PushController extends OCSController {
*
* @return DataResponse
*/
- public function removeDevice() {
+ public function removeDevice(): DataResponse {
$user = $this->userSession->getUser();
if (!$user instanceof IUser) {
return new DataResponse([], Http::STATUS_UNAUTHORIZED);
@@ -174,7 +175,7 @@ class PushController extends OCSController {
* @param string $appType
* @return bool If the hash was new to the database
*/
- protected function savePushToken(IUser $user, IToken $token, $deviceIdentifier, $devicePublicKey, $pushTokenHash, $proxyServer, $appType) {
+ protected function savePushToken(IUser $user, IToken $token, string $deviceIdentifier, string $devicePublicKey, string $pushTokenHash, string $proxyServer, string $appType): bool {
$query = $this->db->getQueryBuilder();
$query->select('*')
->from('notifications_pushtokens')
@@ -201,7 +202,7 @@ class PushController extends OCSController {
* @param string $appType
* @return bool If the entry was created
*/
- protected function insertPushToken(IUser $user, IToken $token, $deviceIdentifier, $devicePublicKey, $pushTokenHash, $proxyServer, $appType) {
+ protected function insertPushToken(IUser $user, IToken $token, string $deviceIdentifier, string $devicePublicKey, string $pushTokenHash, string $proxyServer, string $appType): bool {
$devicePublicKeyHash = hash('sha512', $devicePublicKey);
$query = $this->db->getQueryBuilder();
@@ -228,7 +229,7 @@ class PushController extends OCSController {
* @param string $appType
* @return bool If the entry was updated
*/
- protected function updatePushToken(IUser $user, IToken $token, $devicePublicKey, $pushTokenHash, $proxyServer, $appType) {
+ protected function updatePushToken(IUser $user, IToken $token, string $devicePublicKey, string $pushTokenHash, string $proxyServer, string $appType): bool {
$devicePublicKeyHash = hash('sha512', $devicePublicKey);
$query = $this->db->getQueryBuilder();
@@ -249,7 +250,7 @@ class PushController extends OCSController {
* @param IToken $token
* @return bool If the entry was deleted
*/
- protected function deletePushToken(IUser $user, IToken $token) {
+ protected function deletePushToken(IUser $user, IToken $token): bool {
$query = $this->db->getQueryBuilder();
$query->delete('notifications_pushtokens')
->where($query->expr()->eq('uid', $query->createNamedParameter($user->getUID())))