Skip to content

Commit 68ad0fd

Browse files
committed
[FND-X] Fix functional-php bugs
1 parent 5f5ddb6 commit 68ad0fd

7 files changed

Lines changed: 11 additions & 63 deletions

File tree

src/Functional/FirstIndexOf.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,9 @@ function first_index_of($collection, $value)
2525
{
2626
InvalidArgumentException::assertCollection($collection, __FUNCTION__, 1);
2727

28-
if (\is_callable($value)) {
29-
foreach ($collection as $index => $element) {
30-
if ($element === $value($element, $index, $collection)) {
31-
return $index;
32-
}
33-
}
34-
} else {
35-
foreach ($collection as $index => $element) {
36-
if ($element === $value) {
37-
return $index;
38-
}
28+
foreach ($collection as $index => $element) {
29+
if ($element === $value) {
30+
return $index;
3931
}
4032
}
4133

src/Functional/IndexesOf.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* empty array if no values were found.
1919
*
2020
* @param Traversable|array $collection
21-
* @param mixed|callable $value
21+
* @param mixed $value
2222
* @return array
2323
* @no-named-arguments
2424
*/
@@ -28,17 +28,9 @@ function indexes_of($collection, $value)
2828

2929
$result = [];
3030

31-
if (\is_callable($value)) {
32-
foreach ($collection as $index => $element) {
33-
if ($element === $value($element, $index, $collection)) {
34-
$result[] = $index;
35-
}
36-
}
37-
} else {
38-
foreach ($collection as $index => $element) {
39-
if ($element === $value) {
40-
$result[] = $index;
41-
}
31+
foreach ($collection as $index => $element) {
32+
if ($element === $value) {
33+
$result[] = $index;
4234
}
4335
}
4436

src/Functional/LastIndexOf.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,9 @@ function last_index_of($collection, $value)
2727

2828
$matchingIndex = false;
2929

30-
if (\is_callable($value)) {
31-
foreach ($collection as $index => $element) {
32-
if ($element === $value($element, $index, $collection)) {
33-
$matchingIndex = $index;
34-
}
35-
}
36-
} else {
37-
foreach ($collection as $index => $element) {
38-
if ($element === $value) {
39-
$matchingIndex = $index;
40-
}
30+
foreach ($collection as $index => $element) {
31+
if ($element === $value) {
32+
$matchingIndex = $index;
4133
}
4234
}
4335

src/Functional/With.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,17 @@
1717
*
1818
* @param mixed $value
1919
* @param callable $callback
20-
* @param bool $invokeValue Set to false to not invoke $value if it is a callable. Will be removed in 2.0
2120
* @param mixed $default The default value to return if $value is null
2221
* @return mixed
2322
* @no-named-arguments
2423
*/
25-
function with($value, callable $callback, $invokeValue = true, $default = null)
24+
function with($value, callable $callback, $default = null)
2625
{
2726
InvalidArgumentException::assertCallback($callback, __FUNCTION__, 2);
2827

2928
if ($value === null) {
3029
return $default;
3130
}
3231

33-
if ($invokeValue && \is_callable($value)) {
34-
\trigger_error('Invoking the value is deprecated and will be removed in 2.0', E_USER_DEPRECATED);
35-
36-
$value = $value();
37-
}
38-
3932
return $callback($value);
4033
}

tests/Functional/FirstIndexOfTest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,6 @@ public function testIfValueCouldNotBeFoundFalseIsReturned(): void
4040
self::assertFalse(first_index_of($this->hashIterator, 'invalidValue'));
4141
}
4242

43-
public function testPassCallback(): void
44-
{
45-
self::assertSame(
46-
0,
47-
first_index_of($this->list, function ($element) {
48-
return $element;
49-
})
50-
);
51-
}
52-
5343
public function testPassNoCollection(): void
5444
{
5545
$this->expectArgumentError('Functional\first_index_of() expects parameter 1 to be array or instance of Traversable');

tests/Functional/LastIndexOfTest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,6 @@ public function testIfValueCouldNotBeFoundFalseIsReturned(): void
4040
self::assertFalse(last_index_of($this->hashIterator, 'invalidValue'));
4141
}
4242

43-
public function testPassCallback(): void
44-
{
45-
self::assertSame(
46-
3,
47-
last_index_of($this->list, function ($element) {
48-
return $element;
49-
})
50-
);
51-
}
52-
5343
public function testPassNoCollection(): void
5444
{
5545
$this->expectArgumentError('Functional\last_index_of() expects parameter 1 to be array or instance of Traversable');

tests/Functional/WithTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ public function testDefaultValue(): void
5050
null,
5151
static function () {
5252
},
53-
false,
5453
'foo'
5554
)
5655
);

0 commit comments

Comments
 (0)