Use new code style

This commit is contained in:
David Stone
2025-02-07 19:02:33 -07:00
parent 0181024ae1
commit 8433379d90
672 changed files with 37107 additions and 45249 deletions

View File

@ -9,7 +9,7 @@
// Exit if accessed directly
defined('ABSPATH') || exit;
use \phpDocumentor\Reflection\DocBlockFactory;
use phpDocumentor\Reflection\DocBlockFactory;
/**
* Creates the REST API schema blueprint for an object based on setters.
@ -28,8 +28,7 @@ function wu_reflection_parse_object_arguments($class_name) {
* @todo add a logger.
*/
return $base_schema;
} // end if;
}
$reflector = new \ReflectionClass($class_name);
@ -43,75 +42,55 @@ function wu_reflection_parse_object_arguments($class_name) {
$db_schema = method_exists($class_name, 'get_schema') ? $class_name::get_schema() : false;
foreach ($base_schema as $column) {
try {
$doc_block = $doc_block_factory->create($reflector->getMethod("set_{$column['name']}")->getDocComment());
} catch (\Throwable $exception) {
/**
* Something went wrong trying to parse the doc-blocks.
*/
continue;
} // end try;
}
$param = $doc_block->getTagsByName('param');
if (isset($param[0]) && is_object($param[0])) {
$arguments[$column['name']] = array(
$arguments[ $column['name'] ] = array(
'description' => (string) $param[0]->getDescription(),
'type' => (string) $param[0]->getType(),
'required' => false, // Actual value set later
);
if ($db_schema) {
$db_column = wu_array_find_first_by($db_schema, 'name', $column['name']);
if ($db_column && wu_get_isset($db_column, 'type') && preg_match('/^ENUM/', (string) $db_column['type'])) {
preg_match_all("/'(.*?)'/", (string) $db_column['type'], $matches);
if (isset($matches[1])) {
$arguments[$column['name']]['enum'] = array_map('strtolower', $matches[1]);
} // end if;
} // end if;
} // end if;
$arguments[ $column['name'] ]['enum'] = array_map('strtolower', $matches[1]);
}
}
}
$option = $doc_block->getTagsByName('options');
if (isset($option[0])) {
$description = (string) $option[0]->getDescription();
if (strpos($description, '\\WP_Ultimo\\') !== false) {
$enum_options = new $description();
$arguments[$column['name']]['enum'] = array_map('strtolower', array_keys(array_flip($enum_options->get_options())));
$arguments[ $column['name'] ]['enum'] = array_map('strtolower', array_keys(array_flip($enum_options->get_options())));
} else {
$arguments[$column['name']]['enum'] = explode(',', strtolower($description));
} // end if;
} // end if;
} // end if;
} // end foreach;
$arguments[ $column['name'] ]['enum'] = explode(',', strtolower($description));
}
}
}
}
return $arguments;
} // end wu_reflection_parse_object_arguments;
}
/**
* Use php reflection to generate the documentation for the REST API.
@ -127,28 +106,19 @@ function wu_reflection_parse_arguments_from_setters($class_name, $return_schema
$arguments = array();
foreach (get_class_methods($class_name) as $setter_name) {
if (preg_match('/^set_/', $setter_name)) {
$argument = str_replace('set_', '', $setter_name);
if ($return_schema) {
$arguments[] = array(
'name' => $argument,
'type' => '',
);
} else {
$arguments[] = $argument;
} // end if;
} // end if;
} // end foreach;
}
}
}
return $arguments;
} // end wu_reflection_parse_arguments_from_setters;
}