Skip to content

Commit

Permalink
Small simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
flack committed May 13, 2024
1 parent 598445d commit fef947c
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 47 deletions.
14 changes: 6 additions & 8 deletions lib/midcom/admin/help/help.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,12 @@ private function _add_virtual_files(array $files, string $component) : array
if ($component != 'midcom') {
$options['handlers'] = $this->read_component_handlers($component);
}
foreach ($options as $key => $values) {
if (!empty($values)) {
$files[$key] = [
'path' => '/' . $key,
'subject' => $this->_l10n->get('help_' . $key),
'lang' => 'en',
];
}
foreach (array_filter($options) as $key => $values) {
$files[$key] = [
'path' => '/' . $key,
'subject' => $this->_l10n->get('help_' . $key),
'lang' => 'en',
];
$this->_request_data[$key] = $values;
}

Expand Down
4 changes: 1 addition & 3 deletions lib/midcom/helper/_dbfactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ public function get_cached(string $classname, string|int $src) : midcom_core_dba
throw new midcom_error('invalid source identifier');
}

if (!isset($cache[$classname])) {
$cache[$classname] = [];
}
$cache[$classname] ??= [];

if (isset($cache[$classname][$src])) {
return $cache[$classname][$src];
Expand Down
5 changes: 1 addition & 4 deletions lib/midcom/helper/reflector/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ public static function get(string|object $src) : self
{
$identifier = get_called_class() . (is_object($src) ? get_class($src) : $src);

if (!isset(self::$_cache['instance'][$identifier])) {
self::$_cache['instance'][$identifier] = new static($src);
}
return self::$_cache['instance'][$identifier];
return self::$_cache['instance'][$identifier] ??= new static($src);
}

/**
Expand Down
5 changes: 1 addition & 4 deletions lib/midcom/services/auth/acl.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,10 +464,7 @@ public function can_do_byguid(string $privilege, string $object_guid, string $ob

$cache_key = "{$user_id}::{$object_guid}::{$privilege}";

if (!isset($cache[$cache_key])) {
$cache[$cache_key] = $this->can_do_byguid_uncached($privilege, $object_guid, $object_class, $user_id);
}
return $cache[$cache_key];
return $cache[$cache_key] ??= $this->can_do_byguid_uncached($privilege, $object_guid, $object_class, $user_id);
}

private function can_do_byguid_uncached(string $privilege, string $object_guid, string $object_class, string $user_id) : bool
Expand Down
6 changes: 2 additions & 4 deletions lib/midcom/services/indexer/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,8 @@ public function add_query(string $name, midcom_core_querybuilder $qb, $dm)
public function reindex()
{
foreach ($this->_queries as $name => [$qb, $dm]) {
$results = $qb->execute();
if (!empty($results)) {
$documents = $this->process_results($name, $results, $dm);
if (!empty($documents)) {
if ($results = $qb->execute()) {
if ($documents = $this->process_results($name, $results, $dm)) {
$this->_indexer->index($documents);
}
}
Expand Down
4 changes: 1 addition & 3 deletions lib/midgard/admin/asgard/navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,8 @@ private function _draw_select_navigation()
if (!empty($this->_object_path)) {
$this->_request_data['root_object'] = $this->_object_path[0];
$this->_request_data['navigation_type'] = $this->_object_path[0]->__mgdschema_class_name__;
} elseif (isset($this->expanded_root_types[0])) {
$this->_request_data['navigation_type'] = $this->expanded_root_types[0];
} else {
$this->_request_data['navigation_type'] = '';
$this->_request_data['navigation_type'] = $this->expanded_root_types[0] ?? '';
}

$this->_request_data['label_mapping'] = midgard_admin_asgard_plugin::get_root_classes();
Expand Down
26 changes: 10 additions & 16 deletions lib/midgard/admin/asgard/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,25 +284,19 @@ public static function get_root_classes() : array
{
static $root_classes = [];

// Return cached results
if (!empty($root_classes)) {
return $root_classes;
}

// Initialize the returnable array
$root_classes = [];

// Get the classes
$classes = midcom_helper_reflector_tree::get_root_classes();
if (empty($root_classes)) {
// Get the classes
$classes = midcom_helper_reflector_tree::get_root_classes();

// Get the translated name
foreach ($classes as $class) {
$ref = new midcom_helper_reflector($class);
$root_classes[$class] = $ref->get_class_label();
}

// Get the translated name
foreach ($classes as $class) {
$ref = new midcom_helper_reflector($class);
$root_classes[$class] = $ref->get_class_label();
asort($root_classes);
}

asort($root_classes);

return $root_classes;
}
}
7 changes: 2 additions & 5 deletions lib/midgard/admin/asgard/stylehelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,8 @@ private function _get_style_elements_and_nodes(int $style_id) : array
$style_nodes = $this->_get_nodes_using_style($style_path);

foreach ($style_nodes as $node) {
if (!isset($results['nodes'][$node->component])) {
$results['nodes'][$node->component] = [];
// Get the list of style elements for the component
$results['elements'][$node->component] = $this->_get_component_default_elements($node->component);
}
// Get the list of style elements for the component
$results['elements'][$node->component] ??= $this->_get_component_default_elements($node->component);

$results['nodes'][$node->component][] = $node;
}
Expand Down

0 comments on commit fef947c

Please sign in to comment.