Passed
Push — master ( d66bf3...d51429 )
by Joas
13:28 queued 12s
created
apps/user_status/lib/Controller/HeartbeatController.php 1 patch
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -41,74 +41,74 @@
 block discarded – undo
41 41
 
42 42
 class HeartbeatController extends OCSController {
43 43
 
44
-	/** @var IEventDispatcher */
45
-	private $eventDispatcher;
46
-
47
-	/** @var IUserSession */
48
-	private $userSession;
49
-
50
-	/** @var ITimeFactory */
51
-	private $timeFactory;
52
-
53
-	/** @var StatusService */
54
-	private $service;
55
-
56
-	public function __construct(string $appName,
57
-								IRequest $request,
58
-								IEventDispatcher $eventDispatcher,
59
-								IUserSession $userSession,
60
-								ITimeFactory $timeFactory,
61
-								StatusService $service) {
62
-		parent::__construct($appName, $request);
63
-		$this->eventDispatcher = $eventDispatcher;
64
-		$this->userSession = $userSession;
65
-		$this->timeFactory = $timeFactory;
66
-		$this->service = $service;
67
-	}
68
-
69
-	/**
70
-	 * @NoAdminRequired
71
-	 *
72
-	 * @param string $status
73
-	 * @return DataResponse
74
-	 */
75
-	public function heartbeat(string $status): DataResponse {
76
-		if (!\in_array($status, [IUserStatus::ONLINE, IUserStatus::AWAY], true)) {
77
-			return new DataResponse([], Http::STATUS_BAD_REQUEST);
78
-		}
79
-
80
-		$user = $this->userSession->getUser();
81
-		if ($user === null) {
82
-			return new DataResponse([], Http::STATUS_INTERNAL_SERVER_ERROR);
83
-		}
84
-
85
-		$event = new UserLiveStatusEvent(
86
-			$user,
87
-			$status,
88
-			$this->timeFactory->getTime()
89
-		);
90
-
91
-		$this->eventDispatcher->dispatchTyped($event);
92
-
93
-		$userStatus = $event->getUserStatus();
94
-		if (!$userStatus) {
95
-			return new DataResponse([], Http::STATUS_NO_CONTENT);
96
-		}
97
-
98
-		/** @psalm-suppress UndefinedInterfaceMethod */
99
-		return new DataResponse($this->formatStatus($userStatus->getInternal()));
100
-	}
101
-
102
-	private function formatStatus(UserStatus $status): array {
103
-		return [
104
-			'userId' => $status->getUserId(),
105
-			'message' => $status->getCustomMessage(),
106
-			'messageId' => $status->getMessageId(),
107
-			'messageIsPredefined' => $status->getMessageId() !== null,
108
-			'icon' => $status->getCustomIcon(),
109
-			'clearAt' => $status->getClearAt(),
110
-			'status' => $status->getStatus(),
111
-			'statusIsUserDefined' => $status->getIsUserDefined(),
112
-		];
113
-	}
44
+    /** @var IEventDispatcher */
45
+    private $eventDispatcher;
46
+
47
+    /** @var IUserSession */
48
+    private $userSession;
49
+
50
+    /** @var ITimeFactory */
51
+    private $timeFactory;
52
+
53
+    /** @var StatusService */
54
+    private $service;
55
+
56
+    public function __construct(string $appName,
57
+                                IRequest $request,
58
+                                IEventDispatcher $eventDispatcher,
59
+                                IUserSession $userSession,
60
+                                ITimeFactory $timeFactory,
61
+                                StatusService $service) {
62
+        parent::__construct($appName, $request);
63
+        $this->eventDispatcher = $eventDispatcher;
64
+        $this->userSession = $userSession;
65
+        $this->timeFactory = $timeFactory;
66
+        $this->service = $service;
67
+    }
68
+
69
+    /**
70
+     * @NoAdminRequired
71
+     *
72
+     * @param string $status
73
+     * @return DataResponse
74
+     */
75
+    public function heartbeat(string $status): DataResponse {
76
+        if (!\in_array($status, [IUserStatus::ONLINE, IUserStatus::AWAY], true)) {
77
+            return new DataResponse([], Http::STATUS_BAD_REQUEST);
78
+        }
79
+
80
+        $user = $this->userSession->getUser();
81
+        if ($user === null) {
82
+            return new DataResponse([], Http::STATUS_INTERNAL_SERVER_ERROR);
83
+        }
84
+
85
+        $event = new UserLiveStatusEvent(
86
+            $user,
87
+            $status,
88
+            $this->timeFactory->getTime()
89
+        );
90
+
91
+        $this->eventDispatcher->dispatchTyped($event);
92
+
93
+        $userStatus = $event->getUserStatus();
94
+        if (!$userStatus) {
95
+            return new DataResponse([], Http::STATUS_NO_CONTENT);
96
+        }
97
+
98
+        /** @psalm-suppress UndefinedInterfaceMethod */
99
+        return new DataResponse($this->formatStatus($userStatus->getInternal()));
100
+    }
101
+
102
+    private function formatStatus(UserStatus $status): array {
103
+        return [
104
+            'userId' => $status->getUserId(),
105
+            'message' => $status->getCustomMessage(),
106
+            'messageId' => $status->getMessageId(),
107
+            'messageIsPredefined' => $status->getMessageId() !== null,
108
+            'icon' => $status->getCustomIcon(),
109
+            'clearAt' => $status->getClearAt(),
110
+            'status' => $status->getStatus(),
111
+            'statusIsUserDefined' => $status->getIsUserDefined(),
112
+        ];
113
+    }
114 114
 }
Please login to merge, or discard this patch.