Completed
Pull Request — master (#3233)
by Christoph
19:45
created
core/Controller/ContactsMenuController.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -31,30 +31,30 @@
 block discarded – undo
31 31
 
32 32
 class ContactsMenuController extends Controller {
33 33
 
34
-	/** @var Manager */
35
-	private $manager;
36
-
37
-	/** @var string */
38
-	private $userId;
39
-
40
-	/**
41
-	 * @param IRequest $request
42
-	 * @param string $UserId
43
-	 */
44
-	public function __construct(IRequest $request, $UserId, Manager $manager) {
45
-		parent::__construct('core', $request);
46
-		$this->userId = $UserId;
47
-		$this->manager = $manager;
48
-	}
49
-
50
-	/**
51
-	 * @NoAdminRequired
52
-	 *
53
-	 * @param string|null filter
54
-	 * @return JSONResponse
55
-	 */
56
-	public function index($filter = null) {
57
-		return $this->manager->getEntries($this->userId, $filter);
58
-	}
34
+    /** @var Manager */
35
+    private $manager;
36
+
37
+    /** @var string */
38
+    private $userId;
39
+
40
+    /**
41
+     * @param IRequest $request
42
+     * @param string $UserId
43
+     */
44
+    public function __construct(IRequest $request, $UserId, Manager $manager) {
45
+        parent::__construct('core', $request);
46
+        $this->userId = $UserId;
47
+        $this->manager = $manager;
48
+    }
49
+
50
+    /**
51
+     * @NoAdminRequired
52
+     *
53
+     * @param string|null filter
54
+     * @return JSONResponse
55
+     */
56
+    public function index($filter = null) {
57
+        return $this->manager->getEntries($this->userId, $filter);
58
+    }
59 59
 
60 60
 }
Please login to merge, or discard this patch.
core/routes.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -35,35 +35,35 @@  discard block
 block discarded – undo
35 35
 
36 36
 $application = new Application();
37 37
 $application->registerRoutes($this, [
38
-	'routes' => [
39
-		['name' => 'lost#email', 'url' => '/lostpassword/email', 'verb' => 'POST'],
40
-		['name' => 'lost#resetform', 'url' => '/lostpassword/reset/form/{token}/{userId}', 'verb' => 'GET'],
41
-		['name' => 'lost#setPassword', 'url' => '/lostpassword/set/{token}/{userId}', 'verb' => 'POST'],
42
-		['name' => 'user#getDisplayNames', 'url' => '/displaynames', 'verb' => 'POST'],
43
-		['name' => 'avatar#getAvatar', 'url' => '/avatar/{userId}/{size}', 'verb' => 'GET'],
44
-		['name' => 'avatar#deleteAvatar', 'url' => '/avatar/', 'verb' => 'DELETE'],
45
-		['name' => 'avatar#postCroppedAvatar', 'url' => '/avatar/cropped', 'verb' => 'POST'],
46
-		['name' => 'avatar#getTmpAvatar', 'url' => '/avatar/tmp', 'verb' => 'GET'],
47
-		['name' => 'avatar#postAvatar', 'url' => '/avatar/', 'verb' => 'POST'],
48
-		['name' => 'login#tryLogin', 'url' => '/login', 'verb' => 'POST'],
49
-		['name' => 'login#confirmPassword', 'url' => '/login/confirm', 'verb' => 'POST'],
50
-		['name' => 'login#showLoginForm', 'url' => '/login', 'verb' => 'GET'],
51
-		['name' => 'login#logout', 'url' => '/logout', 'verb' => 'GET'],
52
-		['name' => 'TwoFactorChallenge#selectChallenge', 'url' => '/login/selectchallenge', 'verb' => 'GET'],
53
-		['name' => 'TwoFactorChallenge#showChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'GET'],
54
-		['name' => 'TwoFactorChallenge#solveChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'POST'],
55
-		['name' => 'OCJS#getConfig', 'url' => '/core/js/oc.js', 'verb' => 'GET'],
56
-		['name' => 'Preview#getPreview', 'url' => '/core/preview', 'verb' => 'GET'],
57
-		['name' => 'Preview#getPreview', 'url' => '/core/preview.png', 'verb' => 'GET'],
58
-		['name' => 'Css#getCss', 'url' => '/css/{appName}/{fileName}', 'verb' => 'GET'],
59
-		['name' => 'contactsMenu#index', 'url' => '/contactsmenu/contacts', 'verb' => 'GET'],
60
-	],
61
-	'ocs' => [
62
-		['root' => '/cloud', 'name' => 'OCS#getCapabilities', 'url' => '/capabilities', 'verb' => 'GET'],
63
-		['root' => '', 'name' => 'OCS#getConfig', 'url' => '/config', 'verb' => 'GET'],
64
-		['root' => '/person', 'name' => 'OCS#personCheck', 'url' => '/check', 'verb' => 'POST'],
65
-		['root' => '/identityproof', 'name' => 'OCS#getIdentityProof', 'url' => '/key/{cloudId}', 'verb' => 'GET'],
66
-	],
38
+    'routes' => [
39
+        ['name' => 'lost#email', 'url' => '/lostpassword/email', 'verb' => 'POST'],
40
+        ['name' => 'lost#resetform', 'url' => '/lostpassword/reset/form/{token}/{userId}', 'verb' => 'GET'],
41
+        ['name' => 'lost#setPassword', 'url' => '/lostpassword/set/{token}/{userId}', 'verb' => 'POST'],
42
+        ['name' => 'user#getDisplayNames', 'url' => '/displaynames', 'verb' => 'POST'],
43
+        ['name' => 'avatar#getAvatar', 'url' => '/avatar/{userId}/{size}', 'verb' => 'GET'],
44
+        ['name' => 'avatar#deleteAvatar', 'url' => '/avatar/', 'verb' => 'DELETE'],
45
+        ['name' => 'avatar#postCroppedAvatar', 'url' => '/avatar/cropped', 'verb' => 'POST'],
46
+        ['name' => 'avatar#getTmpAvatar', 'url' => '/avatar/tmp', 'verb' => 'GET'],
47
+        ['name' => 'avatar#postAvatar', 'url' => '/avatar/', 'verb' => 'POST'],
48
+        ['name' => 'login#tryLogin', 'url' => '/login', 'verb' => 'POST'],
49
+        ['name' => 'login#confirmPassword', 'url' => '/login/confirm', 'verb' => 'POST'],
50
+        ['name' => 'login#showLoginForm', 'url' => '/login', 'verb' => 'GET'],
51
+        ['name' => 'login#logout', 'url' => '/logout', 'verb' => 'GET'],
52
+        ['name' => 'TwoFactorChallenge#selectChallenge', 'url' => '/login/selectchallenge', 'verb' => 'GET'],
53
+        ['name' => 'TwoFactorChallenge#showChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'GET'],
54
+        ['name' => 'TwoFactorChallenge#solveChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'POST'],
55
+        ['name' => 'OCJS#getConfig', 'url' => '/core/js/oc.js', 'verb' => 'GET'],
56
+        ['name' => 'Preview#getPreview', 'url' => '/core/preview', 'verb' => 'GET'],
57
+        ['name' => 'Preview#getPreview', 'url' => '/core/preview.png', 'verb' => 'GET'],
58
+        ['name' => 'Css#getCss', 'url' => '/css/{appName}/{fileName}', 'verb' => 'GET'],
59
+        ['name' => 'contactsMenu#index', 'url' => '/contactsmenu/contacts', 'verb' => 'GET'],
60
+    ],
61
+    'ocs' => [
62
+        ['root' => '/cloud', 'name' => 'OCS#getCapabilities', 'url' => '/capabilities', 'verb' => 'GET'],
63
+        ['root' => '', 'name' => 'OCS#getConfig', 'url' => '/config', 'verb' => 'GET'],
64
+        ['root' => '/person', 'name' => 'OCS#personCheck', 'url' => '/check', 'verb' => 'POST'],
65
+        ['root' => '/identityproof', 'name' => 'OCS#getIdentityProof', 'url' => '/key/{cloudId}', 'verb' => 'GET'],
66
+    ],
67 67
 ]);
68 68
 
69 69
 // Post installation check
@@ -72,36 +72,36 @@  discard block
 block discarded – undo
72 72
 // Core ajax actions
73 73
 // Search
74 74
 $this->create('search_ajax_search', '/core/search')
75
-	->actionInclude('core/search/ajax/search.php');
75
+    ->actionInclude('core/search/ajax/search.php');
76 76
 // Routing
77 77
 $this->create('core_ajax_update', '/core/ajax/update.php')
78
-	->actionInclude('core/ajax/update.php');
78
+    ->actionInclude('core/ajax/update.php');
79 79
 
80 80
 // File routes
81 81
 $this->create('files.viewcontroller.showFile', '/f/{fileid}')->action(function($urlParams) {
82
-	$app = new \OCA\Files\AppInfo\Application($urlParams);
83
-	$app->dispatch('ViewController', 'index');
82
+    $app = new \OCA\Files\AppInfo\Application($urlParams);
83
+    $app->dispatch('ViewController', 'index');
84 84
 });
85 85
 
86 86
 // Sharing routes
87 87
 $this->create('files_sharing.sharecontroller.showShare', '/s/{token}')->action(function($urlParams) {
88
-	$app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
89
-	$app->dispatch('ShareController', 'showShare');
88
+    $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
89
+    $app->dispatch('ShareController', 'showShare');
90 90
 });
91 91
 $this->create('files_sharing.sharecontroller.authenticate', '/s/{token}/authenticate')->post()->action(function($urlParams) {
92
-	$app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
93
-	$app->dispatch('ShareController', 'authenticate');
92
+    $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
93
+    $app->dispatch('ShareController', 'authenticate');
94 94
 });
95 95
 $this->create('files_sharing.sharecontroller.showAuthenticate', '/s/{token}/authenticate')->get()->action(function($urlParams) {
96
-	$app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
97
-	$app->dispatch('ShareController', 'showAuthenticate');
96
+    $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
97
+    $app->dispatch('ShareController', 'showAuthenticate');
98 98
 });
99 99
 $this->create('files_sharing.sharecontroller.downloadShare', '/s/{token}/download')->get()->action(function($urlParams) {
100
-	$app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
101
-	$app->dispatch('ShareController', 'downloadShare');
100
+    $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
101
+    $app->dispatch('ShareController', 'downloadShare');
102 102
 });
103 103
 
104 104
 // used for heartbeat
105 105
 $this->create('heartbeat', '/heartbeat')->action(function(){
106
-	// do nothing
106
+    // do nothing
107 107
 });
Please login to merge, or discard this patch.
lib/private/Contacts/ContactsMenu/ContactsStore.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -29,56 +29,56 @@
 block discarded – undo
29 29
 
30 30
 class ContactsStore {
31 31
 
32
-	/** @var IManager */
33
-	private $contactsManager;
32
+    /** @var IManager */
33
+    private $contactsManager;
34 34
 
35
-	/**
36
-	 * @param IManager $contactsManager
37
-	 */
38
-	public function __construct(IManager $contactsManager) {
39
-		$this->contactsManager = $contactsManager;
40
-	}
35
+    /**
36
+     * @param IManager $contactsManager
37
+     */
38
+    public function __construct(IManager $contactsManager) {
39
+        $this->contactsManager = $contactsManager;
40
+    }
41 41
 
42
-	/**
43
-	 * @param string|null $filter
44
-	 * @return IEntry[]
45
-	 */
46
-	public function getContacts($filter) {
47
-		$allContacts = $this->contactsManager->search($filter ?: '', [
48
-			'FN',
49
-		]);
42
+    /**
43
+     * @param string|null $filter
44
+     * @return IEntry[]
45
+     */
46
+    public function getContacts($filter) {
47
+        $allContacts = $this->contactsManager->search($filter ?: '', [
48
+            'FN',
49
+        ]);
50 50
 
51
-		return array_map(function(array $contact) {
52
-			return $this->contactArrayToEntry($contact);
53
-		}, $allContacts);
54
-	}
51
+        return array_map(function(array $contact) {
52
+            return $this->contactArrayToEntry($contact);
53
+        }, $allContacts);
54
+    }
55 55
 
56
-	/**
57
-	 * @param array $contact
58
-	 * @return Entry
59
-	 */
60
-	private function contactArrayToEntry(array $contact) {
61
-		$entry = new Entry();
56
+    /**
57
+     * @param array $contact
58
+     * @return Entry
59
+     */
60
+    private function contactArrayToEntry(array $contact) {
61
+        $entry = new Entry();
62 62
 
63
-		if (isset($contact['id'])) {
64
-			$entry->setId($contact['id']);
65
-		}
63
+        if (isset($contact['id'])) {
64
+            $entry->setId($contact['id']);
65
+        }
66 66
 
67
-		if (isset($contact['FN'])) {
68
-			$entry->setFullName($contact['FN']);
69
-		}
67
+        if (isset($contact['FN'])) {
68
+            $entry->setFullName($contact['FN']);
69
+        }
70 70
 
71
-		if (isset($contact['EMAIL'])) {
72
-			foreach ($contact['EMAIL'] as $email) {
73
-				$entry->addEMailAddress($email);
74
-			}
75
-		}
71
+        if (isset($contact['EMAIL'])) {
72
+            foreach ($contact['EMAIL'] as $email) {
73
+                $entry->addEMailAddress($email);
74
+            }
75
+        }
76 76
 
77
-		// Attach all other properties to the entry too becuase some
78
-		// providers might make use of it.
79
-		$entry->setProperties($contact);
77
+        // Attach all other properties to the entry too becuase some
78
+        // providers might make use of it.
79
+        $entry->setProperties($contact);
80 80
 
81
-		return $entry;
82
-	}
81
+        return $entry;
82
+    }
83 83
 
84 84
 }
Please login to merge, or discard this patch.
lib/private/Contacts/ContactsMenu/ActionFactory.php 2 patches
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -30,28 +30,28 @@
 block discarded – undo
30 30
 
31 31
 class ActionFactory implements IActionFactory {
32 32
 
33
-	/**
34
-	 * @param string $icon
35
-	 * @param string $name
36
-	 * @param string $href
37
-	 * @return ILinkAction
38
-	 */
39
-	public function newLinkAction($icon, $name, $href) {
40
-		$action = new LinkAction();
41
-		$action->setName($name);
42
-		$action->setIcon($icon);
43
-		$action->setHref($href);
44
-		return $action;
45
-	}
33
+    /**
34
+     * @param string $icon
35
+     * @param string $name
36
+     * @param string $href
37
+     * @return ILinkAction
38
+     */
39
+    public function newLinkAction($icon, $name, $href) {
40
+        $action = new LinkAction();
41
+        $action->setName($name);
42
+        $action->setIcon($icon);
43
+        $action->setHref($href);
44
+        return $action;
45
+    }
46 46
 
47
-	/**
48
-	 * @param string $icon
49
-	 * @param string $name
50
-	 * @param string $email
51
-	 * @return ILinkAction
52
-	 */
53
-	public function newEMailAction($icon, $name, $email) {
54
-		return $this->newLinkAction($icon, $name, 'mailto:' . urlencode($email));
55
-	}
47
+    /**
48
+     * @param string $icon
49
+     * @param string $name
50
+     * @param string $email
51
+     * @return ILinkAction
52
+     */
53
+    public function newEMailAction($icon, $name, $email) {
54
+        return $this->newLinkAction($icon, $name, 'mailto:' . urlencode($email));
55
+    }
56 56
 
57 57
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@
 block discarded – undo
51 51
 	 * @return ILinkAction
52 52
 	 */
53 53
 	public function newEMailAction($icon, $name, $email) {
54
-		return $this->newLinkAction($icon, $name, 'mailto:' . urlencode($email));
54
+		return $this->newLinkAction($icon, $name, 'mailto:'.urlencode($email));
55 55
 	}
56 56
 
57 57
 }
Please login to merge, or discard this patch.
lib/private/Contacts/ContactsMenu/Actions/LinkAction.php 1 patch
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -28,76 +28,76 @@
 block discarded – undo
28 28
 
29 29
 class LinkAction implements ILinkAction {
30 30
 
31
-	/** @var string */
32
-	private $icon;
33
-
34
-	/** @var string */
35
-	private $name;
36
-
37
-	/** @var string */
38
-	private $href;
39
-
40
-	/** @var int */
41
-	private $priority = 10;
42
-
43
-	/**
44
-	 * @param string $icon absolute URI to an icon
45
-	 */
46
-	public function setIcon($icon) {
47
-		$this->icon = $icon;
48
-	}
49
-
50
-	/**
51
-	 * @param string $name
52
-	 */
53
-	public function setName($name) {
54
-		$this->name = $name;
55
-	}
56
-
57
-	/**
58
-	 * @return string
59
-	 */
60
-	public function getName() {
61
-		return $this->name;
62
-	}
63
-
64
-	/**
65
-	 * @param int $priority
66
-	 */
67
-	public function setPriority($priority) {
68
-		$this->priority = $priority;
69
-	}
70
-
71
-	/**
72
-	 * @return int
73
-	 */
74
-	public function getPriority() {
75
-		return $this->priority;
76
-	}
77
-
78
-	/**
79
-	 * @param string $href
80
-	 */
81
-	public function setHref($href) {
82
-		$this->href = $href;
83
-	}
84
-
85
-	/**
86
-	 * @return string
87
-	 */
88
-	public function getHref() {
89
-		return $this->href;
90
-	}
91
-
92
-	/**
93
-	 * @return array
94
-	 */
95
-	public function jsonSerialize() {
96
-		return [
97
-			'title' => $this->name,
98
-			'icon' => $this->icon,
99
-			'hyperlink' => $this->href,
100
-		];
101
-	}
31
+    /** @var string */
32
+    private $icon;
33
+
34
+    /** @var string */
35
+    private $name;
36
+
37
+    /** @var string */
38
+    private $href;
39
+
40
+    /** @var int */
41
+    private $priority = 10;
42
+
43
+    /**
44
+     * @param string $icon absolute URI to an icon
45
+     */
46
+    public function setIcon($icon) {
47
+        $this->icon = $icon;
48
+    }
49
+
50
+    /**
51
+     * @param string $name
52
+     */
53
+    public function setName($name) {
54
+        $this->name = $name;
55
+    }
56
+
57
+    /**
58
+     * @return string
59
+     */
60
+    public function getName() {
61
+        return $this->name;
62
+    }
63
+
64
+    /**
65
+     * @param int $priority
66
+     */
67
+    public function setPriority($priority) {
68
+        $this->priority = $priority;
69
+    }
70
+
71
+    /**
72
+     * @return int
73
+     */
74
+    public function getPriority() {
75
+        return $this->priority;
76
+    }
77
+
78
+    /**
79
+     * @param string $href
80
+     */
81
+    public function setHref($href) {
82
+        $this->href = $href;
83
+    }
84
+
85
+    /**
86
+     * @return string
87
+     */
88
+    public function getHref() {
89
+        return $this->href;
90
+    }
91
+
92
+    /**
93
+     * @return array
94
+     */
95
+    public function jsonSerialize() {
96
+        return [
97
+            'title' => $this->name,
98
+            'icon' => $this->icon,
99
+            'hyperlink' => $this->href,
100
+        ];
101
+    }
102 102
 
103 103
 }
Please login to merge, or discard this patch.
lib/private/Contacts/ContactsMenu/Providers/EMailProvider.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -30,27 +30,27 @@
 block discarded – undo
30 30
 
31 31
 class EMailProvider implements IProvider {
32 32
 
33
-	/** @var IActionFactory */
34
-	private $actionFactory;
35
-
36
-	/**
37
-	 * @param IActionFactory $actionFactory
38
-	 */
39
-	public function __construct(IActionFactory $actionFactory) {
40
-		$this->actionFactory = $actionFactory;
41
-	}
42
-
43
-	/**
44
-	 * @param IEntry $entry
45
-	 */
46
-	public function process(IEntry $entry) {
47
-		foreach ($entry->getEMailAddresses() as $address) {
48
-			// TODO: absolute path
49
-			// TODO: meaningful URL
50
-			// TODO: l10n
51
-			$action = $this->actionFactory->newEMailAction('icon-mail', 'Mail', $address);
52
-			$entry->addAction($action);
53
-		}
54
-	}
33
+    /** @var IActionFactory */
34
+    private $actionFactory;
35
+
36
+    /**
37
+     * @param IActionFactory $actionFactory
38
+     */
39
+    public function __construct(IActionFactory $actionFactory) {
40
+        $this->actionFactory = $actionFactory;
41
+    }
42
+
43
+    /**
44
+     * @param IEntry $entry
45
+     */
46
+    public function process(IEntry $entry) {
47
+        foreach ($entry->getEMailAddresses() as $address) {
48
+            // TODO: absolute path
49
+            // TODO: meaningful URL
50
+            // TODO: l10n
51
+            $action = $this->actionFactory->newEMailAction('icon-mail', 'Mail', $address);
52
+            $entry->addAction($action);
53
+        }
54
+    }
55 55
 
56 56
 }
Please login to merge, or discard this patch.
lib/private/Contacts/ContactsMenu/Entry.php 1 patch
Indentation   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -29,123 +29,123 @@
 block discarded – undo
29 29
 
30 30
 class Entry implements IEntry {
31 31
 
32
-	/** @var string|int|null */
33
-	private $id = null;
34
-
35
-	/** @var string */
36
-	private $fullName = '';
37
-
38
-	/** @var string[] */
39
-	private $emailAddresses = [];
40
-
41
-	/** @var IAction[] */
42
-	private $actions = [];
43
-
44
-	/** @var array */
45
-	private $properties = [];
46
-
47
-	/**
48
-	 * @param string $id
49
-	 */
50
-	public function setId($id) {
51
-		$this->id = $id;
52
-	}
53
-
54
-	/**
55
-	 * @param string $displayName
56
-	 */
57
-	public function setFullName($displayName) {
58
-		$this->fullName = $displayName;
59
-	}
60
-
61
-	/**
62
-	 * @return string
63
-	 */
64
-	public function getFullName() {
65
-		return $this->fullName;
66
-	}
67
-
68
-	/**
69
-	 * @param string $address
70
-	 */
71
-	public function addEMailAddress($address) {
72
-		$this->emailAddresses[] = $address;
73
-	}
74
-
75
-	/**
76
-	 * @return string
77
-	 */
78
-	public function getEMailAddresses() {
79
-		return $this->emailAddresses;
80
-	}
81
-
82
-	/**
83
-	 * @param IAction $action
84
-	 */
85
-	public function addAction(IAction $action) {
86
-		$this->actions[] = $action;
87
-		$this->sortActions();
88
-	}
89
-
90
-	/**
91
-	 * @return IAction[]
92
-	 */
93
-	public function getActions() {
94
-		return $this->actions;
95
-	}
96
-
97
-	/**
98
-	 * sort the actions by priority and name
99
-	 */
100
-	private function sortActions() {
101
-		usort($this->actions, function(IAction $action1, IAction $action2) {
102
-			$prio1 = $action1->getPriority();
103
-			$prio2 = $action2->getPriority();
104
-
105
-			if ($prio1 === $prio2) {
106
-				// Ascending order for same priority
107
-				return strcasecmp($action1->getName(), $action2->getName());
108
-			}
109
-
110
-			// Descending order when priority differs
111
-			return $prio2 - $prio1;
112
-		});
113
-	}
114
-
115
-	/**
116
-	 * @param array $contact key-value array containing additional properties
117
-	 */
118
-	public function setProperties(array $contact) {
119
-		$this->properties = $contact;
120
-	}
121
-
122
-	/**
123
-	 * @param string $key
124
-	 * @return mixed
125
-	 */
126
-	public function getProperty($key) {
127
-		if (!isset($this->properties[$key])) {
128
-			return null;
129
-		}
130
-		return $this->properties[$key];
131
-	}
132
-
133
-	/**
134
-	 * @return array
135
-	 */
136
-	public function jsonSerialize() {
137
-		$topAction = !empty($this->actions) ? $this->actions[0]->jsonSerialize() : null;
138
-		$otherActions = array_map(function(IAction $action) {
139
-			return $action->jsonSerialize();
140
-		}, array_slice($this->actions, 1));
141
-
142
-		return [
143
-			'id' => $this->id,
144
-			'fullName' => $this->fullName,
145
-			'topAction' => $topAction,
146
-			'actions' => $otherActions,
147
-			'lastMessage' => '',
148
-		];
149
-	}
32
+    /** @var string|int|null */
33
+    private $id = null;
34
+
35
+    /** @var string */
36
+    private $fullName = '';
37
+
38
+    /** @var string[] */
39
+    private $emailAddresses = [];
40
+
41
+    /** @var IAction[] */
42
+    private $actions = [];
43
+
44
+    /** @var array */
45
+    private $properties = [];
46
+
47
+    /**
48
+     * @param string $id
49
+     */
50
+    public function setId($id) {
51
+        $this->id = $id;
52
+    }
53
+
54
+    /**
55
+     * @param string $displayName
56
+     */
57
+    public function setFullName($displayName) {
58
+        $this->fullName = $displayName;
59
+    }
60
+
61
+    /**
62
+     * @return string
63
+     */
64
+    public function getFullName() {
65
+        return $this->fullName;
66
+    }
67
+
68
+    /**
69
+     * @param string $address
70
+     */
71
+    public function addEMailAddress($address) {
72
+        $this->emailAddresses[] = $address;
73
+    }
74
+
75
+    /**
76
+     * @return string
77
+     */
78
+    public function getEMailAddresses() {
79
+        return $this->emailAddresses;
80
+    }
81
+
82
+    /**
83
+     * @param IAction $action
84
+     */
85
+    public function addAction(IAction $action) {
86
+        $this->actions[] = $action;
87
+        $this->sortActions();
88
+    }
89
+
90
+    /**
91
+     * @return IAction[]
92
+     */
93
+    public function getActions() {
94
+        return $this->actions;
95
+    }
96
+
97
+    /**
98
+     * sort the actions by priority and name
99
+     */
100
+    private function sortActions() {
101
+        usort($this->actions, function(IAction $action1, IAction $action2) {
102
+            $prio1 = $action1->getPriority();
103
+            $prio2 = $action2->getPriority();
104
+
105
+            if ($prio1 === $prio2) {
106
+                // Ascending order for same priority
107
+                return strcasecmp($action1->getName(), $action2->getName());
108
+            }
109
+
110
+            // Descending order when priority differs
111
+            return $prio2 - $prio1;
112
+        });
113
+    }
114
+
115
+    /**
116
+     * @param array $contact key-value array containing additional properties
117
+     */
118
+    public function setProperties(array $contact) {
119
+        $this->properties = $contact;
120
+    }
121
+
122
+    /**
123
+     * @param string $key
124
+     * @return mixed
125
+     */
126
+    public function getProperty($key) {
127
+        if (!isset($this->properties[$key])) {
128
+            return null;
129
+        }
130
+        return $this->properties[$key];
131
+    }
132
+
133
+    /**
134
+     * @return array
135
+     */
136
+    public function jsonSerialize() {
137
+        $topAction = !empty($this->actions) ? $this->actions[0]->jsonSerialize() : null;
138
+        $otherActions = array_map(function(IAction $action) {
139
+            return $action->jsonSerialize();
140
+        }, array_slice($this->actions, 1));
141
+
142
+        return [
143
+            'id' => $this->id,
144
+            'fullName' => $this->fullName,
145
+            'topAction' => $topAction,
146
+            'actions' => $otherActions,
147
+            'lastMessage' => '',
148
+        ];
149
+    }
150 150
 
151 151
 }
Please login to merge, or discard this patch.
lib/public/Contacts/ContactsMenu/IEntry.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -31,30 +31,30 @@
 block discarded – undo
31 31
  */
32 32
 interface IEntry extends JsonSerializable {
33 33
 
34
-	/**
35
-	 * @since 12.0
36
-	 * @return string
37
-	 */
38
-	public function getFullName();
39
-
40
-	/**
41
-	 * @since 12.0
42
-	 * @return string[]
43
-	 */
44
-	public function getEMailAddresses();
45
-
46
-	/**
47
-	 * @since 12.0
48
-	 * @param IAction $action an action to show in the contacts menu
49
-	 */
50
-	public function addAction(IAction $action);
51
-
52
-	/**
53
-	 * Get an arbitrary property from the contact
54
-	 *
55
-	 * @since 12.0
56
-	 * @param string $key
57
-	 * @return mixed the value of the property or null
58
-	 */
59
-	public function getProperty($key);
34
+    /**
35
+     * @since 12.0
36
+     * @return string
37
+     */
38
+    public function getFullName();
39
+
40
+    /**
41
+     * @since 12.0
42
+     * @return string[]
43
+     */
44
+    public function getEMailAddresses();
45
+
46
+    /**
47
+     * @since 12.0
48
+     * @param IAction $action an action to show in the contacts menu
49
+     */
50
+    public function addAction(IAction $action);
51
+
52
+    /**
53
+     * Get an arbitrary property from the contact
54
+     *
55
+     * @since 12.0
56
+     * @param string $key
57
+     * @return mixed the value of the property or null
58
+     */
59
+    public function getProperty($key);
60 60
 }
Please login to merge, or discard this patch.
lib/public/Contacts/ContactsMenu/IAction.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -33,33 +33,33 @@
 block discarded – undo
33 33
  */
34 34
 interface IAction extends JsonSerializable {
35 35
 
36
-	/**
37
-	 * @param string $icon absolute URI to an icon
38
-	 * @since 12.0
39
-	 */
40
-	public function setIcon($icon);
36
+    /**
37
+     * @param string $icon absolute URI to an icon
38
+     * @since 12.0
39
+     */
40
+    public function setIcon($icon);
41 41
 
42
-	/**
43
-	 * @return string localized action name, e.g. 'Call'
44
-	 * @since 12.0
45
-	 */
46
-	public function getName();
42
+    /**
43
+     * @return string localized action name, e.g. 'Call'
44
+     * @since 12.0
45
+     */
46
+    public function getName();
47 47
 
48
-	/**
49
-	 * @param string $name localized action name, e.g. 'Call'
50
-	 * @since 12.0
51
-	 */
52
-	public function setName($name);
48
+    /**
49
+     * @param string $name localized action name, e.g. 'Call'
50
+     * @since 12.0
51
+     */
52
+    public function setName($name);
53 53
 
54
-	/**
55
-	 * @param int $priority priorize actions, high order ones are shown on top
56
-	 * @since 12.0
57
-	 */
58
-	public function setPriority($priority);
54
+    /**
55
+     * @param int $priority priorize actions, high order ones are shown on top
56
+     * @since 12.0
57
+     */
58
+    public function setPriority($priority);
59 59
 
60
-	/**
61
-	 * @return int priority to priorize actions, high order ones are shown on top
62
-	 * @since 12.0
63
-	 */
64
-	public function getPriority();
60
+    /**
61
+     * @return int priority to priorize actions, high order ones are shown on top
62
+     * @since 12.0
63
+     */
64
+    public function getPriority();
65 65
 }
Please login to merge, or discard this patch.