Skip to content

Commit e0623a7

Browse files
authored
Merge pull request #11 from 8fold/prepare-major
feat: Append property to list
2 parents 2cd9421 + 4a94825 commit e0623a7

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

src/Contracts/Contentable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
interface Contentable
88
{
99
/**
10-
* @param string[] $content
10+
* @param array<string|Stringable> $content
1111
*/
1212
public static function __callStatic(
1313
string $name,

src/Implementations/Properties.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,22 @@ trait Properties
1414
/**
1515
* @return static $properties [description]
1616
*/
17-
public function props(string ...$properties)
17+
public function props(string ...$properties): static
1818
{
1919
$this->properties = $properties;
2020
return $this;
2121
}
2222

23+
public function prop(string $prop): static
24+
{
25+
$this->properties[] = $prop;
26+
return $this;
27+
}
28+
2329
protected function propertiesString(): string
2430
{
2531
if (count($this->properties()) === 0) {
2632
return '';
27-
2833
}
2934

3035
$b = [];

tests/ElementBaselineTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,20 @@ public function element_can_omit_end_tag(): void
3939
*/
4040
public function element_can_have_properties(): void
4141
{
42+
// basic
4243
$this->assertEquals(
4344
Element::create('root')->props('id 6', 'property hello')->build(),
4445
'<root id="6" property="hello"></root>'
4546
);
47+
48+
// add
49+
$this->assertEquals(
50+
Element::create('root')
51+
->props('id 6', 'property hello')
52+
->prop('class something')
53+
->build(),
54+
'<root id="6" property="hello" class="something"></root>'
55+
);
4656
}
4757

4858
/**

0 commit comments

Comments
 (0)