Skip to content

Commit

Permalink
Add some more return type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
flack committed Sep 20, 2019
1 parent 6c0bb30 commit c64baf5
Show file tree
Hide file tree
Showing 42 changed files with 67 additions and 79 deletions.
2 changes: 1 addition & 1 deletion lib/midcom/admin/folder/handler/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private function _update_topic($prefix, $old_name)
return preg_replace("/{$old_name}\/\$/", "{$this->edit_topic->name}/", $prefix);
}

private function _create_topic($prefix)
private function _create_topic($prefix) : string
{
midcom::get()->uimessages->add($this->_l10n->get('midcom.admin.folder'), $this->_l10n->get('folder created'));

Expand Down
2 changes: 1 addition & 1 deletion lib/midcom/admin/rcs/handler/rcs.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected function handler_callback($handler_id)
]);
}

protected function get_object_url()
protected function get_object_url() : string
{
return midcom::get()->permalinks->create_permalink($this->object->guid);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/midcom/baseclasses/components/handler/configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

use midcom\datamanager\datamanager;
use Symfony\Component\HttpFoundation\Request;
use midcom\datamanager\controller;

/**
* midcom.datamanager based configuration
Expand Down Expand Up @@ -39,7 +40,7 @@ public function __construct()
parent::__construct();
}

private function load_controller()
private function load_controller() : controller
{
if ($schemadb_path = $this->_config->get('schemadb_config')) {
return datamanager::from_schemadb($schemadb_path)
Expand Down
5 changes: 2 additions & 3 deletions lib/midcom/baseclasses/components/handler/dataexport.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,14 @@ abstract class midcom_baseclasses_components_handler_dataexport extends midcom_b
* @param array $data The local request data.
* @return midcom\datamanager\schemadb[]
*/
abstract public function _load_schemadbs($handler_id, array &$args, array &$data);
abstract public function _load_schemadbs($handler_id, array &$args, array &$data) : array;

/**
* @param mixed $handler_id The ID of the handler.
* @param array $args The argument list.
* @param array $data The local request data.
* @return array
*/
abstract public function _load_data($handler_id, array &$args, array &$data);
abstract public function _load_data($handler_id, array &$args, array &$data) : array;

/**
* @param mixed $handler_id The ID of the handler.
Expand Down
6 changes: 4 additions & 2 deletions lib/midcom/baseclasses/components/handler/rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,10 @@ private function _check_object()
}
}

// the classname of the object we expect
abstract public function get_object_classname();
/**
* the classname of the object we expect
*/
abstract public function get_object_classname() : string;

// these RESTful methods might be overwritten, but contain a default implementation
public function handle_get()
Expand Down
8 changes: 4 additions & 4 deletions lib/midcom/core/dbaobject.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public static function new_collector($domain = null, $value = null) : midcom_cor
* @param mixed $src GUID of object (ids work but are discouraged)
* @return static Reference to the object
*/
public static function &get_cached($src)
public static function &get_cached($src) : self
{
return midcom::get()->dbfactory->get_cached(get_called_class(), $src);
}
Expand Down Expand Up @@ -300,7 +300,7 @@ public function is_in_tree($root, $id)
{
return $this->__object->is_in_tree($root, $id);
}
public function has_dependents()
public function has_dependents() : bool
{
return $this->__object->has_dependents();
}
Expand Down Expand Up @@ -403,12 +403,12 @@ public function unapprove() : bool
return false;
}

public function get_properties()
public function get_properties() : array
{
return midcom_helper_reflector::get_object_fieldnames($this);
}

public static function new_reflection_property()
public static function new_reflection_property() : midgard_reflection_property
{
$classname = midcom::get()->dbclassloader->get_mgdschema_class_name_for_midcom_class(get_called_class());
return call_user_func([$classname, 'new_reflection_property']);
Expand Down
2 changes: 1 addition & 1 deletion lib/midcom/db/group.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class midcom_db_group extends midcom_core_dbaobject
midcom_db_member::class => 'gid'
];

public function get_label()
public function get_label() : string
{
return $this->official;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/midcom/db/member.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class midcom_db_member extends midcom_core_dbaobject

public $_use_rcs = false;

public function get_label()
public function get_label() : string
{
try {
$person = new midcom_db_person($this->uid);
Expand Down
2 changes: 1 addition & 1 deletion lib/midcom/db/parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static function get_by_objectguid($objectguid, $domain, $name)
return $parameter_cache[$cache_key];
}

public function get_label()
public function get_label() : string
{
return "{$this->domain} {$this->name}";
}
Expand Down
2 changes: 1 addition & 1 deletion lib/midcom/db/person.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private function _update_computed_members()
}
}

