Skip to content

Commit

Permalink
Use match
Browse files Browse the repository at this point in the history
  • Loading branch information
flack committed May 12, 2024
1 parent 766a049 commit 8cd424b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 28 deletions.
13 changes: 5 additions & 8 deletions lib/midcom/helper/nav/itemlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,11 @@ abstract public function get_sorted_list() : array;
public static function factory(midcom_helper_nav $nap, array $parent_node) : midcom_helper_nav_itemlist
{
$guid = $parent_node[MIDCOM_NAV_GUID];
$navorder = (int) midcom_db_parameter::get_by_objectguid($guid, 'midcom.helper.nav', 'navorder');
if ($navorder === MIDCOM_NAVORDER_ARTICLESFIRST) {
$navorder = 'articlesfirst';
} elseif ($navorder === MIDCOM_NAVORDER_SCORE) {
$navorder = 'score';
} else {
$navorder = 'topicsfirst';
}
$navorder = match ((int) midcom_db_parameter::get_by_objectguid($guid, 'midcom.helper.nav', 'navorder')) {
MIDCOM_NAVORDER_ARTICLESFIRST => 'articlesfirst',
MIDCOM_NAVORDER_SCORE => 'score',
default => 'topicsfirst'
};
$class = "midcom_helper_nav_itemlist_{$navorder}";

return new $class($nap, $parent_node[MIDCOM_NAV_ID]);
Expand Down
12 changes: 5 additions & 7 deletions lib/net/nehmer/blog/handler/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,11 @@ public function _handler_index(string $handler_id, array $args, array &$data)

$qb->add_order('metadata.published', 'DESC');

if (in_array($handler_id, ['latest', 'ajax-latest'])) {
$qb->results_per_page = $args[0];
} elseif ($handler_id == 'latest-category') {
$qb->results_per_page = $args[1];
} else {
$qb->results_per_page = $this->_config->get('index_entries');
}
$qb->results_per_page = match ($handler_id) {
'latest', 'ajax-latest' => $args[0],
'latest-category' => $args[1],
default => $this->_config->get('index_entries')
};

$this->_articles = $qb->execute();

Expand Down
26 changes: 13 additions & 13 deletions lib/org/openpsa/directmarketing/campaign/ruleresolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,19 @@ private function add_rules(array $rules, string $class)
$class = midcom::get()->dbclassloader->get_mgdschema_class_name_for_midcom_class($class);
}

if ($class == 'midgard_parameter') {
$this->add_parameter_rule($rules);
} elseif (in_array($class, [midcom::get()->config->get('person_class'), 'midgard_person', 'org_openpsa_person'])) {
$this->apply_rules('person', $rules);
} elseif (in_array($class, ['midgard_group', 'org_openpsa_organization'])) {
$this->apply_rules('group', $rules);
} elseif (in_array($class, ['midgard_member', 'org_openpsa_eventmember'])) {
$this->apply_rules('misc', $rules, $class, 'uid');
} elseif (in_array($class, ['org_openpsa_campaign_member', 'org_openpsa_campaign_message_receipt', 'org_openpsa_link_log'])) {
$this->apply_rules('misc', $rules, $class, 'person');
} else {
throw new midcom_error("class " . $class . " not supported");
}
match ($class) {
'midgard_parameter' => $this->add_parameter_rule($rules),
midcom::get()->config->get('person_class'),
'midgard_person',
'org_openpsa_person' => $this->apply_rules('person', $rules),
'midgard_group',
'org_openpsa_organization' => $this->apply_rules('group', $rules),
'midgard_member',
'org_openpsa_eventmember' => $this->apply_rules('misc', $rules, $class, 'uid'),
'org_openpsa_campaign_member',
'org_openpsa_campaign_message_receipt',
'org_openpsa_link_log' => $this->apply_rules('misc', $rules, $class, 'person')
};
}

private function apply_rules(string $type, array $rules, ...$args)
Expand Down

0 comments on commit 8cd424b

Please sign in to comment.