public function testMFilterWithEmptyValueNegateFiltered() { $a = new MFilterTestHelper('o', 'p', 'q'); $b = new MFilterTestHelper('o', '', 'q'); $c = new MFilterTestHelper('o', 'p', 'q'); $list = ['a' => $a, 'b' => $b, 'c' => $c]; $actual = Objects::mfilter($list, 'getI', true); $expected = ['b' => $b]; $this->assertEquals($expected, $actual); }
/** * Filter a list of objects by executing a method across all the objects and * filter out the ones wth empty() results. this function works just like * @{function:ifilter}, except that it operates on a list of objects instead * of a list of arrays. * * For example, to remove all objects with no children from a list, where * 'hasChildren' is a method name, do this: * * mfilter($list, 'hasChildren'); * * The optional third parameter allows you to negate the operation and filter * out nonempty objects. To remove all objects that DO have children, do this: * * mfilter($list, 'hasChildren', true); * * @param $list array List of objects to filter. * @param $method string A method name. * @param $negate bool Optionally, pass true to drop objects * which pass the filter instead of keeping them. * * @return array List of objects which pass the filter. * @throws InvalidArgumentException * @group util * * @deprecated */ function mfilter(array $list, $method, $negate = false) { return \Packaged\Helpers\Objects::mfilter($list, $method, $negate); }