Skip to content

Commit 868402b

Browse files
vitalyrotariendihunter
authored andcommitted
replace Mutable::push with Mutable::add method, solve Laravel version compatibility
1 parent aa75174 commit 868402b

File tree

5 files changed

+21
-26
lines changed

5 files changed

+21
-26
lines changed

src/Collection/Mutable.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,21 @@
1212
class Mutable extends BaseCollection
1313
{
1414
/**
15-
* Push an item onto the end of the collection.
15+
* Add an element to the collection.
1616
*
17-
* @param mixed $values [optional]
17+
* @param mixed $element
18+
* @param Closure $callback
1819
* @return $this
1920
*/
20-
public function push(...$values)
21+
public function add($element, Closure $callback = null)
2122
{
22-
$element = $values[0] ?? null;
23-
$callback = $values[1] ?? null;
24-
2523
$element = $this->createElement($element);
2624

27-
if ($callback instanceof Closure) {
25+
if ($callback) {
2826
$callback($element);
2927
}
3028

31-
parent::push($element);
29+
parent::add($element);
3230

3331
return $this;
3432
}
@@ -51,13 +49,13 @@ public function insert($element, $position, Closure $callback = null): self
5149
}
5250

5351
if (\is_string($position)) {
54-
$this->push($element);
52+
$this->add($element);
5553

5654
return $this->move($element->id(), $position);
5755
}
5856

5957
if ($position >= $this->count()) {
60-
return $this->push($element);
58+
return $this->add($element);
6159
}
6260

6361
if (0 === $position) {
@@ -267,7 +265,7 @@ public function group(string $id, Closure $callback): self
267265

268266
$callback($group);
269267

270-
$this->push($group);
268+
$this->add($group);
271269

272270
return $this;
273271
}
@@ -295,7 +293,7 @@ public function stack(array $elements, string $groupId, $position = null): self
295293
if ($position) {
296294
$this->insert($group, $position);
297295
} else {
298-
$this->push($group);
296+
$this->add($group);
299297
}
300298

301299
return $this;

src/Traits/Module/HasFilters.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ trait HasFilters
4242
*/
4343
public function addFilter(Filter $filter)
4444
{
45-
$this->filters->push($filter);
45+
$this->filters->add($filter);
4646

4747
return $this;
4848
}
@@ -55,7 +55,7 @@ public function addFilter(Filter $filter)
5555
*/
5656
public function addScope(Scope $scope)
5757
{
58-
$this->scopes->push($scope);
58+
$this->scopes->add($scope);
5959

6060
return $this;
6161
}

src/Traits/Module/HasOptions.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ protected function scaffoldForm()
2727

2828
foreach (options_fetch() as $option) {
2929
$element = Text::make($option->key)->setValue($option->value);
30-
31-
$collection->push(
32-
$element
33-
);
30+
$collection->add($element);
3431
}
3532

3633
return $collection;

tests/Collection/MutableTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function it_initializes_a_collection()
4545
/** @test */
4646
public function it_pushes_an_element()
4747
{
48-
$this->collection->push('test', function ($e) {
48+
$this->collection->add('test', function ($e) {
4949
return $e;
5050
});
5151

@@ -293,8 +293,8 @@ protected function makeElementsCollection()
293293
$collection = (new Mutable());
294294

295295
return $collection
296-
->push($this->e('first'))
297-
->push($this->e('second'))
298-
->push($this->e('third'));
296+
->add($this->e('first'))
297+
->add($this->e('second'))
298+
->add($this->e('third'));
299299
}
300300
}

tests/Form/Collection/FormCollectionMutableTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function setUp()
2323
public function it_creates_a_form_element_from_string_id()
2424
{
2525
$collection = new Mutable();
26-
$collection->push('title');
26+
$collection->add('title');
2727

2828
$this->assertCount(1, $collection->all());
2929
$this->assertInstanceOf(Text::class, $collection->find('title'));
@@ -60,8 +60,8 @@ public function it_creates_a_form_element_from_object()
6060
$collection = new Mutable();
6161

6262
$collection
63-
->push($title = Text::make('title'))
64-
->push($body = Textarea::make('body'));
63+
->add($title = Text::make('title'))
64+
->add($body = Textarea::make('body'));
6565

6666
$this->assertCount(2, $collection->all());
6767
$this->assertSame([$title, $body], $collection->all());
@@ -79,7 +79,7 @@ public function it_creates_a_form_element_from_object()
7979
*/
8080
public function it_allows_editing_of_new_created_element($collection)
8181
{
82-
$collection->push(
82+
$collection->add(
8383
$desc = Textarea::make('description'),
8484
function (Textarea $element) {
8585
$element->setTitle('New description');

0 commit comments

Comments
 (0)