8
I am currently working on an achievement system for a small online game. The achievement entity basically has 4 attributes:
- id
- earnedBy
- earnedOn
- progress
The last one is supposed to be a percentage, meaning a number between 0 and 100. In order to make sure that no numbers greater than 100 or smaller than 0 are saved in the database, my setter-method looks as followed (I am using Symfony2 / Doctrine ORM):
public function setProgress($progress)
{
$this->progress = max(min($progress, 100), 0);
return $this;
}
The important line here is max(min($progress, 100), 0).
It works totally fine, I just wanted to ask, if there is another built-in function in PHP doing exactly that thing, and if what I am doing is okay (concerning good-developing style)