Skip to content

Commit

Permalink
Remove internal "arguments" terminology
Browse files Browse the repository at this point in the history
The original version of much of the interal Brief documentation used
"argument(s)" to refer to data stored on the Brief. This was influenced
by some of the original intent, but I've come to feel that--especially
with the introduction of more callables--this terminology serves only to
confuse the documentation.

Hence I have switched to using, simply, "data" to describe the data
stored in a Brief, and "store" to refer to the location where that data
is stored.
  • Loading branch information
alwaysblank committed Dec 22, 2019
1 parent 6b0842a commit 3a2eeef
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions src/Brief.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ class Brief
*
* @var array
*/
private $arguments = [];
private $store = [];

/**
* A limited list of terms that cannot be used as argument keys.
*
* @var array|object
*/
static $protected = ['protected', 'arguments', 'aliases', 'logger'];
static $protected = ['protected', 'store', 'aliases', 'logger', 'callables'];

/**
* An array of aliases for internal terms. The key is the alias; the value
Expand Down Expand Up @@ -251,7 +251,7 @@ protected function storeSingle($value, string $key = null, int $order = null): s
$key = $this->getAuthoritativeName($key) ?? $key;
}

$this->arguments[$key] = [
$this->store[$key] = [
'value' => $value,
'order' => $order
];
Expand Down Expand Up @@ -303,7 +303,7 @@ public static function isKeyAllowed($key)
*/
public function __isset($name)
{
return in_array($name, array_keys($this->arguments));
return in_array($name, array_keys($this->store));
}

/**
Expand Down Expand Up @@ -342,8 +342,8 @@ public function __set(string $name, $value)
*/
protected function getArgument($name)
{
return isset($this->arguments[$name])
? $this->getValue($this->arguments[$name])
return isset($this->store[$name])
? $this->getValue($this->store[$name])
: null;
}

Expand All @@ -361,7 +361,7 @@ protected function getArgument($name)
*/
protected function getAuthoritativeName($name)
{
if (isset($this->arguments[$name])) {
if (isset($this->store[$name])) {
return $name;
}

Expand All @@ -388,9 +388,9 @@ protected function getValue($item)
*
* @return array
*/
protected function getArgumentsSortedByOrder()
protected function getDataSortedByOrder()
{
$rekeyed = array_column($this->arguments, null, 'order');
$rekeyed = array_column($this->store, null, 'order');
ksort($rekeyed);

return $rekeyed;
Expand All @@ -408,7 +408,7 @@ protected function getArgumentsSortedByOrder()
*/
protected function getOrderLimit(string $which = 'start', string $attribute = null)
{
$ordered = $this->getArgumentsSortedByOrder();
$ordered = $this->getDataSortedByOrder();
if ('start' === $which) {
$limit = reset($ordered);
} else { // i.e. 'end'
Expand Down Expand Up @@ -462,7 +462,7 @@ protected function getIncrementedOrder(): int
*/
protected function getFilledOrdered($fill = null)
{
$orders = $this->getArgumentsSortedByOrder();
$orders = $this->getDataSortedByOrder();

return array_map(function ($key) use ($orders, $fill) {
return $orders[$key] ?? ['order' => $key, 'value' => $fill];
Expand All @@ -483,21 +483,21 @@ public function getOrdered($fill = null)
}

/**
* Get all arguments in this Brief as a keyed array.
* Get all data in this Brief as a keyed array.
*
* @return array
*/
public function getKeyed()
{
return array_map(function ($block) {
return $block['value'];
}, $this->arguments);
}, $this->store);
}

/**
* Pass an unmodified Brief to an callable.
*
* If the callable does not understand Briefs or how to get arguments from
* If the callable does not understand Briefs or how to get properties from
* objects, you should probably use `pass()` instead.
*
* @param callable $callable
Expand All @@ -510,7 +510,7 @@ public function debrief(callable $callable)
}

/**
* Pass the contents of a Brief as a series of arguments to callable.
* Pass the contents of a Brief as a series of arguments to a callable.
*
* This method allows for Brief to easily interact with methods that do not
* know how to handle it specifically.
Expand Down Expand Up @@ -578,8 +578,8 @@ public function find($keys)
/**
* Call a callable on each item of this Brief.
*
* This is method is intended for use with keyed arguments. Ordered
* arguments may produce strange results.
* This is method is intended for use with keyed data. Ordered
* data may produce strange results.
*
* This acts directly on the Brief on which it is called, and returns that
* Brief. Be careful; this means that your original Brief is changed. If
Expand All @@ -601,8 +601,8 @@ public function transform(callable $callable)
/**
* Call a callable on each item of a copy of this Brief.
*
* This is method is intended for use with keyed arguments. Ordered
* arguments may produce strange results.
* This is method is intended for use with keyed data. Ordered
* data may produce strange results.
*
* This acts on a copy of the Brief on which it is called, and returns the
* new Brief, leaving the original unmodified. If you don't want this
Expand Down Expand Up @@ -690,7 +690,7 @@ public function log(string $name, string $description = null, array $data = [])
public function export()
{
return [
'arguments' => $this->arguments,
'store' => $this->store,
'aliases' => $this->aliases,
'callables' => $this->callables,
];
Expand All @@ -710,11 +710,11 @@ public function export()
protected function import(Brief $items, $settings)
{
[
'arguments' => $arguments,
'store' => $store,
'aliases' => $aliases,
'callables' => $callables
] = $items->export();
$this->arguments = $arguments;
$this->store = $store;
$this->aliases = $aliases;
$this->callables = $callables;
if (is_array($settings) && count($settings) > 0) {
Expand Down

0 comments on commit 3a2eeef

Please sign in to comment.