Skip to content

Commit cf88f89

Browse files
author
Jonathan Nessier
committed
Revert "Shorted method names"
This reverts commit 49cd4fa.
1 parent 49cd4fa commit cf88f89

File tree

5 files changed

+121
-124
lines changed

5 files changed

+121
-124
lines changed

README.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,58 +36,58 @@ $data = new Data([
3636

3737
// Get value by key.
3838
$default = null; // Default value, when key doesn't exists
39-
$value = $data->get('key', $default);
39+
$value = $data->getValue('key', $default);
4040

4141
// Pull value by key and delete it afterwards.
4242
$default = null; // Default value, when key doesn't exists
43-
$value = $data->pull('key', $default);
43+
$value = $data->pullValue('key', $default);
4444

4545
// Set value by key.
4646
$overwrite = true; // Set FALSE to prevent overwrite existing value
47-
$data = $data->set('key', 'value', $overwrite);
47+
$data = $data->setValue('key', 'value', $overwrite);
4848

4949
// Check whether value exists by key.
50-
$valueExists = $data->has('key');
50+
$valueExists = $data->hasValue('key');
5151

5252
// Delete value by key.
53-
$data->delete('key');
53+
$data->deleteValue('key');
5454

55-
// Count number of all values.
56-
$numberOfValues = $data->countAll();
55+
// Count number of values.
56+
$numberOfValues = $data->countValues();
5757

58-
// Get all values as array.
59-
$array = $data->getAll();
58+
// Get values as array.
59+
$array = $data->getValues();
6060

6161
// Iterate trough values.
62-
$data->each(function ($value, string $key) {
62+
$data->eachValue(function ($value, string $key) {
6363
// Callback for each key/value pair
6464
});
6565

66-
// Clear all values.
67-
$data = $data->clearAll();
66+
// Clear values.
67+
$data = $data->clearValues();
6868

69-
// Replace all values with array. Existing values with similar keys will be overwritten.
69+
// Replace values. Existing values with similar keys will be overwritten.
7070
$recursive = true; // Set FALSE to prevent recursive merge
71-
$data = $data->replaceAll([
71+
$data = $data->replaceValues([
7272
// Array with key/value pairs
7373
], $recursive);
7474

75-
// Set array for all values. Existing data will be overwritten.
76-
$data = $data->setAll([
75+
// Set array as values. Existing data will be overwritten.
76+
$data = $data->setValues([
7777
// Array with key/value pairs
7878
]);
7979

80-
// Set referenced array for all values. Existing data will be overwritten.
80+
// Set referenced array as values. Existing data will be overwritten.
8181
$values = [
8282
// Array with key/value pairs
8383
];
84-
$data = $data->setAllReferenced($values);
84+
$data = $data->setReferencedValues($values);
8585
```
8686

8787
## Limitations
8888
* Only string as key supported
8989
* Only array as key/value pairs supported
90-
* No dot notation implemented
90+
* No dot notation implementation
9191
* No type check for values
9292

9393
## Contributors

src/Data.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Data implements DataInterface
1818
public function __construct(array $values = null)
1919
{
2020
if (!is_null($values)) {
21-
$this->setAll($values);
21+
$this->setValues($values);
2222
}
2323
}
2424
}

src/DataInterface.php

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,25 @@
55

66
interface DataInterface
77
{
8+
89
/**
9-
* Clear all values.
10-
*
11-
* @return self
10+
* Clear values.
1211
*/
13-
public function clearAll(): DataInterface;
12+
public function clearValues(): void;
1413

1514
/**
16-
* Count number of all values.
15+
* Count number of values.
1716
*
1817
* @return int
1918
*/
20-
public function countAll(): int;
19+
public function countValues(): int;
2120

2221
/**
2322
* Delete value by key.
2423
*
2524
* @param string $key Key as identifier of the value
2625
*/
27-
public function delete(string $key): void;
26+
public function deleteValue(string $key): void;
2827

2928
/**
3029
* Iterate trough values.
@@ -33,7 +32,7 @@ public function delete(string $key): void;
3332
*
3433
* @return mixed
3534
*/
36-
public function each(callable $callback): void;
35+
public function eachValue(callable $callback): void;
3736

3837
/**
3938
* Get value by key.
@@ -43,14 +42,14 @@ public function each(callable $callback): void;
4342
*
4443
* @return mixed
4544
*/
46-
public function get(string $key, $default = null);
45+
public function getValue(string $key, $default = null);
4746

4847
/**
49-
* Get all values as array.
48+
* Get values as array.
5049
*
5150
* @return array
5251
*/
53-
public function getAll(): array;
52+
public function getValues(): array;
5453

5554
/**
5655
* Check whether value exists by key.
@@ -59,7 +58,7 @@ public function getAll(): array;
5958
*
6059
* @return bool
6160
*/
62-
public function has(string $key): bool;
61+
public function hasValue(string $key): bool;
6362

6463
/**
6564
* Pull value by key and delete it afterwards.
@@ -69,44 +68,44 @@ public function has(string $key): bool;
6968
*
7069
* @return mixed
7170
*/
72-
public function pull(string $key, $default = null);
71+
public function pullValue(string $key, $default = null);
7372

7473
/**
75-
* Replace all values with array. Existing values with similar keys will be overwritten.
74+
* Replace values by key. Existing values with similar keys will be overwritten.
7675
*
7776
* @param array $values Array with key/value pairs
7877
* @param bool $recursive Set TRUE to enable recursive merge
7978
*
8079
* @return self
8180
*/
82-
public function replaceAll(array $values, bool $recursive = true): DataInterface;
81+
public function replaceValues(array $values, bool $recursive = true): DataInterface;
8382

8483
/**
85-
* Set value by key.
84+
* Set referenced array as values. Existing values will be overwritten.
8685
*
87-
* @param string $key Key as identifier of the value
88-
* @param mixed $value Value to set
89-
* @param bool $overwrite Set FALSE to prevent overwrite existing value
86+
* @param array $values Array with key/value pairs
9087
*
9188
* @return self
9289
*/
93-
public function set(string $key, $value, bool $overwrite = true): DataInterface;
90+
public function setReferencedValues(array &$values): DataInterface;
9491

9592
/**
96-
* Set array for all values. Existing values will be overwritten.
93+
* Set value by key.
9794
*
98-
* @param array $values Array with key/value pairs
95+
* @param string $key Key as identifier of the value
96+
* @param mixed $value Value to set
97+
* @param bool $overwrite Set FALSE to prevent overwrite existing value
9998
*
10099
* @return self
101100
*/
102-
public function setAll(array $values): DataInterface;
101+
public function setValue(string $key, $value, bool $overwrite = true): DataInterface;
103102

104103
/**
105-
* Set referenced array for all values. Existing values will be overwritten.
104+
* Set array as values. Existing values will be overwritten.
106105
*
107106
* @param array $values Array with key/value pairs
108107
*
109108
* @return self
110109
*/
111-
public function setAllReferenced(array &$values): DataInterface;
110+
public function setValues(array $values): DataInterface;
112111
}

src/DataTrait.php

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,33 @@ trait DataTrait
1313
/**
1414
* {@inheritDoc}
1515
*/
16-
public function clearAll(): DataInterface
16+
public function clearValues(): void
1717
{
1818
$this->values = [];
19-
20-
return $this;
2119
}
2220

2321
/**
2422
* {@inheritDoc}
2523
*/
26-
public function countAll(): int
24+
public function countValues(): int
2725
{
2826
return count((array)$this->values);
2927
}
3028

3129
/**
3230
* {@inheritDoc}
3331
*/
34-
public function delete(string $key): void
32+
public function deleteValue(string $key): void
3533
{
36-
if ($this->has($key)) {
34+
if ($this->hasValue($key)) {
3735
unset($this->values[$key]);
3836
}
3937
}
4038

4139
/**
4240
* {@inheritDoc}
4341
*/
44-
public function each(callable $callback): void
42+
public function eachValue(callable $callback): void
4543
{
4644
foreach ($this->values as $key => $value) {
4745
call_user_func_array($callback, [
@@ -54,9 +52,9 @@ public function each(callable $callback): void
5452
/**
5553
* {@inheritDoc}
5654
*/
57-
public function get(string $key, $default = null)
55+
public function getValue(string $key, $default = null)
5856
{
59-
if ($this->has($key)) {
57+
if ($this->hasValue($key)) {
6058
return $this->values[$key];
6159
}
6260

@@ -66,27 +64,37 @@ public function get(string $key, $default = null)
6664
/**
6765
* {@inheritDoc}
6866
*/
69-
public function getAll(): array
67+
public function getValues(): array
7068
{
7169
return (array)$this->values;
7270
}
7371

7472
/**
7573
* {@inheritDoc}
7674
*/
77-
public function has(string $key): bool
75+
public function setValues(array $values): DataInterface
76+
{
77+
$this->values = $values;
78+
79+
return $this;
80+
}
81+
82+
/**
83+
* {@inheritDoc}
84+
*/
85+
public function hasValue(string $key): bool
7886
{
7987
return isset($this->values[$key]);
8088
}
8189

8290
/**
8391
* {@inheritDoc}
8492
*/
85-
public function pull(string $key, $default = null)
93+
public function pullValue(string $key, $default = null)
8694
{
87-
if ($this->has($key)) {
88-
$value = $this->get($key);
89-
$this->delete($key);
95+
if ($this->hasValue($key)) {
96+
$value = $this->getValue($key);
97+
$this->deleteValue($key);
9098
return $value;
9199
}
92100

@@ -96,7 +104,7 @@ public function pull(string $key, $default = null)
96104
/**
97105
* {@inheritDoc}
98106
*/
99-
public function replaceAll(array $values, bool $recursive = true): DataInterface
107+
public function replaceValues(array $values, bool $recursive = true): DataInterface
100108
{
101109
if ($recursive) {
102110
$this->values = array_replace_recursive($this->values, $values);
@@ -110,31 +118,21 @@ public function replaceAll(array $values, bool $recursive = true): DataInterface
110118
/**
111119
* {@inheritDoc}
112120
*/
113-
public function set(string $key, $value, bool $overwrite = true): DataInterface
114-
{
115-
if ($overwrite || !$this->has($key)) {
116-
$this->values[$key] = $value;
117-
}
118-
119-
return $this;
120-
}
121-
122-
/**
123-
* {@inheritDoc}
124-
*/
125-
public function setAll(array $values): DataInterface
121+
public function setReferencedValues(array &$values): DataInterface
126122
{
127-
$this->values = $values;
123+
$this->values = &$values;
128124

129125
return $this;
130126
}
131127

132128
/**
133129
* {@inheritDoc}
134130
*/
135-
public function setAllReferenced(array &$values): DataInterface
131+
public function setValue(string $key, $value, bool $overwrite = true): DataInterface
136132
{
137-
$this->values = &$values;
133+
if ($overwrite || !$this->hasValue($key)) {
134+
$this->values[$key] = $value;
135+
}
138136

139137
return $this;
140138
}

0 commit comments

Comments
 (0)