Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
storm
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
afi
storm
Commits
4ad90f73
Commit
4ad90f73
authored
May 28, 2016
by
Laurent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add Storm_Model_Collection::reject + refactoring
parent
49e0bebc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
6 deletions
+30
-6
Collection.php
src/Storm/Collection.php
+9
-3
Abstract.php
src/Storm/Model/Collection/Abstract.php
+13
-3
LoaderVolatileTest.php
tests/Storm/Test/LoaderVolatileTest.php
+8
-0
No files found.
src/Storm/Collection.php
View file @
4ad90f73
...
...
@@ -32,9 +32,15 @@ class Storm_Collection extends ArrayObject {
return
$collection
;
}
public
function
newInstance
(
$elements
)
{
$classname
=
get_class
(
$this
);
return
new
$classname
(
$elements
);
}
public
function
collect
(
$closure
)
{
return
new
Storm_Collection
(
array_map
(
$closure
,
(
array
)
$this
));
return
$this
->
newInstance
(
array_map
(
$closure
,
(
array
)
$this
));
}
...
...
@@ -44,7 +50,7 @@ class Storm_Collection extends ArrayObject {
public
function
select
(
$closure
)
{
return
new
Storm_Collection
(
array_values
(
array_filter
((
array
)
$this
,
$closure
)));
return
$this
->
newInstance
(
array_values
(
array_filter
((
array
)
$this
,
$closure
)));
}
...
...
src/Storm/Model/Collection/Abstract.php
View file @
4ad90f73
...
...
@@ -34,8 +34,7 @@ abstract class Storm_Model_Collection_Abstract extends Storm_Collection {
function
(
$e
)
use
(
$closure_or_string
)
{
return
$e
->
callGetterByAttributeName
(
$closure_or_string
);
})
:
new
Storm_Model_Collection
(
array_map
(
$closure_or_string
,
(
array
)
$this
));
:
parent
::
collect
(
$closure_or_string
);
}
...
...
@@ -46,7 +45,18 @@ abstract class Storm_Model_Collection_Abstract extends Storm_Collection {
function
(
$e
)
use
(
$closure_or_string
)
{
return
call_user_func
([
$e
,
$closure_or_string
]);
})
:
new
Storm_Model_Collection
(
array_values
(
array_filter
((
array
)
$this
,
$closure_or_string
)));
:
parent
::
select
(
$closure_or_string
);
}
public
function
reject
(
$closure_or_string
)
{
return
is_string
(
$closure_or_string
)
?
$this
->
select
(
function
(
$e
)
use
(
$closure_or_string
)
{
return
false
==
call_user_func
([
$e
,
$closure_or_string
]);
})
:
parent
::
reject
(
$closure_or_string
);
}
...
...
tests/Storm/Test/LoaderVolatileTest.php
View file @
4ad90f73
...
...
@@ -423,6 +423,14 @@ class Storm_Test_LoaderVolatileTest extends Storm_Test_ModelTestCase {
}
/** @test */
public
function
rejectInvitesBySelectorNameShouldReturnAlbertAndZoe
()
{
$users
=
new
Storm_Model_Collection
(
Storm_Test_VolatileUser
::
findAll
());
$this
->
assertEquals
([
$this
->
albert
,
$this
->
zoe
],
$users
->
reject
(
'isInvite'
)
->
getArrayCopy
());
}
/** @test */
public
function
collectAllLoginsShouldReturnHubert
()
{
$users
=
new
Storm_Collection
(
Storm_Test_VolatileUser
::
findAll
());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment