Skip to content

Commit

Permalink
Merge pull request #8 from spatie/analysis-8LmYMK
Browse files Browse the repository at this point in the history
Applied fixes from StyleCI
  • Loading branch information
sebastiandedeyne authored Aug 29, 2016
2 parents 5982b78 + 438ed79 commit 776c95c
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 60 deletions.
2 changes: 1 addition & 1 deletion src/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, '/');
}

/**
Expand Down
15 changes: 7 additions & 8 deletions src/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
}

Expand Down
1 change: 0 additions & 1 deletion src/Traits/HtmlAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Spatie\Menu\Traits;

use Spatie\HtmlElement\Attributes;
use Spatie\Menu\Helpers\Arr;

trait HtmlAttributes
{
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/ParentAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function setParentAttribute(string $attribute, string $value = '')
public function setParentAttributes(array $attributes)
{
$this->parentAttributes->setAttributes($attributes);

return $this;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Items/HtmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class HtmlTest extends \PHPUnit_Framework_TestCase
{
/** @test */
function it_contains_html()
public function it_contains_html()
{
$this->assertEquals(
'Hello world',
Expand All @@ -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());
}
Expand Down
20 changes: 10 additions & 10 deletions tests/Items/LinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class LinkTest extends \PHPUnit_Framework_TestCase
{
/** @test */
function it_contains_text()
public function it_contains_text()
{
$this->assertEquals(
'Home',
Expand All @@ -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',
Expand All @@ -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,
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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(
'<a href="https://spatie.be">Home</a>',
Expand All @@ -61,7 +61,7 @@ function it_can_be_rendered()
}

/** @test */
function it_can_render_classes()
public function it_can_render_classes()
{
$this->assertEquals(
'<a href="https://spatie.be" class="home">Home</a>',
Expand All @@ -70,7 +70,7 @@ function it_can_render_classes()
}

/** @test */
function it_can_render_attributes()
public function it_can_render_attributes()
{
$this->assertEquals(
'<a href="https://spatie.be" data-home-link>Home</a>',
Expand All @@ -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',
Expand All @@ -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',
Expand Down
24 changes: 12 additions & 12 deletions tests/MenuAddTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
class MenuAddTest extends MenuTestCase
{
/** @test */
function it_starts_as_an_empty_list()
public function it_starts_as_an_empty_list()
{
$this->menu = Menu::new();

$this->assertRenders('<ul></ul>');
}

/** @test */
function an_item_can_be_added()
public function an_item_can_be_added()
{
$this->menu = Menu::new()->add(Link::to('#', 'Hello'));

Expand All @@ -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');

Expand All @@ -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'))
Expand All @@ -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());
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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'))
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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']);

Expand All @@ -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'])
Expand Down
16 changes: 8 additions & 8 deletions tests/MenuExtraHtmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,39 @@
class MenuExtraHtmlTest extends MenuTestCase
{
/** @test */
function it_can_prepend_content()
public function it_can_prepend_content()
{
$this->menu = Menu::new()->prepend('<h1>Hi!</h1>');

$this->assertRenders('<h1>Hi!</h1><ul></ul>');
}

/** @test */
function it_can_append_content()
public function it_can_append_content()
{
$this->menu = Menu::new()->append('<aside>Bye!</aside>');

$this->assertRenders('<ul></ul><aside>Bye!</aside>');
}

/** @test */
function it_renders_classes()
public function it_renders_classes()
{
$this->menu = Menu::new()->addClass('menu');

$this->assertRenders('<ul class="menu"></ul>');
}

/** @test */
function it_renders_attributes()
public function it_renders_attributes()
{
$this->menu = Menu::new()->setAttribute('data-role', 'navigation');

$this->assertRenders('<ul data-role="navigation"></ul>');
}

/** @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'));
Expand All @@ -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'));
Expand All @@ -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'));
Expand All @@ -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');

Expand Down
4 changes: 2 additions & 2 deletions tests/MenuPrefixLinksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand All @@ -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')
Expand Down
Loading

0 comments on commit 776c95c

Please sign in to comment.