What test should I use?

In the database when the execution of the mission, is coded exp_mission = exp_mission + 10
Now check this:
if ($this->mission->exp_mission == 100) {
 throw new DomainException('You have already completed this mission completely');
}
// here is the query ... update missions set exp_mission = exp_mission + 10 where id = ? and id_mission = ? limit 1 ...

Maybe you should right?
if ($this->mission->exp_mission >= 100) {
 if ($this->mission->exp_mission > 100) {
 // here is the query ... update missions set exp_mission = 100 where id = ? and id_mission = ? limit 1 ...
}
 throw new DomainException('You have already completed this mission completely');
}
// here is the query ... update missions set exp_mission = exp_mission + 10 where id = ? and id_mission = ? limit 1 ...

Insure exp_mission = exp_mission + 10 or not?
April 4th 20 at 13:25
1 answer
April 4th 20 at 13:27
Solution
class Controller 
{
 private $repo;

 pulic function __construct(MissionRepository $repo) 
{
 $this->repo = $repo;
}

 pulic function excuteMission($id)
{
 $mission = $this->repo->find($id);
$mission->next();
$mission->save();
}
}

class Mission
{
 private $progress;

 public function next(): void
{
 $progress = $this->progress + 10;

 if($progress > 100) {
 throw new DomainExeption('the Mission cannot be completed.')
}
 if($progress = 100) {
 throw new DomainExeption('the Mission is already accomplished.')
}
}
}

In General, use the tests and you will understand what is needed, what is not necessary.
Well, You just described what I did) - Albin.Romaguera commented on April 4th 20 at 13:30
@Albin.Romaguera, not quite, but almost. What I have to describe the neighboring question?)

I'm leaning toward the latter, but without a double if two of the written request

In General, use the tests and you will understand what is needed, what is not necessary.
- petra commented on April 4th 20 at 13:33
@petra, in the second embodiment, will not be the second request is fulfilled, if >= 100, there is released and the request before the release but only if > 100 - Albin.Romaguera commented on April 4th 20 at 13:36
@petra, I understand Your washed: first add a property to +10 and then check and write OK - Albin.Romaguera commented on April 4th 20 at 13:39
@Albin.Romaguera, I see. But you write it. This duplication of code. It is better to assign it to a variable and entered into the database. - petra commented on April 4th 20 at 13:42
@petra, above the comments))) - Albin.Romaguera commented on April 4th 20 at 13:45
Why everywhere to push the PLO? - Hermina_Hills63 commented on April 4th 20 at 13:48
In the condition assignment - pietro.Mitchell47 commented on April 4th 20 at 13:51

Find more questions by tags PHP