Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate definition of brevity #6

Open
cokernel opened this issue Jun 13, 2024 · 1 comment
Open

Duplicate definition of brevity #6

cokernel opened this issue Jun 13, 2024 · 1 comment

Comments

@cokernel
Copy link
Member

cokernel commented Jun 13, 2024

The functions

public function brevity($message, $length = 0)
{
if ($length == 0) {
$length = EUK_MAX_LABEL;
}
if (strlen($message) <= $length) {
return $message;
}
$source_words = preg_split('/\b/', $message);
$target_words = array();
$current_length = 0;
foreach ($source_words as $word) {
if (($current_length == 0) || $current_length + strlen($word) <= $length) {
$target_words[] = $word;
$current_length += strlen($word);
} else {
break;
}
}
$count = count($target_words);
if ($count == 0) {
$message = '';
} else {
$terminal = $target_words[$count - 1];
if (preg_match('/^\W+$/', $terminal)) {
array_pop($target_words);
}
$message = implode('', $target_words) . '';
}
return $message;
}

function brevity($message, $length = 0)
{
if ($length == 0) {
$length = EUK_MAX_LABEL;
}
if (strlen($message) <= $length) {
return $message;
}
$source_words = preg_split('/\b/', $message);
$target_words = array();
$current_length = 0;
foreach ($source_words as $word) {
if (($current_length == 0) || $current_length + strlen($word) <= $length) {
$target_words[] = $word;
$current_length += strlen($word);
} else {
break;
}
}
$count = count($target_words);
if ($count == 0) {
$message = '';
} else {
$terminal = $target_words[$count - 1];
if (preg_match('/^\W+$/', $terminal)) {
array_pop($target_words);
}
$message = implode('', $target_words) . '';
}
return $message;
}

have identical bodies. Is there a reason why they are defined separately?

@cokernel
Copy link
Member Author

The method brevity on View is used in a few views, for example:

<li><a href="<?= $value['add_link'] ?>"><?= $this->brevity($value['value_label'], 40) ?> <span class="facet-count">(<?= $value['count'] ?>)</span></a></li>

It seems likely that these occurrences of $this->brevity can just be replaced with brevity, but this requires testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant