Type Entry and IEntry

* Fixed a docblock
* Typed the entries

Psalm happier, Roeland happier

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2021-03-04 14:30:21 +01:00
parent 3bbacb2f54
commit b14be34689
2 changed files with 22 additions and 19 deletions

View File

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
*
@ -49,56 +52,56 @@ class Entry implements IEntry {
/**
* @param string $id
*/
public function setId($id) {
public function setId(string $id): void {
$this->id = $id;
}
/**
* @param string $displayName
*/
public function setFullName($displayName) {
public function setFullName(string $displayName): void {
$this->fullName = $displayName;
}
/**
* @return string
*/
public function getFullName() {
public function getFullName(): string {
return $this->fullName;
}
/**
* @param string $address
*/
public function addEMailAddress($address) {
public function addEMailAddress(string $address): void {
$this->emailAddresses[] = $address;
}
/**
* @return string
* @return string[]
*/
public function getEMailAddresses() {
public function getEMailAddresses(): array {
return $this->emailAddresses;
}
/**
* @param string $avatar
*/
public function setAvatar($avatar) {
public function setAvatar(string $avatar): void {
$this->avatar = $avatar;
}
/**
* @return string
*/
public function getAvatar() {
public function getAvatar(): ?string {
return $this->avatar;
}
/**
* @param IAction $action
*/
public function addAction(IAction $action) {
public function addAction(IAction $action): void {
$this->actions[] = $action;
$this->sortActions();
}
@ -106,14 +109,14 @@ class Entry implements IEntry {
/**
* @return IAction[]
*/
public function getActions() {
public function getActions(): array {
return $this->actions;
}
/**
* sort the actions by priority and name
*/
private function sortActions() {
private function sortActions(): void {
usort($this->actions, function (IAction $action1, IAction $action2) {
$prio1 = $action1->getPriority();
$prio2 = $action2->getPriority();
@ -131,7 +134,7 @@ class Entry implements IEntry {
/**
* @param array $contact key-value array containing additional properties
*/
public function setProperties(array $contact) {
public function setProperties(array $contact): void {
$this->properties = $contact;
}
@ -139,7 +142,7 @@ class Entry implements IEntry {
* @param string $key
* @return mixed
*/
public function getProperty($key) {
public function getProperty(string $key) {
if (!isset($this->properties[$key])) {
return null;
}
@ -149,7 +152,7 @@ class Entry implements IEntry {
/**
* @return array
*/
public function jsonSerialize() {
public function jsonSerialize(): array {
$topAction = !empty($this->actions) ? $this->actions[0]->jsonSerialize() : null;
$otherActions = array_map(function (IAction $action) {
return $action->jsonSerialize();

View File

@ -34,25 +34,25 @@ interface IEntry extends JsonSerializable {
* @since 12.0
* @return string
*/
public function getFullName();
public function getFullName(): string;
/**
* @since 12.0
* @return string[]
*/
public function getEMailAddresses();
public function getEMailAddresses(): array;
/**
* @since 12.0
* @return string|null image URI
*/
public function getAvatar();
public function getAvatar(): ?string;
/**
* @since 12.0
* @param IAction $action an action to show in the contacts menu
*/
public function addAction(IAction $action);
public function addAction(IAction $action): void;
/**
* Get an arbitrary property from the contact
@ -61,5 +61,5 @@ interface IEntry extends JsonSerializable {
* @param string $key
* @return mixed the value of the property or null
*/
public function getProperty($key);
public function getProperty(string $key);
}