Skip to content

Commit 731b94f

Browse files
committed
formatting
1 parent 1a0c7b8 commit 731b94f

File tree

2 files changed

+12
-24
lines changed

2 files changed

+12
-24
lines changed

src/Illuminate/View/ComponentAttributeBag.php

+11-24
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ public function __construct(array $attributes = [])
3333
$this->attributes = $attributes;
3434
}
3535

36+
/**
37+
* Get the first attribute's value.
38+
*
39+
* @param mixed $default
40+
* @return mixed
41+
*/
42+
public function first($default = null)
43+
{
44+
return $this->getIterator()->current() ?? value($default);
45+
}
46+
3647
/**
3748
* Get a given attribute from the attribute array.
3849
*
@@ -117,30 +128,6 @@ public function thatStartWith($string)
117128
{
118129
return $this->whereStartsWith($string);
119130
}
120-
121-
/**
122-
* Get the first attribute that starts with the given value from the attribute array.
123-
*
124-
* @param string $string
125-
* @param mixed $default
126-
* @return mixed
127-
*/
128-
public function getFirstWhereStartsWith($string, $default = null)
129-
{
130-
return $this->whereStartsWith($string)->getIterator()->current() ?? value($default);
131-
}
132-
133-
/**
134-
* Get the first attribute that starts with the given value from the attribute array.
135-
*
136-
* @param string $string
137-
* @param mixed $default
138-
* @return mixed
139-
*/
140-
public function getFirstThatStartsWith($string, $default = null)
141-
{
142-
return $this->getFirstWhereStartsWith($string, $default);
143-
}
144131

145132
/**
146133
* Exclude the given attribute from the attribute array.

tests/View/ViewComponentAttributeBagTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public function testAttributeRetrieval()
1212
$bag = new ComponentAttributeBag(['class' => 'font-bold', 'name' => 'test']);
1313

1414
$this->assertSame('class="font-bold"', (string) $bag->whereStartsWith('class'));
15+
$this->assertSame('font-bold', (string) $bag->whereStartsWith('class')->first());
1516
$this->assertSame('class="mt-4 font-bold" name="test"', (string) $bag->merge(['class' => 'mt-4']));
1617
$this->assertSame('class="mt-4 font-bold" name="test"', (string) $bag->merge(['class' => 'mt-4', 'name' => 'foo']));
1718
$this->assertSame('class="mt-4 font-bold" id="bar" name="test"', (string) $bag->merge(['class' => 'mt-4', 'id' => 'bar']));

0 commit comments

Comments
 (0)