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

MINOR: adding SpelledOut method in DBInt #11096

Open
wants to merge 1 commit into
base: 5
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/ORM/FieldType/DBInt.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ public function Nice()
{
return sprintf('%d', $this->value);
}


public function SpelledOut()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a phpdoc comment explaining what the method does.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function SpelledOut()
public function SpelledOut(): string

People will expect a string, but NumberFormatter::format() can return false.

This method should return an empty string in the event the format() method returns false.

{
$v = $this->prepValueForDB($this->value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you calling prepValueForDB() first? e.g. DBInt::Formatted() doesn't do that.

return (new NumberFormatter(i18n::get_locale(), NumberFormatter::SPELLOUT))->format($v);
Comment on lines +70 to +71
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$v = $this->prepValueForDB($this->value);
return (new NumberFormatter(i18n::get_locale(), NumberFormatter::SPELLOUT))->format($v);
$value = $this->prepValueForDB($this->value);
$formatter = new NumberFormatter(i18n::get_locale(), NumberFormatter::SPELLOUT);
return $formatter->format($value);

Please don't use single-letter variables, nor wrap instantiation in quotes.

}

public function scaffoldFormField($title = null, $params = null)
{
return NumericField::create($this->name, $title);
Expand Down