summaryrefslogtreecommitdiffstats
path: root/lib/public/AppFramework
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2018-02-09 15:12:49 +0100
committerRoeland Jago Douma <roeland@famdouma.nl>2018-02-27 12:25:53 +0100
commit9cf49873fa0d6b9156da7983e729a59e8417d653 (patch)
treee5bf2bad9eee81faa5eb7ec0885d0cac7c3c2209 /lib/public/AppFramework
parent2b6c00fc0f4730a20479edee78cfca775bb3bd9a (diff)
downloadnextcloud-server-9cf49873fa0d6b9156da7983e729a59e8417d653.tar.gz
nextcloud-server-9cf49873fa0d6b9156da7983e729a59e8417d653.zip
Rework array handling to avoid phan error
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib/public/AppFramework')
-rw-r--r--lib/public/AppFramework/Http/Template/PublicTemplateResponse.php39
1 files changed, 12 insertions, 27 deletions
diff --git a/lib/public/AppFramework/Http/Template/PublicTemplateResponse.php b/lib/public/AppFramework/Http/Template/PublicTemplateResponse.php
index df4909e7f18..3409d5aae53 100644
--- a/lib/public/AppFramework/Http/Template/PublicTemplateResponse.php
+++ b/lib/public/AppFramework/Http/Template/PublicTemplateResponse.php
@@ -23,6 +23,7 @@
namespace OCP\AppFramework\Http\Template;
+use InvalidArgumentException;
use OCP\AppFramework\Http\TemplateResponse;
/**
@@ -85,36 +86,30 @@ class PublicTemplateResponse extends TemplateResponse {
/**
* @param array $actions
* @since 14.0.0
+ * @throws InvalidArgumentException
*/
public function setHeaderActions(array $actions) {
foreach ($actions as $action) {
if ($actions instanceof IMenuAction) {
- throw new \InvalidArgumentException('Actions must be of type IMenuAction');
+ throw new InvalidArgumentException('Actions must be of type IMenuAction');
}
$this->headerActions[] = $action;
}
- }
-
- /**
- * @param IMenuAction $action
- * @since 14.0.0
- */
- public function addAction(IMenuAction $action) {
- $this->headerActions[] = $action;
+ usort($this->headerActions, function(IMenuAction $a, IMenuAction $b) {
+ return $a->getPriority() > $b->getPriority();
+ });
}
/**
* @return IMenuAction
* @since 14.0.0
+ * @throws \Exception
*/
public function getPrimaryAction(): IMenuAction {
- $lowest = null;
- foreach ($this->headerActions as $action) {
- if($lowest === null || $action->getPriority() < $lowest->getPriority()) {
- $lowest = $action;
- }
+ if ($this->getActionCount() > 0) {
+ return $this->headerActions[0];
}
- return $lowest;
+ throw new \Exception('No header actions have been set');
}
/**
@@ -130,24 +125,14 @@ class PublicTemplateResponse extends TemplateResponse {
* @since 14.0.0
*/
public function getOtherActions(): array {
- $list = [];
- $primary = $this->getPrimaryAction();
- foreach ($this->headerActions as $action) {
- if($primary !== $action) {
- $list[] = $action;
- }
- }
- usort($list, function(IMenuAction $a, IMenuAction $b) {
- return $a->getPriority() > $b->getPriority();
- });
- return $list;
+ return array_slice($this->headerActions, 1);
}
/**
* @return string
* @since 14.0.0
*/
- public function render() {
+ public function render(): string {
$params = array_merge($this->getParams(), [
'template' => $this,
]);