Skip to content
Permalink
Browse files

Remove combined getter/setter on QueryTrait.

  • Loading branch information...
dereuromark committed Mar 14, 2018
1 parent 9adecae commit f84edf3fb9c70feeec3d18bf895529e1ea3ec295
@@ -67,7 +67,7 @@ class MapReduce implements IteratorAggregate
* A callable that will be executed for each intermediate record emitted during
* the Map phase
*
* @var callable
* @var callable|null
*/
protected $_reducer;
@@ -318,7 +318,7 @@ public function toArray()
* result is attempted to be fetched.
*
* If the first argument is set to null, it will return the list of previously
* registered map reduce routines.
* registered map reduce routines. This is deprecated as of 3.6.0 - use getMapReducers() instead.
*
* If the third argument is set to true, it will erase previous map reducers
* and replace it with the arguments passed.
@@ -335,13 +335,29 @@ public function mapReduce(callable $mapper = null, callable $reducer = null, $ov
$this->_mapReduce = [];
}
if ($mapper === null) {
if (!$overwrite) {
deprecationWarning(
'Using QueryTrait::mapReduce() as a getter is deprecated. ' .
'Use getMapReducers() instead.'
);
}
return $this->_mapReduce;
}
$this->_mapReduce[] = compact('mapper', 'reducer');
return $this;
}
/**
* Returns the list of previously registered map reduce routines.
*
* @return array
*/
public function getMapReducers()
{
return $this->_mapReduce;
}
/**
* Registers a new formatter callback function that is to be executed when trying
* to fetch the results from the database.
@@ -354,7 +370,7 @@ public function mapReduce(callable $mapper = null, callable $reducer = null, $ov
* after all the `MapReduce` routines for this query have been executed.
*
* If the first argument is set to null, it will return the list of previously
* registered map reduce routines.
* registered format routines. This is deprecated as of 3.6.0 - use getResultFormatters() instead.
*
* If the second argument is set to true, it will erase previous formatters
* and replace them with the passed first argument.
@@ -386,6 +402,12 @@ public function formatResults(callable $formatter = null, $mode = 0)
$this->_formatters = [];
}
if ($formatter === null) {
if ($mode !== self::OVERWRITE) {
deprecationWarning(
'Using QueryTrait::formatResults() as a getter is deprecated. ' .
'Use getResultFormatters() instead.'
);
}
return $this->_formatters;
}
@@ -400,6 +422,16 @@ public function formatResults(callable $formatter = null, $mode = 0)
return $this;
}
/**
* Returns the list of previously registered format routines.
*
* @return array
*/
public function getResultFormatters()
{
return $this->_formatters;
}
/**
* Returns the first result out of executing this query, if the query has not been
* executed before, it will set the limit clause to 1 for performance reasons.
@@ -1216,7 +1216,7 @@ protected function _appendFields($query, $surrogate, $options)
*/
protected function _formatAssociationResults($query, $surrogate, $options)
{
$formatters = $surrogate->formatResults();
$formatters = $surrogate->getResultFormatters();
if (!$formatters || empty($options['propertyPath'])) {
return;
@@ -606,7 +606,7 @@ public function testFindThreadedCompositeKeys()
['id' => 8, 'name' => 'a', 'site_id' => 2, 'parent_id' => 4],
]);
$query->find('threaded', ['parentField' => ['parent_id', 'site_id']]);
$formatter = $query->formatResults()[0];
$formatter = $query->getResultFormatters()[0];
$expected = [
[
@@ -991,11 +991,11 @@ public function testMapReduceOnlyMapper()
$this->assertSame($query, $query->mapReduce($mapper1));
$this->assertEquals(
[['mapper' => $mapper1, 'reducer' => null]],
$query->mapReduce()
$query->getMapReducers()
);
$this->assertEquals($query, $query->mapReduce($mapper2));
$result = $query->mapReduce();
$result = $query->getMapReducers();
$this->assertSame(
[
['mapper' => $mapper1, 'reducer' => null],
@@ -1024,7 +1024,7 @@ public function testMapReduceBothMethods()
$this->assertSame($query, $query->mapReduce($mapper1, $reducer1));
$this->assertEquals(
[['mapper' => $mapper1, 'reducer' => $reducer1]],
$query->mapReduce()
$query->getMapReducers()
);
$this->assertSame($query, $query->mapReduce($mapper2, $reducer2));
@@ -1033,7 +1033,7 @@ public function testMapReduceBothMethods()
['mapper' => $mapper1, 'reducer' => $reducer1],
['mapper' => $mapper2, 'reducer' => $reducer2]
],
$query->mapReduce()
$query->getMapReducers()
);
}
@@ -1056,13 +1056,13 @@ public function testOverwriteMapReduce()
$this->assertEquals($query, $query->mapReduce($mapper1, $reducer1));
$this->assertEquals(
[['mapper' => $mapper1, 'reducer' => $reducer1]],
$query->mapReduce()
$query->getMapReducers()
);
$this->assertEquals($query, $query->mapReduce($mapper2, $reducer2, true));
$this->assertEquals(
[['mapper' => $mapper2, 'reducer' => $reducer2]],
$query->mapReduce()
$query->getMapReducers()
);
}
@@ -2141,17 +2141,17 @@ public function testFormatResults()
$table = $this->getTableLocator()->get('authors');
$query = new Query($this->connection, $table);
$this->assertSame($query, $query->formatResults($callback1));
$this->assertSame([$callback1], $query->formatResults());
$this->assertSame([$callback1], $query->getResultFormatters());
$this->assertSame($query, $query->formatResults($callback2));
$this->assertSame([$callback1, $callback2], $query->formatResults());
$this->assertSame([$callback1, $callback2], $query->getResultFormatters());
$query->formatResults($callback2, true);
$this->assertSame([$callback2], $query->formatResults());
$this->assertSame([$callback2], $query->getResultFormatters());
$query->formatResults(null, true);
$this->assertSame([], $query->formatResults());
$this->assertSame([], $query->getResultFormatters());
$query->formatResults($callback1);
$query->formatResults($callback2, $query::PREPEND);
$this->assertSame([$callback2, $callback1], $query->formatResults());
$this->assertSame([$callback2, $callback1], $query->getResultFormatters());
}
/**

0 comments on commit f84edf3

Please sign in to comment.
You can’t perform that action at this time.