@@ -78,22 +78,22 @@ public function searchInDirectory($dir)
78
78
$ find ->add ('-type f ' );
79
79
}
80
80
81
- $ this ->buildNamesCommand ($ find , $ this ->names );
82
- $ this ->buildNamesCommand ($ find , $ this ->notNames , true );
83
- $ this ->buildSizesCommand ($ find , $ this ->sizes );
84
- $ this ->buildDatesCommand ($ find , $ this ->dates );
81
+ $ this ->buildNamesFiltering ($ find , $ this ->names );
82
+ $ this ->buildNamesFiltering ($ find , $ this ->notNames , true );
83
+ $ this ->buildSizesFiltering ($ find , $ this ->sizes );
84
+ $ this ->buildDatesFiltering ($ find , $ this ->dates );
85
85
86
86
$ useGrep = $ this ->shell ->testCommand ('grep ' ) && $ this ->shell ->testCommand ('xargs ' );
87
87
$ useSort = is_int ($ this ->sort ) && $ this ->shell ->testCommand ('sort ' ) && $ this ->shell ->testCommand ('awk ' );
88
88
89
89
if ($ useGrep && ($ this ->contains || $ this ->notContains )) {
90
90
$ grep = $ command ->ins ('grep ' );
91
- $ this ->buildContainsCommand ($ grep , $ this ->contains );
92
- $ this ->buildContainsCommand ($ grep , $ this ->notContains , true );
91
+ $ this ->buildContentFiltering ($ grep , $ this ->contains );
92
+ $ this ->buildContentFiltering ($ grep , $ this ->notContains , true );
93
93
}
94
94
95
95
if ($ useSort ) {
96
- $ this ->buildSortCommand ($ command , $ this ->sort );
96
+ $ this ->buildSorting ($ command , $ this ->sort );
97
97
}
98
98
99
99
$ paths = $ this ->shell ->testCommand ('uniq ' ) ? $ command ->add ('| uniq ' )->execute () : array_unique ($ command ->execute ());
@@ -141,7 +141,7 @@ public function getName()
141
141
* @param string[] $names
142
142
* @param bool $not
143
143
*/
144
- private function buildNamesCommand (Command $ command , array $ names , $ not = false )
144
+ private function buildNamesFiltering (Command $ command , array $ names , $ not = false )
145
145
{
146
146
if (0 === count ($ names )) {
147
147
return ;
@@ -178,7 +178,7 @@ private function buildNamesCommand(Command $command, array $names, $not = false)
178
178
* @param Command $command
179
179
* @param NumberComparator[] $sizes
180
180
*/
181
- private function buildSizesCommand (Command $ command , array $ sizes )
181
+ private function buildSizesFiltering (Command $ command , array $ sizes )
182
182
{
183
183
foreach ($ sizes as $ i => $ size ) {
184
184
$ command ->add ($ i > 0 ? '-and ' : null );
@@ -217,7 +217,7 @@ private function buildSizesCommand(Command $command, array $sizes)
217
217
* @param Command $command
218
218
* @param DateComparator[] $dates
219
219
*/
220
- private function buildDatesCommand (Command $ command , array $ dates )
220
+ private function buildDatesFiltering (Command $ command , array $ dates )
221
221
{
222
222
foreach ($ dates as $ i => $ date ) {
223
223
$ command ->add ($ i > 0 ? '-and ' : null );
@@ -265,11 +265,12 @@ private function buildDatesCommand(Command $command, array $dates)
265
265
* @param array $contains
266
266
* @param bool $not
267
267
*/
268
- private function buildContainsCommand (Command $ command , array $ contains , $ not = false )
268
+ private function buildContentFiltering (Command $ command , array $ contains , $ not = false )
269
269
{
270
270
foreach ($ contains as $ contain ) {
271
271
$ expr = Expression::create ($ contain );
272
272
273
+ // todo: avoid forking process for each $pattern by using multiple -e options
273
274
$ command
274
275
->add ('| xargs -r grep -I ' )
275
276
->add ($ expr ->isCaseSensitive () ? null : '-i ' )
@@ -278,7 +279,7 @@ private function buildContainsCommand(Command $command, array $contains, $not =
278
279
}
279
280
}
280
281
281
- private function buildSortCommand (Command $ command , $ sort )
282
+ private function buildSorting (Command $ command , $ sort )
282
283
{
283
284
switch ($ sort ) {
284
285
case SortableIterator::SORT_BY_NAME :
0 commit comments