mirror of
https://github.com/danog/psalm-plugin-laravel.git
synced 2024-11-26 20:34:48 +01:00
Merge pull request #167 from caugner/head-support
This commit is contained in:
commit
3392dc087d
@ -81,6 +81,32 @@ class NullObject {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first element of an array. Useful for method chaining.
|
||||
*
|
||||
* @template TValue
|
||||
* @template TParam of TValue[]
|
||||
* @param TParam $array
|
||||
* @return (TParam is non-empty-array ? TValue : false)
|
||||
*/
|
||||
function head($array)
|
||||
{
|
||||
return reset($array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last element from an array.
|
||||
*
|
||||
* @template TValue
|
||||
* @template TParam of TValue[]
|
||||
* @param TParam $array
|
||||
* @return (TParam is non-empty-array ? TValue : false)
|
||||
*/
|
||||
function last($array)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide access to optional objects.
|
||||
*
|
||||
|
@ -31,6 +31,38 @@ Feature: helpers
|
||||
When I run Psalm
|
||||
Then I see no errors
|
||||
|
||||
Scenario: head and last support
|
||||
Given I have the following code
|
||||
"""
|
||||
/**
|
||||
* @return false
|
||||
*/
|
||||
function empty_head()
|
||||
{
|
||||
return head([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return false
|
||||
*/
|
||||
function empty_last()
|
||||
{
|
||||
return last([]);
|
||||
}
|
||||
|
||||
function non_empty_head(): int
|
||||
{
|
||||
return last([1, 2, 3]);
|
||||
}
|
||||
|
||||
function non_empty_last(): int
|
||||
{
|
||||
return last([1, 2, 3]);
|
||||
}
|
||||
"""
|
||||
When I run Psalm
|
||||
Then I see no errors
|
||||
|
||||
Scenario: optional support
|
||||
Given I have the following code
|
||||
"""
|
||||
@ -38,7 +70,6 @@ Feature: helpers
|
||||
{
|
||||
return optional($user)->getMessage();
|
||||
}
|
||||
|
||||
"""
|
||||
When I run Psalm
|
||||
Then I see no errors
|
||||
@ -58,7 +89,6 @@ Feature: helpers
|
||||
{
|
||||
return logger();
|
||||
}
|
||||
|
||||
"""
|
||||
When I run Psalm
|
||||
Then I see no errors
|
||||
|
Loading…
Reference in New Issue
Block a user