diff --git a/src/Link.php b/src/Link.php index 414136c..3eff0be 100644 --- a/src/Link.php +++ b/src/Link.php @@ -62,7 +62,7 @@ public function getUrl(): string return $this->url; } - return implode('', $this->prefixes) . '/' . ltrim($this->url, '/'); + return implode('', $this->prefixes).'/'.ltrim($this->url, '/'); } /** diff --git a/src/Menu.php b/src/Menu.php index e8e55db..8fe0d96 100644 --- a/src/Menu.php +++ b/src/Menu.php @@ -195,7 +195,7 @@ public function submenu($header, $menu = null) return $this->add($menu->prependIf($header, $header)); } - + /** * @param bool $condition * @param callable|\Spatie\Menu\Menu|\Spatie\Menu\Item $header @@ -265,7 +265,7 @@ public function each(callable $callable) $type = Reflection::firstParameterType($callable); foreach ($this->items as $item) { - if (!Reflection::itemMatchesType($item, $type)) { + if (! Reflection::itemMatchesType($item, $type)) { continue; } @@ -301,7 +301,7 @@ protected function applyFilter(callable $filter, Item $item) { $type = Reflection::firstParameterType($filter); - if (!Reflection::itemMatchesType($item, $type)) { + if (! Reflection::itemMatchesType($item, $type)) { return; } @@ -484,7 +484,7 @@ public function setActiveFromUrl(string $url, string $root = '/') $this->applyToAll(function ($item) use ($requestUrl, $requestRoot) { // Not using a magic typehint since we need to do two instance checks - if (!$item instanceof HasUrl || !$item instanceof Activatable) { + if (! $item instanceof HasUrl || ! $item instanceof Activatable) { return; } @@ -516,7 +516,7 @@ public function setActiveFromUrl(string $url, string $root = '/') // The menu item is active if it's path starts with the request path. if (strpos($requestUrl['path'], $url['path']) === 0) { $item->setActive(); - }; + } }); return $this; @@ -536,8 +536,7 @@ public function setActiveFromCallable(callable $callable) $type = Reflection::firstParameterType($callable); $this->applyToAll(function (Activatable $item) use ($callable, $type) { - - if (!Reflection::itemMatchesType($item, $type)) { + if (! Reflection::itemMatchesType($item, $type)) { return; } @@ -665,7 +664,7 @@ public function render(): string $menu = "{$this->prepend}{$contents}{$this->append}"; - if (!empty($this->wrap)) { + if (! empty($this->wrap)) { return HtmlElement::render($this->wrap[0], $this->wrap[1], $menu); } diff --git a/src/Traits/HtmlAttributes.php b/src/Traits/HtmlAttributes.php index bbc69f4..98f5de5 100644 --- a/src/Traits/HtmlAttributes.php +++ b/src/Traits/HtmlAttributes.php @@ -3,7 +3,6 @@ namespace Spatie\Menu\Traits; use Spatie\HtmlElement\Attributes; -use Spatie\Menu\Helpers\Arr; trait HtmlAttributes { diff --git a/src/Traits/ParentAttributes.php b/src/Traits/ParentAttributes.php index 9d01a65..9e87f39 100644 --- a/src/Traits/ParentAttributes.php +++ b/src/Traits/ParentAttributes.php @@ -46,7 +46,7 @@ public function setParentAttribute(string $attribute, string $value = '') public function setParentAttributes(array $attributes) { $this->parentAttributes->setAttributes($attributes); - + return $this; } diff --git a/tests/Items/HtmlTest.php b/tests/Items/HtmlTest.php index c2ba8b9..5024790 100644 --- a/tests/Items/HtmlTest.php +++ b/tests/Items/HtmlTest.php @@ -7,7 +7,7 @@ class HtmlTest extends \PHPUnit_Framework_TestCase { /** @test */ - function it_contains_html() + public function it_contains_html() { $this->assertEquals( 'Hello world', @@ -16,7 +16,7 @@ function it_contains_html() } /** @test */ - function it_can_be_set_active() + public function it_can_be_set_active() { $this->assertTrue(Html::raw('')->setActive()->isActive()); } diff --git a/tests/Items/LinkTest.php b/tests/Items/LinkTest.php index 2d289c7..c7338d3 100644 --- a/tests/Items/LinkTest.php +++ b/tests/Items/LinkTest.php @@ -7,7 +7,7 @@ class LinkTest extends \PHPUnit_Framework_TestCase { /** @test */ - function it_contains_text() + public function it_contains_text() { $this->assertEquals( 'Home', @@ -16,7 +16,7 @@ function it_contains_text() } /** @test */ - function it_has_an_url() + public function it_has_an_url() { $this->assertEquals( 'https://spatie.be', @@ -25,7 +25,7 @@ function it_has_an_url() } /** @test */ - function it_can_retrieve_a_segment_from_an_absolute_root_url() + public function it_can_retrieve_a_segment_from_an_absolute_root_url() { $this->assertEquals( null, @@ -34,7 +34,7 @@ function it_can_retrieve_a_segment_from_an_absolute_root_url() } /** @test */ - function it_can_retrieve_a_segment_from_an_absolute_url() + public function it_can_retrieve_a_segment_from_an_absolute_url() { $this->assertEquals( 'opensource', @@ -43,7 +43,7 @@ function it_can_retrieve_a_segment_from_an_absolute_url() } /** @test */ - function it_can_retrieve_a_segment_from_a_relative_url() + public function it_can_retrieve_a_segment_from_a_relative_url() { $this->assertEquals( 'opensource', @@ -52,7 +52,7 @@ function it_can_retrieve_a_segment_from_a_relative_url() } /** @test */ - function it_can_be_rendered() + public function it_can_be_rendered() { $this->assertEquals( 'Home', @@ -61,7 +61,7 @@ function it_can_be_rendered() } /** @test */ - function it_can_render_classes() + public function it_can_render_classes() { $this->assertEquals( 'Home', @@ -70,7 +70,7 @@ function it_can_render_classes() } /** @test */ - function it_can_render_attributes() + public function it_can_render_attributes() { $this->assertEquals( 'Home', @@ -79,7 +79,7 @@ function it_can_render_attributes() } /** @test */ - function it_can_prefix_an_url() + public function it_can_prefix_an_url() { $this->assertEquals( '/foo/bar', @@ -88,7 +88,7 @@ function it_can_prefix_an_url() } /** @test */ - function it_can_prefix_an_url_multiple_times() + public function it_can_prefix_an_url_multiple_times() { $this->assertEquals( '/foo/bar/baz', diff --git a/tests/MenuAddTest.php b/tests/MenuAddTest.php index e138f98..3cdb390 100644 --- a/tests/MenuAddTest.php +++ b/tests/MenuAddTest.php @@ -8,7 +8,7 @@ class MenuAddTest extends MenuTestCase { /** @test */ - function it_starts_as_an_empty_list() + public function it_starts_as_an_empty_list() { $this->menu = Menu::new(); @@ -16,7 +16,7 @@ function it_starts_as_an_empty_list() } /** @test */ - function an_item_can_be_added() + public function an_item_can_be_added() { $this->menu = Menu::new()->add(Link::to('#', 'Hello')); @@ -28,7 +28,7 @@ function an_item_can_be_added() } /** @test */ - function a_link_can_be_added() + public function a_link_can_be_added() { $this->menu = Menu::new()->link('#', 'Hello'); @@ -40,7 +40,7 @@ function a_link_can_be_added() } /** @test */ - function multiple_items_can_be_added() + public function multiple_items_can_be_added() { $this->menu = Menu::new() ->add(Link::to('#', 'Hello')) @@ -55,7 +55,7 @@ function multiple_items_can_be_added() } /** @test */ - function it_adds_an_active_class_to_active_items() + public function it_adds_an_active_class_to_active_items() { $this->menu = Menu::new() ->add(Link::to('#', 'Hello')->setActive()); @@ -68,7 +68,7 @@ function it_adds_an_active_class_to_active_items() } /** @test */ - function submenus_can_be_added() + public function submenus_can_be_added() { $this->menu = Menu::new() ->add(Menu::new() @@ -87,7 +87,7 @@ function submenus_can_be_added() } /** @test */ - function it_adds_active_classes_to_active_submenus() + public function it_adds_active_classes_to_active_submenus() { $this->menu = Menu::new() ->add(Menu::new() @@ -106,7 +106,7 @@ function it_adds_active_classes_to_active_submenus() } /** @test */ - function it_can_conditionally_add_an_item() + public function it_can_conditionally_add_an_item() { $this->menu = Menu::new() ->addIf(true, Link::to('#', 'Foo')) @@ -120,7 +120,7 @@ function it_can_conditionally_add_an_item() } /** @test */ - function it_can_conditionally_add_a_link() + public function it_can_conditionally_add_a_link() { $this->menu = Menu::new() ->linkIf(true, '#', 'Foo') @@ -134,7 +134,7 @@ function it_can_conditionally_add_a_link() } /** @test */ - function it_can_conditionally_add_html() + public function it_can_conditionally_add_html() { $this->menu = Menu::new() ->htmlIf(true, 'Foo') @@ -148,7 +148,7 @@ function it_can_conditionally_add_html() } /** @test */ - function it_can_add_void_items_with_parent_attributes() + public function it_can_add_void_items_with_parent_attributes() { $this->menu = Menu::new()->void(['role' => 'divider', 'data-divider']); @@ -160,7 +160,7 @@ function it_can_add_void_items_with_parent_attributes() } /** @test */ - function it_can_conditionally_add_void_items_with_parent_attributes() + public function it_can_conditionally_add_void_items_with_parent_attributes() { $this->menu = Menu::new() ->voidIf(true, ['class' => 'divider--a']) diff --git a/tests/MenuExtraHtmlTest.php b/tests/MenuExtraHtmlTest.php index 0e5639e..3312847 100644 --- a/tests/MenuExtraHtmlTest.php +++ b/tests/MenuExtraHtmlTest.php @@ -8,7 +8,7 @@ class MenuExtraHtmlTest extends MenuTestCase { /** @test */ - function it_can_prepend_content() + public function it_can_prepend_content() { $this->menu = Menu::new()->prepend('

Hi!

'); @@ -16,7 +16,7 @@ function it_can_prepend_content() } /** @test */ - function it_can_append_content() + public function it_can_append_content() { $this->menu = Menu::new()->append(''); @@ -24,7 +24,7 @@ function it_can_append_content() } /** @test */ - function it_renders_classes() + public function it_renders_classes() { $this->menu = Menu::new()->addClass('menu'); @@ -32,7 +32,7 @@ function it_renders_classes() } /** @test */ - function it_renders_attributes() + public function it_renders_attributes() { $this->menu = Menu::new()->setAttribute('data-role', 'navigation'); @@ -40,7 +40,7 @@ function it_renders_attributes() } /** @test */ - function it_renders_attributes_on_the_list_items() + public function it_renders_attributes_on_the_list_items() { $this->menu = Menu::new() ->add(Link::to('/foo', 'Foo')->setParentAttribute('data-foo')); @@ -53,7 +53,7 @@ function it_renders_attributes_on_the_list_items() } /** @test */ - function it_renders_classes_on_the_list_items() + public function it_renders_classes_on_the_list_items() { $this->menu = Menu::new() ->add(Link::to('/foo', 'Foo')->addParentClass('red')); @@ -66,7 +66,7 @@ function it_renders_classes_on_the_list_items() } /** @test */ - function it_renders_classes_on_the_list_items_when_they_are_active() + public function it_renders_classes_on_the_list_items_when_they_are_active() { $this->menu = Menu::new() ->add(Link::to('/foo', 'Foo')->setActive()->addParentClass('red')); @@ -79,7 +79,7 @@ function it_renders_classes_on_the_list_items_when_they_are_active() } /** @test */ - function it_can_be_wrapped_in_an_element() + public function it_can_be_wrapped_in_an_element() { $this->menu = Menu::new()->link('#', 'Foo')->wrap('div'); diff --git a/tests/MenuPrefixLinksTest.php b/tests/MenuPrefixLinksTest.php index 07e5269..ddcf019 100644 --- a/tests/MenuPrefixLinksTest.php +++ b/tests/MenuPrefixLinksTest.php @@ -8,7 +8,7 @@ class MenuPrefixLinksTest extends MenuTestCase { /** @test */ - function it_can_prefix_link_urls_after_adding_them() + public function it_can_prefix_link_urls_after_adding_them() { $this->menu = Menu::new() ->add(Link::to('/bar', 'Bar')) @@ -22,7 +22,7 @@ function it_can_prefix_link_urls_after_adding_them() } /** @test */ - function it_can_prefix_link_urls_before_adding_them() + public function it_can_prefix_link_urls_before_adding_them() { $this->menu = Menu::new() ->prefixLinks('/foo') diff --git a/tests/MenuSetActiveTest.php b/tests/MenuSetActiveTest.php index 3f45143..0ab7eb7 100644 --- a/tests/MenuSetActiveTest.php +++ b/tests/MenuSetActiveTest.php @@ -8,7 +8,7 @@ class MenuSetActiveTest extends MenuTestCase { /** @test */ - function it_can_set_items_active_with_a_callable() + public function it_can_set_items_active_with_a_callable() { $this->menu = Menu::new() ->add(Link::to('/', 'Home')) @@ -26,7 +26,7 @@ function it_can_set_items_active_with_a_callable() } /** @test */ - function it_can_set_items_active_recursively_through_submenus_with_a_callable() + public function it_can_set_items_active_recursively_through_submenus_with_a_callable() { $this->menu = Menu::new() ->add(Menu::new() @@ -50,7 +50,7 @@ function it_can_set_items_active_recursively_through_submenus_with_a_callable() } /** @test */ - function it_can_set_items_active_from_an_absolute_url() + public function it_can_set_items_active_from_an_absolute_url() { $this->menu = Menu::new() ->add(Link::to('/', 'Home')) @@ -72,7 +72,7 @@ function it_can_set_items_active_from_an_absolute_url() } /** @test */ - function it_can_set_items_active_recursively_through_submenus_from_an_absolute_url() + public function it_can_set_items_active_recursively_through_submenus_from_an_absolute_url() { $this->menu = Menu::new() ->add(Menu::new() @@ -100,7 +100,7 @@ function it_can_set_items_active_recursively_through_submenus_from_an_absolute_u } /** @test */ - function it_can_set_items_active_from_a_relative_url() + public function it_can_set_items_active_from_a_relative_url() { $this->menu = Menu::new() ->add(Link::to('/', 'Home')) @@ -122,7 +122,7 @@ function it_can_set_items_active_from_a_relative_url() } /** @test */ - function it_doesnt_set_items_active_if_the_paths_match_but_they_have_a_different_domain() + public function it_doesnt_set_items_active_if_the_paths_match_but_they_have_a_different_domain() { $this->menu = Menu::new() ->add(Link::to('https://example.com/foo', 'Example Foo')) @@ -138,7 +138,7 @@ function it_doesnt_set_items_active_if_the_paths_match_but_they_have_a_different } /** @test */ - function it_doesnt_set_items_active_if_the_paths_match_but_they_have_a_different_subdomain() + public function it_doesnt_set_items_active_if_the_paths_match_but_they_have_a_different_subdomain() { $this->menu = Menu::new() ->add(Link::to('https://example.com/foo', 'Example Foo')) @@ -154,7 +154,7 @@ function it_doesnt_set_items_active_if_the_paths_match_but_they_have_a_different } /** @test */ - function it_uses_a_request_root_to_ensure_top_level_links_arent_always_active() + public function it_uses_a_request_root_to_ensure_top_level_links_arent_always_active() { $this->menu = Menu::new() ->add(Link::to('/nl', 'Home')) @@ -171,7 +171,7 @@ function it_uses_a_request_root_to_ensure_top_level_links_arent_always_active() '); } - function it_can_render_a_custom_active_class() + public function it_can_render_a_custom_active_class() { $this->menu = Menu::new() ->setActiveClass('-active') diff --git a/tests/MenuSubmenuTest.php b/tests/MenuSubmenuTest.php index 676b0d2..09d94f5 100644 --- a/tests/MenuSubmenuTest.php +++ b/tests/MenuSubmenuTest.php @@ -8,7 +8,7 @@ class MenuSubmenuTest extends MenuTestCase { /** @test */ - function it_can_add_a_submenu_with_a_menu() + public function it_can_add_a_submenu_with_a_menu() { $this->menu = Menu::new()->submenu(Menu::new()); @@ -16,7 +16,7 @@ function it_can_add_a_submenu_with_a_menu() } /** @test */ - function it_can_add_a_submenu_with_a_callable_menu() + public function it_can_add_a_submenu_with_a_callable_menu() { $this->menu = Menu::new()->submenu(function (Menu $menu): Menu { return $menu; @@ -32,7 +32,7 @@ function it_can_add_a_submenu_with_a_callable_menu() } /** @test */ - function it_preserves_filters_with_callable_menus() + public function it_preserves_filters_with_callable_menus() { $this->menu = Menu::new() ->prefixLinks('/bar') @@ -53,7 +53,7 @@ function it_preserves_filters_with_callable_menus() } /** @test */ - function it_can_add_a_submenu_with_a_string_header() + public function it_can_add_a_submenu_with_a_string_header() { $this->menu = Menu::new()->submenu('Hi', Menu::new()); @@ -65,7 +65,7 @@ function it_can_add_a_submenu_with_a_string_header() } /** @test */ - function it_can_add_a_submenu_with_an_item_header() + public function it_can_add_a_submenu_with_an_item_header() { $this->menu = Menu::new()->submenu(Link::to('#', 'Hi'), Menu::new()); @@ -80,7 +80,7 @@ function it_can_add_a_submenu_with_an_item_header() } /** @test */ - function it_can_conditionally_add_a_submenu() + public function it_can_conditionally_add_a_submenu() { $this->menu = Menu::new()->submenuIf(false, Menu::new());