public function get_label()
public function get_label() : string
{
return $this->rname;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/midcom/db/snippet.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class midcom_db_snippet extends midcom_core_dbaobject
public $__midcom_class_name__ = __CLASS__;
public $__mgdschema_class_name__ = 'midgard_snippet';

public function get_icon()
public function get_icon() : string
{
return 'file-code-o';
}
Expand Down
10 changes: 2 additions & 8 deletions lib/midcom/db/topic.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,9 @@ class midcom_db_topic extends midcom_core_dbaobject
public $__midcom_class_name__ = __CLASS__;
public $__mgdschema_class_name__ = 'midgard_topic';

public function get_label()
public function get_label() : string
{
if ($this->extra) {
return $this->extra;
}
if ($this->name) {
return $this->name;
}
return '#' . $this->id;
return $this->extra ?: $this->name ?: '#' . $this->id;
}

public function _on_loaded()
Expand Down
6 changes: 3 additions & 3 deletions lib/midcom/helper/nav/item.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ abstract class midcom_helper_nav_item

protected $loaded = false;

abstract protected function prepare_data();
abstract protected function prepare_data() : array;

abstract public function is_readable_by($user_id);

Expand Down Expand Up @@ -90,7 +90,7 @@ private function translate_name($name)
*/
public function is_object_visible() : bool
{
if ($this->get_data() === null) {
if (empty($this->get_data())) {
debug_add('Got a null value as napdata, so this object does not have any NAP info, so we cannot display it.');
return false;
}
Expand All @@ -115,7 +115,7 @@ public function is_object_visible() : bool
return true;
}

public function get_data()
public function get_data() : array
{
if (!$this->loaded) {
$this->data = $this->prepare_data();
Expand Down
3 changes: 1 addition & 2 deletions lib/midcom/helper/nav/itemlist/score.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ public function get_sorted_list() : array
*
* @param array $a Navigation item array
* @param array $b Navigation item array
* @return integer Preferred order
*/
private function sort_cmp($a, $b)
private function sort_cmp($a, $b) : int
{
return $b[MIDCOM_NAV_SCORE] <=> $a[MIDCOM_NAV_SCORE];
}
Expand Down
2 changes: 1 addition & 1 deletion lib/midcom/helper/nav/leaf.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function write_to_cache()
return $this->get_data();
}

protected function prepare_data()
protected function prepare_data() : array
{
$topic = $this->node->object;

Expand Down
6 changes: 3 additions & 3 deletions lib/midcom/helper/nav/node.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private function write_leaves_to_cache($leaves)
$this->get_cache()->put_leaves("{$this->id}-leaves", $cachedata);
}

protected function prepare_data()
protected function prepare_data() : array
{
$data = $this->get_cache()->get_node($this->topic_id);

Expand All @@ -127,8 +127,8 @@ protected function prepare_data()
midcom::get()->auth->drop_sudo();

if ($data === null) {
debug_add('We got null for this node, so we do not have any NAP information, returning null directly.');
return null;
debug_add('We got null for this node, so we do not have any NAP information, returning directly.');
return [];
}

$this->get_cache()->put_node($data[MIDCOM_NAV_ID], $data);
Expand Down
6 changes: 1 addition & 5 deletions lib/midcom/helper/toolbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,7 @@ public function is_rendered() : bool
return $this->rendered;
}

/**
*
* @return string
*/
public function get_label()
public function get_label() : string
{
return $this->label;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/midcom/services/rcs/handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ abstract class midcom_services_rcs_handler extends midcom_baseclasses_components

protected $url_prefix = '';

abstract protected function get_object_url();
abstract protected function get_object_url() : string;

abstract protected function handler_callback($handler_id);

Expand Down
2 changes: 1 addition & 1 deletion lib/midgard/admin/asgard/handler/object/rcs.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class midgard_admin_asgard_handler_object_rcs extends midcom_services_rcs_handle

protected $url_prefix = '__mfa/asgard/object/rcs/';

protected function get_object_url()
protected function get_object_url() : string
{
return $this->router->generate('object_open', ['guid' => $this->object->guid]);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/net/nemein/tag/link.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function get_parent_guid_uncached()
return $parent->guid;
}

public function get_label()
public function get_label() : string
{
$mc = net_nemein_tag_tag_dba::new_collector('id', $this->tag);
$tag_guids = $mc->get_values('tag');
Expand Down
2 changes: 1 addition & 1 deletion lib/net/nemein/tag/tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class net_nemein_tag_tag_dba extends midcom_core_dbaobject

public $_use_rcs = false;

public function get_label()
public function get_label() : string
{
return $this->tag;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/org/openpsa/calendar/event.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class org_openpsa_calendar_event_dba extends midcom_core_dbaobject
public $ignorebusy_em = false;
public $rob_tentative = false;

public function get_label()
public function get_label() : string
{
if ($this->start == 0) {
return $this->title;
Expand Down
2 changes: 1 addition & 1 deletion lib/org/openpsa/calendar/event/member.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function _on_deleted()
}
}

public function get_label()
public function get_label() : string
{
$person = new midcom_db_person($this->uid);
$event = new org_openpsa_calendar_event_dba($this->eid);
Expand Down
2 changes: 1 addition & 1 deletion lib/org/openpsa/calendar/event/resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class org_openpsa_calendar_event_resource_dba extends midcom_core_dbaobject
/**
* Human-readable label for cases like Asgard navigation
*/
public function get_label()
public function get_label() : string
{
if ($this->resource) {
$resource = new org_openpsa_calendar_resource_dba($this->resource);
Expand Down
7 changes: 2 additions & 5 deletions lib/org/openpsa/contacts/group.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,9 @@ public function __set($name, $value)
parent::__set($name, $value);
}

public function get_label()
public function get_label() : string
{
if ($this->official) {
return $this->official;
}
return $this->name;
return $this->official ?: $this->name;
}

public function render_link() : string
Expand Down
4 changes: 2 additions & 2 deletions lib/org/openpsa/contacts/handler/rest/person.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
*/
class org_openpsa_contacts_handler_rest_person extends midcom_baseclasses_components_handler_rest
{
public function get_object_classname()
public function get_object_classname() : string
{
return "org_openpsa_contacts_person_dba";
return org_openpsa_contacts_person_dba::class;
}

public function handle_create()
Expand Down
2 changes: 1 addition & 1 deletion lib/org/openpsa/contacts/person.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function _on_deleting()
return parent::_on_deleting();
}

public function get_label_property()
public function get_label_property() : string
{
return 'rname';
}
Expand Down
2 changes: 1 addition & 1 deletion lib/org/openpsa/directmarketing/campaign/member.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct($id = null)
/**
* Human-readable label for cases like Asgard navigation
*/
public function get_label()
public function get_label() : string
{
if ($this->person) {
$person = new org_openpsa_contacts_person_dba($this->person);
Expand Down
4 changes: 2 additions & 2 deletions lib/org/openpsa/directmarketing/handler/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class org_openpsa_directmarketing_handler_export extends midcom_baseclasses_comp

protected $_schema = 'export';

public function _load_schemadbs($handler_id, array &$args, array &$data)
public function _load_schemadbs($handler_id, array &$args, array &$data) : array
{
// Try to load the correct campaign
$data['campaign'] = $this->load_campaign($args[0]);
Expand All @@ -40,7 +40,7 @@ public function _load_schemadbs($handler_id, array &$args, array &$data)
];
}

public function _load_data($handler_id, array &$args, array &$data)
public function _load_data($handler_id, array &$args, array &$data) : array
{
$rows = [];
$qb_members = org_openpsa_directmarketing_campaign_member_dba::new_query_builder();
Expand Down
2 changes: 1 addition & 1 deletion lib/org/openpsa/documents/document.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private function _update_directory_timestamp()
}
}

public function get_label()
public function get_label() : string
{
return $this->title;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/org/openpsa/invoices/billing/data.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function render_address()
echo "</div>\n";
}

public function get_label()
public function get_label() : string
{
$label = midcom::get()->i18n->get_l10n('org.openpsa.invoices')->get('billing data') . ' (';
if ($contact = $this->get_contact()) {
Expand Down
4 changes: 2 additions & 2 deletions lib/org/openpsa/invoices/handler/rest/billingdata.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
*/
class org_openpsa_invoices_handler_rest_billingdata extends midcom_baseclasses_components_handler_rest
{
public function get_object_classname()
public function get_object_classname() : string
{
return "org_openpsa_invoices_billing_data_dba";
return org_openpsa_invoices_billing_data_dba::class;
}

private function get_billingdata($linkGuid) : org_openpsa_invoices_billing_data_dba
Expand Down
Loading

0 comments on commit c64baf5

Please sign in to comment.