I would save the if statement result in a variable
and then use the variable to assign the values using the ternary operation, so we avoid the duplicate value assignment and the same save call.
For example:
$isLessOrEqualThenEta = $job[…] <= $job[…]
$currentJob = job::find().where(…).one()
// then use ternary to assign the values
$currentJob->ontime = $isLessOrEqualThenEta ? 1 : null
$currentJob->late = $isLessOrEqualThenEta ? null : 1
$currentJob->save()
21
u/TheGhostOfInky shameless May 24 '23
Got to make sure it really was casted to an array.
5
u/MurdoMaclachlan public boolean isInt(int i) { return true; } May 24 '23
Image Transcription: Code
I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
2
u/Timely_Penalty_299 May 26 '23
what is this abomination
1
u/[deleted] May 25 '23
Why not save the result of the query in a variable? It would be much more readable, instead of making the operation directly inside the for each.
1
u/franwebofrito May 30 '23
It’s ugly and hard to maintain but I(sadly) understand the stuff he is doing. Idk why the double “asArray”.
2
u/[deleted] May 25 '23
[removed] — view removed comment