Skip to content
Snippets Groups Projects
Commit 733ad541 authored by Tim Rohaly's avatar Tim Rohaly
Browse files

Issue #3478883 by tr: Parameter typing and return type hints

parent 5aac9552
No related branches found
No related tags found
1 merge request!14Issue #3478883 by tr: Parameter typing and return type hints
Pipeline #301958 failed
......@@ -7,6 +7,7 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsStyle;
use Drupal\views\Plugin\views\field\BulkForm;
use Drupal\views\Plugin\views\field\FieldHandlerInterface;
use Drupal\views\Plugin\views\style\Table as ViewsTable;
use Drupal\views\Render\ViewsRenderPipelineMarkup;
use Drupal\views\ResultRow;
......@@ -456,7 +457,7 @@ class Table extends ViewsTable {
/**
* Filters out rows from the table based on a field cell matching a regexp.
*/
protected function applyRowFilters() {
protected function applyRowFilters(): void {
$field_handlers = $this->view->field;
foreach ($this->options['info'] as $field_name => $options) {
if (!empty($options['has_aggr']) && in_array('views_aggregator_row_filter', $options['aggr'])) {
......@@ -471,7 +472,7 @@ class Table extends ViewsTable {
* @return array
* An array of aggregated groups.
*/
protected function aggregateGroups() {
protected function aggregateGroups(): array {
$field_handlers = $this->view->field;
// Find the one column to group by and execute the grouping.
foreach ($this->options['info'] as $field_name => $options) {
......@@ -496,7 +497,7 @@ class Table extends ViewsTable {
* @return array
* Functions used for aggregation.
*/
protected function collectAggregationFunctions() {
protected function collectAggregationFunctions(): array {
$functions = [];
foreach ($this->options['info'] as $field_name => $options) {
// Make a list of the group and column functions to call for this field.
......@@ -531,7 +532,7 @@ class Table extends ViewsTable {
* @return array
* Function return values.
*/
protected function executeAggregationFunctions(array $groups, array $functions) {
protected function executeAggregationFunctions(array $groups, array $functions): array {
$field_handlers = $this->view->field;
$values = [];
foreach ($functions as $field_name => $field_functions) {
......@@ -602,7 +603,7 @@ class Table extends ViewsTable {
/**
* Returns the raw or rendered result at the intersection of column and row.
*
* @param object $field_handler
* @param \Drupal\views\Plugin\views\field\FieldHandlerInterface $field_handler
* The handler associated with the result column being requested.
* @param int $row_num
* The result row number.
......@@ -612,7 +613,7 @@ class Table extends ViewsTable {
* @return string
* Returns empty string if there are no results for the requested row_num.
*/
public function getCell($field_handler, $row_num, $render = FALSE) {
public function getCell(FieldHandlerInterface $field_handler, int $row_num, bool $render = FALSE): string {
// Some functions need rendered values (e.g. enumerate).
// For the rendered_fields array we need id, otherwise take entity_field.
if (isset($field_handler->options['entity_field']) && $render == FALSE) {
......@@ -647,9 +648,9 @@ class Table extends ViewsTable {
* Should normally not be called, especially not for
* "Global: Custom text" fields.
*
* @param object $field_handler
* @param \Drupal\views\Plugin\views\field\FieldHandlerInterface $field_handler
* The handler associated with the result column being requested.
* @param object $result_row
* @param \Drupal\views\ResultRow $result_row
* The result row.
* @param bool $compressed
* If the result is a (nested) array, return the first primitive value.
......@@ -657,7 +658,7 @@ class Table extends ViewsTable {
* @return string
* The raw contents of the cell.
*/
private function getCellRaw($field_handler, $result_row, $compressed = TRUE) {
private function getCellRaw(FieldHandlerInterface $field_handler, ResultRow $result_row, bool $compressed = TRUE): string {
if (isset($field_handler->options['entity_field'])) {
$field_name = $field_handler->options['entity_field'];
}
......@@ -742,14 +743,14 @@ class Table extends ViewsTable {
/**
* This is needed.
*/
public function getFormats() {
public function getFormats(): array {
return [];
}
/**
* Render and set a raw value on the table cell in specified column and row.
*
* @param object $field_handler
* @param \Drupal\views\Plugin\views\field\FieldHandlerInterface $field_handler
* The field handler associated with the table column being requested.
* @param int $row_num
* The result row number. Must be specified.
......@@ -762,7 +763,7 @@ class Table extends ViewsTable {
* @return mixed
* The rendered value.
*/
public function setCell($field_handler, $row_num, $new_values, $separator) {
public function setCell(FieldHandlerInterface $field_handler, int $row_num, $new_values, string $separator) {
$rendered_value = FALSE;
if (isset($field_handler->options['entity_field'])) {
......@@ -813,9 +814,9 @@ class Table extends ViewsTable {
/**
* Returns the rendered value for a new (raw) value of a table cell.
*
* @param object $field_handler
* @param \Drupal\views\Plugin\views\field\FieldHandlerInterface $field_handler
* The handler associated with the field/table-column being requested.
* @param int $row_num
* @param int|null $row_num
* The result row number.
* @param mixed $new_values
* The raw value or array of raw values to render.
......@@ -825,7 +826,7 @@ class Table extends ViewsTable {
* @return mixed
* The rendered new value or FALSE if the value could not be rendered.
*/
protected function renderNewValue($field_handler, $row_num, $new_values, $separator) {
protected function renderNewValue(FieldHandlerInterface $field_handler, ?int $row_num, $new_values, string $separator) {
$new_values = is_array($new_values) ? $new_values : [$new_values];
// If the field_handler belongs to an entity Field (as in the field module),
......@@ -904,78 +905,78 @@ class Table extends ViewsTable {
/**
* Returns whether the supplied field is a standard Views field.
*
* @param object $field_handler
* @param \Drupal\views\Plugin\views\field\FieldHandlerInterface $field_handler
* The object belonging to the View result field.
*
* @return bool
* TRUE if the field is a standard Views field.
*/
protected function isStandardField($field_handler) {
protected function isStandardField(FieldHandlerInterface $field_handler): bool {
return ($field_handler->getPluginId() === 'field');
}
/**
* Checks if the field is a Views field of type "Global: Custom text".
*
* @param object $field_handler
* @param \Drupal\views\Plugin\views\field\FieldHandlerInterface $field_handler
* The object belonging to the View result field.
*
* @return bool
* TRUE if the field is of type "Global: Custom text".
*/
protected function isCustomTextField($field_handler) {
protected function isCustomTextField(FieldHandlerInterface $field_handler): bool {
return ($field_handler->getPluginId() === 'custom');
}
/**
* Checks if the field is a Views field of type "Global: Custom text".
*
* @param object $field_handler
* @param \Drupal\views\Plugin\views\field\FieldHandlerInterface $field_handler
* The object belonging to the View result field.
*
* @return bool
* TRUE if the field is of type "Global: Custom text".
*/
protected function isViewsFieldView($field_handler) {
protected function isViewsFieldView(FieldHandlerInterface $field_handler): bool {
return ($field_handler->getPluginId() === 'view');
}
/**
* Checks if the field is a Webform Submission Data Numeric field.
*
* @param object $field_handler
* @param \Drupal\views\Plugin\views\field\FieldHandlerInterface $field_handler
* The object belonging to the View result field.
*
* @return bool
* TRUE if the field is a Webform Submission Data Numeric field.
*/
protected function isWebformNumeric($field_handler) {
protected function isWebformNumeric(FieldHandlerInterface $field_handler): bool {
return ($field_handler->getPluginId() === 'webform_submission_field_numeric');
}
/**
* Checks if the field is a Webform Submission Data field.
*
* @param object $field_handler
* @param \Drupal\views\Plugin\views\field\FieldHandlerInterface $field_handler
* The object belonging to the View result field.
*
* @return bool
* TRUE if the field is a Webform Submission Data field.
*/
protected function isWebformField($field_handler) {
protected function isWebformField(FieldHandlerInterface $field_handler): bool {
return ($field_handler->getPluginId() === 'webform_submission_field');
}
/**
* Checks if the field comes from a Commerce entity.
*
* @param object $field_handler
* @param \Drupal\views\Plugin\views\field\FieldHandlerInterface $field_handler
* The object belonging to the View result field.
*
* @return bool
* TRUE if the field is from a Commerce entity.
*/
protected function isCommerceField($field_handler) {
protected function isCommerceField(FieldHandlerInterface $field_handler): bool {
if (isset($field_handler->definition['entity_type'])) {
return (substr($field_handler->definition['entity_type'], 0, 9) === 'commerce_');
}
......@@ -987,7 +988,7 @@ class Table extends ViewsTable {
/**
* Returns the rendered representation for a new webform value.
*
* @param object $field_handler
* @param \Drupal\views\Plugin\views\field\FieldHandlerInterface $field_handler
* The webform handler associated with the
* field/table-column being requested.
* @param int $row_num
......@@ -1000,7 +1001,7 @@ class Table extends ViewsTable {
* @return string
* The rendered value.
*/
protected function renderNewWebformValue($field_handler, $row_num, array $new_values, $separator) {
protected function renderNewWebformValue(FieldHandlerInterface $field_handler, int $row_num, array $new_values, string $separator) {
$result_row = isset($row_num) ? $field_handler->view->result[$row_num] : reset($field_handler->view->result);
$nid = $field_handler->options['id'];
if (isset($field_handler->options['entity_field'])) {
......@@ -1052,9 +1053,9 @@ class Table extends ViewsTable {
*
* The field will be rendered with appropriate CSS classes, without label.
*
* @param object $field_handler
* @param \Drupal\views\Plugin\views\field\FieldHandlerInterface $field_handler
* The views_handler_field_field object belonging to the View result field.
* @param int $row_num
* @param int|null $row_num
* The view result row number to change. Pass NULL to simply render
* $raw_value outside the context of a View, without affecting any rows.
* @param mixed $raw_value
......@@ -1062,10 +1063,10 @@ class Table extends ViewsTable {
* If NULL the row value of the field is re-rendered using its current
* (raw) value.
*
* @return string
* @return string|false
* The rendered value or FALSE, if the type of field is not supported.
*/
protected function renderFromRaw($field_handler, $row_num = NULL, $raw_value = NULL) {
protected function renderFromRaw(FieldHandlerInterface $field_handler, ?int $row_num = NULL, $raw_value = NULL): string|false {
if (isset($field_handler->options['entity_field'])) {
$field_name = $field_handler->options['entity_field'];
}
......@@ -1147,7 +1148,7 @@ class Table extends ViewsTable {
* @param int $group_aggregation_results
* Options flag, whether to aggregate the values or not.
*/
protected function setAggregatedGroupValues(array $groups, array $values, $group_aggregation_results) {
protected function setAggregatedGroupValues(array $groups, array $values, int $group_aggregation_results): void {
$subtotals = [];
$label_prefix = ($this->options['group_aggregation']['result_label_prefix']) ? $this->options['group_aggregation']['result_label_prefix'] : '';
$label_suffix = ($this->options['group_aggregation']['result_label_suffix']) ? $this->options['group_aggregation']['result_label_suffix'] : '';
......@@ -1201,8 +1202,13 @@ class Table extends ViewsTable {
*
* @param array $values
* An array of field value arrays, indexed by field name and 'column'.
*
* @return array
* An array of totals indexed by field name.
*
* @todo The return value description is just a guess.
*/
protected function setTotalsRow(array $values) {
protected function setTotalsRow(array $values): array {
$totals = [];
foreach ($values as $field_name => $group) {
if (!empty($this->options['info'][$field_name]['has_aggr_column']) && isset($group['column'])) {
......@@ -1318,7 +1324,7 @@ class Table extends ViewsTable {
* @return bool
* TRUE, if the field is renderable through its native function.
*/
public function isRenderable($field_name, $is_column = FALSE) {
public function isRenderable(string $field_name, bool $is_column = FALSE): bool {
if (empty($this->options['info'][$field_name][$is_column ? 'has_aggr_column' : 'has_aggr'])) {
return TRUE;
}
......@@ -1400,7 +1406,7 @@ class Table extends ViewsTable {
* The compare code indicating whether $row1 is smaller than (-1), equal
* to (0) or greater than (1) $row2.
*/
protected function compareResultRows(ResultRow $row1, ResultRow $row2) {
protected function compareResultRows(ResultRow $row1, ResultRow $row2): int {
// The sorting data may be raw or rendered, while the sorting style may be
// alphabetical or numeric.
......@@ -1474,7 +1480,7 @@ class Table extends ViewsTable {
/**
* Set correct counter field order after sorting.
*/
private function fixCounterFields() {
private function fixCounterFields(): void {
// Get the list of counter fields.
$fields = [];
foreach ($this->view->field as $field_name => $properties) {
......
......@@ -9,13 +9,14 @@ use Drupal\Component\Utility\Html;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Drupal\bootstrap\Bootstrap;
use Drupal\views\Plugin\views\field\FieldHandlerInterface;
require_once __DIR__ . '/views_aggregator_functions.inc';
/**
* Implements hook_help().
*/
function views_aggregator_help($route_name, RouteMatchInterface $route_match) {
function views_aggregator_help(string $route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.views_aggregator':
$module_handler = \Drupal::service('module_handler');
......@@ -32,7 +33,7 @@ function views_aggregator_help($route_name, RouteMatchInterface $route_match) {
/**
* Implements hook_theme().
*/
function views_aggregator_theme() {
function views_aggregator_theme(): array {
return [
'views_aggregator_plugin_style_table' => [
'render element' => 'form',
......@@ -50,7 +51,7 @@ function views_aggregator_theme() {
* @return array
* An array of aggregation function info.
*/
function views_aggregator_get_aggregation_functions_info($name = NULL) {
function views_aggregator_get_aggregation_functions_info(?string $name = NULL): array {
$aggregation_functions = &drupal_static(__FUNCTION__);
......@@ -76,7 +77,7 @@ function views_aggregator_get_aggregation_functions_info($name = NULL) {
/**
* Returns the result value at the intersection of column and row.
*
* @param object $field_handler
* @param \Drupal\views\Plugin\views\field\FieldHandlerInterface $field_handler
* The handler associated with the table column being requested.
* @param int $row_num
* Index into the View result rows array.
......@@ -86,7 +87,7 @@ function views_aggregator_get_aggregation_functions_info($name = NULL) {
* @return string
* The content of the cell
*/
function views_aggregator_get_cell($field_handler, $row_num, $rendered = FALSE) {
function views_aggregator_get_cell(FieldHandlerInterface $field_handler, int $row_num, bool $rendered = FALSE): string {
if (isset($field_handler->view->style_plugin)) {
return $field_handler->view->style_plugin->getCell($field_handler, $row_num, $rendered);
}
......
......@@ -9,10 +9,13 @@
* hook_views_aggregation_functions_info()
*/
use Drupal\views\Plugin\views\field\FieldHandlerInterface;
use Drupal\views\Plugin\views\style\StylePluginBase;
/**
* Implements hook_views_aggregation_functions_info().
*/
function views_aggregator_views_aggregation_functions_info() {
function views_aggregator_views_aggregation_functions_info(): array {
$functions = [
// The first two are special and must be executed before the others.
'views_aggregator_row_filter' => [
......@@ -93,14 +96,14 @@ function views_aggregator_views_aggregation_functions_info() {
*
* Matching takes place on the raw values (1000, rather than "$ 1,000").
*
* @param object $views_plugin_style
* @param \Drupal\views\Plugin\views\style\StylePluginBase $views_plugin_style
* An array of groups of rows, each group indexed by group value.
* @param object $field_handler
* @param \Drupal\views\Plugin\views\field\FieldHandlerInterface $field_handler
* The handler for the view column to count groups members in.
* @param string $regexp
* If empty all result rows are kept.
*/
function views_aggregator_row_filter($views_plugin_style, $field_handler, $regexp = NULL) {
function views_aggregator_row_filter(StylePluginBase $views_plugin_style, FieldHandlerInterface $field_handler, ?string $regexp = NULL) {
if (empty($regexp)) {
return;
}
......@@ -124,9 +127,9 @@ function views_aggregator_row_filter($views_plugin_style, $field_handler, $regex
* Its parameters and return value are different from the other aggregation
* functions.
*
* @param object $view_results
* @param \Drupal\views\ResultRow[] $view_results
* The result rows as they appear on the view object.
* @param object $field_handler
* @param \Drupal\views\Plugin\views\field\FieldHandlerInterface $field_handler
* The handler for the view column to group rows on.
* @param string $case
* Whether group-inclusion is case-sensitive (the default).
......@@ -134,7 +137,7 @@ function views_aggregator_row_filter($views_plugin_style, $field_handler, $regex
* @return array
* An array of groups, keyed by group value first and row number second.
*/
function views_aggregator_group_and_compress($view_results, $field_handler, $case = 'case-sensitive') {
function views_aggregator_group_and_compress(array $view_results, FieldHandlerInterface $field_handler, string $case = 'case-sensitive'): array {
$groups = [];
$is_set = FALSE;
$is_ci = (strcasecmp($case, 'case-insensitive') === 0) || ($case == t('case-insensitive'));
......@@ -184,7 +187,7 @@ function views_aggregator_group_and_compress($view_results, $field_handler, $cas
*
* @param array $groups
* An array of groups of rows, each group indexed by group value.
* @param object $field_handler
* @param \Drupal\views\Plugin\views\field\FieldHandlerInterface $field_handler
* The handler for the view column to find the minimum in.
* @param int $precision_group
* The number of decimals, if specified.
......@@ -194,7 +197,7 @@ function views_aggregator_group_and_compress($view_results, $field_handler, $cas
* @return array
* An array of values, one for each group and one for the column.
*/
function views_aggregator_average(array $groups, $field_handler, $precision_group, $precision_column) {
function views_aggregator_average(array $groups, FieldHandlerInterface $field_handler, int $precision_group, int $precision_column): array {
$values = [];
$sum_column = 0.0;
$count_column = 0;
......@@ -224,7 +227,7 @@ function views_aggregator_average(array $groups, $field_handler, $precision_grou
*
* @param array $groups
* An array of groups of rows, each group indexed by group value.
* @param object $field_handler
* @param \Drupal\views\Plugin\views\field\FieldHandlerInterface $field_handler
* The handler for the view column to count groups members in.
* @param string $group_regexp
* An optional regexp to count, if omitted all non-empty group values count.
......@@ -234,7 +237,7 @@ function views_aggregator_average(array $groups, $field_handler, $precision_grou
* @return array
* An array of values, one for each group and one for the column.
*/
function views_aggregator_count(array $groups, $field_handler, $group_regexp = NULL, $column_regexp = NULL) {
function views_aggregator_count(array $groups, FieldHandlerInterface $field_handler, ?string $group_regexp = NULL, ?string $column_regexp = NULL): array {
$values = [];
$count_column = 0;
......@@ -272,7 +275,7 @@ function views_aggregator_count(array $groups, $field_handler, $group_regexp = N
*
* @param array $groups
* An array of groups of rows, each group indexed by group value.
* @param object $field_handler
* @param \Drupal\views\Plugin\views\field\FieldHandlerInterface $field_handler
* The handler for the view column to count groups members in.
* @param string $group_regexp
* An optional regexp to count, if omitted all non-empty group values count.
......@@ -282,7 +285,7 @@ function views_aggregator_count(array $groups, $field_handler, $group_regexp = N
* @return array
* An array of values, one for each group and one for the column.
*/
function views_aggregator_count_unique(array $groups, $field_handler, $group_regexp = NULL, $column_regexp = NULL) {
function views_aggregator_count_unique(array $groups, FieldHandlerInterface $field_handler, ?string $group_regexp = NULL, ?string $column_regexp = NULL): array {
$values = [];
$count_column = 0;
......@@ -324,7 +327,7 @@ function views_aggregator_count_unique(array $groups, $field_handler, $group_reg
*
* @param array $groups
* An array of groups of rows, each group indexed by group value.
* @param object $field_handler
* @param \Drupal\views\Plugin\views\field\FieldHandlerInterface $field_handler
* The handler for the view column to find members of the group.
* @param string $separator_group
* The separator to use in group enumerations, defaults to '<br/>'.
......@@ -334,7 +337,7 @@ function views_aggregator_count_unique(array $groups, $field_handler, $group_reg
* @return array
* An array of values, one for each group.
*/
function views_aggregator_enumerate(array $groups, $field_handler, $separator_group, $separator_column) {
function views_aggregator_enumerate(array $groups, FieldHandlerInterface $field_handler, string $separator_group, string $separator_column): array {
return _views_aggregator_enumerate($groups, $field_handler, $separator_group, $separator_column, TRUE, FALSE);
}
......@@ -345,7 +348,7 @@ function views_aggregator_enumerate(array $groups, $field_handler, $separator_gr
*
* @param array $groups
* An array of groups of rows, each group indexed by group value.
* @param object $field_handler
* @param \Drupal\views\Plugin\views\field\FieldHandlerInterface $field_handler
* The handler for the view column to find members of the group.
* @param string $separator_group
* The separator to use in group enumerations, defaults to '<br/>'.
......@@ -355,7 +358,7 @@ function views_aggregator_enumerate(array $groups, $field_handler, $separator_gr
* @return array
* An array of values, one for each group.
*/
function views_aggregator_enumerate_raw(array $groups, $field_handler, $separator_group, $separator_column) {
function views_aggregator_enumerate_raw(array $groups, FieldHandlerInterface $field_handler, string $separator_group, string $separator_column): array {
return _views_aggregator_enumerate($groups, $field_handler, $separator_group, $separator_column, FALSE, TRUE);
}
......@@ -364,7 +367,7 @@ function views_aggregator_enumerate_raw(array $groups, $field_handler, $separato
*
* @param array $groups
* An array of groups of rows, each group indexed by group value.
* @param object $field_handler
* @param \Drupal\views\Plugin\views\field\FieldHandlerInterface $field_handler
* The handler for the view column to find members of the group.
* @param string $separator_group
* The separator to use in group enumerations, defaults to '<br/>'.
......@@ -378,7 +381,7 @@ function views_aggregator_enumerate_raw(array $groups, $field_handler, $separato
* @return array
* An array of values, one for each group.
*/
function _views_aggregator_enumerate(array $groups, $field_handler, $separator_group, $separator_column, $sort = TRUE, $allow_duplicates = FALSE) {
function _views_aggregator_enumerate(array $groups, FieldHandlerInterface $field_handler, string $separator_group, string $separator_column, bool $sort = TRUE, bool $allow_duplicates = FALSE): array {
$separator_group = empty($separator_group) ? '<br/>' : $separator_group;
$separator_column = empty($separator_column) ? '<br/>' : $separator_column;
$values = ['column' => []];
......@@ -419,13 +422,13 @@ function _views_aggregator_enumerate(array $groups, $field_handler, $separator_g
*
* @param array $groups
* An array of groups of rows, each group indexed by group value.
* @param object $field_handler
* @param \Drupal\views\Plugin\views\field\FieldHandlerInterface $field_handler
* The handler for the view column to find the first group member in.
*
* @return array
* An empty array.
*/
function views_aggregator_first(array $groups, $field_handler) {
function views_aggregator_first(array $groups, FieldHandlerInterface $field_handler): array {
// This is the default operation, so nothing to do, except for Webforms.
$values = [];
foreach ($groups as $group => $rows) {
......@@ -441,13 +444,13 @@ function views_aggregator_first(array $groups, $field_handler) {
*
* @param array $groups
* An array of groups of rows, each group indexed by group value.
* @param object $field_handler
* @param \Drupal\views\Plugin\views\field\FieldHandlerInterface $field_handler
* The handler for the view column to find the maximum groups member in.
*
* @return array
* An array of values, one for each group, plus the 'column' group.
*/
function views_aggregator_maximum(array $groups, $field_handler) {
function views_aggregator_maximum(array $groups, FieldHandlerInterface $field_handler): array {
$values = [];
foreach ($groups as $group => $rows) {
......@@ -486,13 +489,13 @@ function views_aggregator_maximum(array $groups, $field_handler) {
*
* @param array $groups
* An array of groups of rows, each group indexed by group value.
* @param object $field_handler
* @param \Drupal\views\Plugin\views\field\FieldHandlerInterface $field_handler
* The handler for the view column to calculate the median for.
*
* @return array
* An array of values, one for each group, plus the 'column' group.
*/
function views_aggregator_median(array $groups, $field_handler) {
function views_aggregator_median(array $groups, FieldHandlerInterface $field_handler): array {
$values = [];
$column_cells = [];
foreach ($groups as $group => $rows) {
......@@ -523,13 +526,13 @@ function views_aggregator_median(array $groups, $field_handler) {
*
* @param array $groups
* An array of groups of rows, each group indexed by group value.
* @param object $field_handler
* @param \Drupal\views\Plugin\views\field\FieldHandlerInterface $field_handler
* The handler for the view column to find the minimum groups member in.
*
* @return array
* An array of values, one for each group, plus the 'column' group.
*/
function views_aggregator_minimum(array $groups, $field_handler) {
function views_aggregator_minimum(array $groups, FieldHandlerInterface $field_handler): array {
$values = [];
foreach ($groups as $group => $rows) {
$is_first = TRUE;
......@@ -565,7 +568,7 @@ function views_aggregator_minimum(array $groups, $field_handler) {
*
* @param array $groups
* An array of groups of rows, each group indexed by group value.
* @param object $field_handler
* @param \Drupal\views\Plugin\views\field\FieldHandlerInterface $field_handler
* The handler for the view column.
* @param string $separator_group
* The range separator between minimum and maximum values of the group range,
......@@ -579,7 +582,7 @@ function views_aggregator_minimum(array $groups, $field_handler) {
* Each range is an array of two elements, so they can be individually
* rendered.
*/
function views_aggregator_range(array $groups, $field_handler, $separator_group = NULL, $separator_column = NULL) {
function views_aggregator_range(array $groups, FieldHandlerInterface $field_handler, ?string $separator_group = NULL, ?string $separator_column = NULL): array {
$values = [];
foreach ($groups as $group => $rows) {
$is_first = TRUE;
......@@ -613,7 +616,7 @@ function views_aggregator_range(array $groups, $field_handler, $separator_group
*
* @param array $groups
* An array of groups of rows, each group indexed by group value.
* @param object $field_handler
* @param \Drupal\views\Plugin\views\field\FieldHandlerInterface $field_handler
* The handler for the view column.
* @param string $replace_text
* An optional parameter, specifying the replacement text to use.
......@@ -623,7 +626,7 @@ function views_aggregator_range(array $groups, $field_handler, $separator_group
* @return array
* An array of values, one for each group and one for the 'column'.
*/
function views_aggregator_replace(array $groups, $field_handler, $replace_text = NULL, $column_label = NULL) {
function views_aggregator_replace(array $groups, FieldHandlerInterface $field_handler, ?string $replace_text = NULL, ?string $column_label = NULL): array {
$values = [];
foreach ($groups as $group => $rows) {
if (isset($replace_text)) {
......@@ -647,13 +650,13 @@ function views_aggregator_replace(array $groups, $field_handler, $replace_text =
*
* @param array $groups
* An array of groups of rows, each group indexed by group value.
* @param object $field_handler
* @param \Drupal\views\Plugin\views\field\FieldHandlerInterface $field_handler
* The handler for the view column to sum groups in.
*
* @return array
* An array of values, one for each group, plus the 'column' group.
*/
function views_aggregator_sum(array $groups, $field_handler) {
function views_aggregator_sum(array $groups, FieldHandlerInterface $field_handler): array {
$values = [];
$sum_column = 0.0;
foreach ($groups as $group => $rows) {
......@@ -676,7 +679,7 @@ function views_aggregator_sum(array $groups, $field_handler) {
*
* @param array $groups
* An array of groups of rows, each group indexed by group value.
* @param object $field_handler
* @param \Drupal\views\Plugin\views\field\FieldHandlerInterface $field_handler
* The handler for the view column to find members of the group.
* @param string $separator_group
* The separator to use between tallies in a group, defaults to '<br/>'.
......@@ -687,7 +690,7 @@ function views_aggregator_sum(array $groups, $field_handler) {
* @return array
* An array of values, one for each group.
*/
function views_aggregator_tally(array $groups, $field_handler, $separator_group, $separator_column) {
function views_aggregator_tally(array $groups, FieldHandlerInterface $field_handler, string $separator_group, string $separator_column): array {
$separator_group = empty($separator_group) ? '<br/>' : $separator_group;
$separator_column = empty($separator_column) ? '<br/>' : $separator_column;
$values = ['column' => []];
......@@ -731,12 +734,13 @@ function views_aggregator_tally(array $groups, $field_handler, $separator_group,
* Scientific notation, e.g., 1.23E-45, is NOT supported, it will return 1.23
*
* @param string $string
* A string representation of a double-precision floating point number.
* A string representation of a double-precision floating-point number.
*
* @return mixed
* Returns double, or FALSE if no number could be found in the string.
* @return float|false
* Returns a floating-point value, or FALSE if no number could be found
* in the string.
*/
function vap_num($string) {
function vap_num(string $string): float|false {
// Strip out any spaces and thousand makers.
$stripped = str_replace([' ', ','], '.', $string);
$dots_count = substr_count($stripped, '.');
......
......@@ -9,10 +9,12 @@
* @phpcs:disable Drupal.NamingConventions.ValidFunctionName.InvalidPrefix
*/
use Drupal\views\Plugin\views\field\FieldHandlerInterface;
/**
* Implements hook_views_aggregation_functions_info().
*/
function views_aggregator_more_functions_views_aggregation_functions_info() {
function views_aggregator_more_functions_views_aggregation_functions_info(): array {
$functions = [
// By edc1, see https://www.drupal.org/node/2299055
'views_aggregator_group_seq_number' => [
......@@ -41,7 +43,7 @@ function views_aggregator_more_functions_views_aggregation_functions_info() {
*
* @param array $groups
* An array of groups of rows, each group indexed by group value.
* @param object $field_handler
* @param \Drupal\views\Plugin\views\field\FieldHandlerInterface $field_handler
* Not used.
* @param int $start_value
* Number at which to start the sequence, defaults to 1.
......@@ -49,11 +51,10 @@ function views_aggregator_more_functions_views_aggregation_functions_info() {
* @return array
* An array of values, one for each group and one for the column.
*/
function views_aggregator_group_seq_number(array $groups, $field_handler = NULL, $start_value = NULL) {
function views_aggregator_group_seq_number(array $groups, FieldHandlerInterface $field_handler, int $start_value = 1): array {
$values = [];
$count = (!isset($start_value) || $start_value == '') ? 1 : (int) $start_value;
foreach ($groups as $group => $rows) {
$values['column'] = $values[$group] = $count++;
$values['column'] = $values[$group] = $start_value++;
}
return $values;
}
......@@ -65,13 +66,13 @@ function views_aggregator_group_seq_number(array $groups, $field_handler = NULL,
*
* @param array $groups
* An array of groups of rows, each group indexed by group value.
* @param object $field_handler
* @param \Drupal\views\Plugin\views\field\FieldHandlerInterface $field_handler
* The handler for the view column.
*
* @return array
* An array of values, one for each group, plus the 'column' group.
*/
function views_aggregator_range_diff(array $groups, $field_handler) {
function views_aggregator_range_diff(array $groups, FieldHandlerInterface $field_handler): array {
$values = [];
foreach ($groups as $group => $rows) {
$is_first = TRUE;
......@@ -105,14 +106,14 @@ function views_aggregator_range_diff(array $groups, $field_handler) {
*
* @param array $groups
* An array of groups of rows, each group indexed by group value.
* @param object $field_handler
* @param \Drupal\views\Plugin\views\field\FieldHandlerInterface $field_handler
* The handler for the view column to calculate percentages in.
*
* @return array
* An array of values, one for each group and one for the column
* (always 100%).
*/
function views_aggregator_percentage(array $groups, $field_handler, $arg_group, $arg_column) {
function views_aggregator_percentage(array $groups, FieldHandlerInterface $field_handler): array {
$values = [];
$sum_column = 0.0;
foreach ($groups as $group => $rows) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment