Skip to content

Commit f7b8160

Browse files
authored
Merge pull request #1178 from hydephp/update-frontmatter-get-method-to-return-data-instead-of-object
Update FrontMatter::get method to return data array instead of $this
2 parents 2782fc4 + bead498 commit f7b8160

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

packages/framework/src/Framework/Concerns/InteractsWithFrontMatter.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ public function data(string $key = null, mixed $default = null): mixed
3434
*/
3535
public function matter(string $key = null, mixed $default = null): mixed
3636
{
37-
return $this->matter->get($key, $default);
37+
if ($key) {
38+
return $this->matter->get($key, $default);
39+
}
40+
41+
return $this->matter;
3842
}
3943

4044
/**

packages/framework/src/Markdown/Models/FrontMatter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function get(string $key = null, mixed $default = null): mixed
5454
return Arr::get($this->data, $key, $default);
5555
}
5656

57-
return $this;
57+
return $this->data;
5858
}
5959

6060
public function set(string $key, mixed $value): static

packages/framework/tests/Unit/FrontMatterModelTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,16 @@ public function test_magic_get_method_returns_null_if_property_does_not_exist()
5555
$this->assertNull($matter->foo);
5656
}
5757

58-
public function test_get_method_returns_self_when_no_argument_is_specified()
58+
public function test_get_method_returns_data_when_no_argument_is_specified()
5959
{
6060
$matter = new FrontMatter();
61-
$this->assertSame($matter, $matter->get());
61+
$this->assertSame([], $matter->get());
6262
}
6363

64-
public function test_get_method_returns_self_when_no_argument_is_specified_with_data()
64+
public function test_get_method_returns_data_when_no_argument_is_specified_with_data()
6565
{
6666
$matter = new FrontMatter(['foo' => 'bar']);
67-
$this->assertSame($matter, $matter->get());
67+
$this->assertSame(['foo' => 'bar'], $matter->get());
6868
}
6969

7070
public function test_get_method_returns_null_if_specified_front_matter_key_does_not_exist()

0 commit comments

Comments
 (0)