-
-
Notifications
You must be signed in to change notification settings - Fork 45
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
Calling Sequence->get()
with an index of -1 doesn't work in 4.8+
#85
Comments
->get()
with -1 doesn't work in 4.8+Sequence->get()
with an index of -1 doesn't work in 4.8+
@Jamesking56 thanks for using the library. Could you provide a snippet please as this feature is covered by tests I would need to see a concrete example in order to understand the origin of the issue if there's one. thanks in advance. |
Well, its the smallest concrete example known to man really, I don't think your tests actually cover negative offsets: $sequence = new Sequence(
new Period(
new \DateTimeImmutable('yesterday'),
new \DateTimeImmutable('now')
)
);
$sequence->get(-1); // Exception instead of expected period. |
Same with an empty Sequence, I think it should return $sequence = new Sequence();
$sequence->get(-1); // Exception instead of expected period. |
$sequence = new Sequence();
$sequence->get(-1); // Exception instead of expected period. This is correct with an empty sequence The first example is debatable but I can see where your reasoning comes from ... I'll see if I'll fix it or not it needs thinking first. |
Looks like its just the |
Thinking further about this, I think it would be a lot nicer if there was a |
Just use the |
the issue is fixed ... it will be released in a patch version in the upcoming days |
the |
Thanks @nyamsprod |
Bug Report
Summary
According to the documentation, the
get()
method supports passing in a negative index from version4.8
and above. When I do this however, I getInvalidIndex
exception thrown with the message:Standalone code, or other way to reproduce the problem
Create any Sequence (empty or not) and call
->get(-1)
.Expected result
I'm expecting that the return value is the latest
Period
item in theSequence
as shown in the documentation:https://period.thephpleague.com/4.0/sequence/collection/#sequenceget
Actual result
InvalidIndex
exception is thrown citing that-1
is an invalid index.The text was updated successfully, but these errors were encountered: