I have these two methods inside a Value Object:
public final function unlockableLetters()
{
return [
[],
['A', 'B'],
['C']
][$this->level];
}
public final function unlockedLetters()
{
return [
[],
['A', 'B'],
['A', 'B', 'C'],
][$this->level];
}
The first one returns unlockable elements of each level.
- At level 0, returns [].
- At level 1 returns A and B.
- At level 2 returns C.
The second one returns unlocked elements.
- At level 0, returns [].
- At level 1 returns A and B. // NULL + A + B
- At level 2 returns A, B and C. // A + B + C
There is a way to use array functions of php that create an merge of array returned by unlockLetters() from index 0 to current $this->level?
EDIT I want to leave letters only inside unlockableLetters() method. So, unlockedLetters() can "build" its own return value from first method. If something change in the former, change will occur in the latter.
unlockedLetters()fromunlockLetters()using array functions instead of hard coding it? Also i think better method names are in order here because that also makes it confusing... i would usegetUnlockableLettersandgetUnlockedLetters()or something along those lines depending on how these are used.