Skip to content
This repository has been archived by the owner on Oct 18, 2020. It is now read-only.

Commit

Permalink
Remove Array variants of methods
Browse files Browse the repository at this point in the history
  • Loading branch information
d13r committed Jun 26, 2017
1 parent 8dcc134 commit 9fba0ef
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 213 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -711,9 +711,16 @@ Breadcrumbs::register('name', function ($breadcrumbs, $page) {
- Add [package auto-discovery](https://laravel-news.com/package-auto-discovery)
- Add type hints to all methods
- Add more specific exception classes
- Remove `Array` variants of methods (use [variadic arguments](https://php.net/manual/en/migration56.new-features.php#migration56.new-features.variadics) instead
- `Breadcrumbs::renderArray($page, $params)``Breadcrumbs::render($page, ...$params)`
- `Breadcrumbs::generateArray($page, $params)``Breadcrumbs::generate($page, ...$params)`
- `Breadcrumbs::renderIfExistsArray($page, $params)``Breadcrumbs::renderIfExists($page, ...$params)`
- `Breadcrumbs::generateIfExistsArray($page, $params)``Breadcrumbs::generateIfExists($page, ...$params)`
- `Breadcrumbs::renderArrayIfExists($name, $params)``Breadcrumbs::renderIfExists($page, ...$params)`
- `Breadcrumbs::generateArrayIfExists($name, $params)``Breadcrumbs::generateIfExists($page, ...$params)`
- `Breadcrumbs::setCurrentRouteArray($name, $params)``Breadcrumbs::setCurrentRoute($page, ...$params)`
- `$breadcrumbs->parentArray($name, $params)``$breadcrumbs->parent($name, ...$params)`
- Remove deprecated features & methods:
- `Breadcrumbs::renderArrayIfExists()` (use `Breadcrumbs::renderIfExistsArray()` instead)
- `Breadcrumbs::generateArrayIfExists()` (use `Breadcrumbs::generateIfExistsArray()` instead)
- `app/Http/breadcrumbs.php` file (use `routes/breadcrumbs.php` instead)
- `laravel-breadcrumbs::` view prefix (use `breadcrumbs::` instead)
- `$app['breadcrumbs']` container short name (use `Breadcrumbs::` facade or `DaveJamesMiller\Breadcrumbs\Manager` type hint)
Expand Down
14 changes: 0 additions & 14 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,6 @@ public function parent(string $name, ...$params) //: void
$this->call($name, $params);
}

/**
* Add breadcrumbs for a parent page, with an array of parameters.
*
* Should be called from the closure for a page, before `push()` is called.
*
* @param string $name The name of the parent page.
* @param array $params The parameters to pass to the closure.
* @throws InvalidBreadcrumbException
*/
public function parentArray(string $name, array $params) //: void
{
$this->call($name, $params);
}

/**
* Add a breadcrumb.
*
Expand Down
81 changes: 0 additions & 81 deletions src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,6 @@ public function generate(string $name = null, ...$params): array
return $this->generator->generate($this->callbacks, $name, $params);
}

/**
* Generate a set of breadcrumbs for a page, with an array of parameters.
*
* @param string|null $name The name of the current page.
* @param array $params The parameters to pass to the closure for the current page.
* @return array The generated breadcrumbs.
* @throws InvalidBreadcrumbException if the name is (or any ancestor names are) not registered.
*/
public function generateArray(string $name, array $params = []): array
{
return $this->generator->generate($this->callbacks, $name, $params);
}

/**
* Generate a set of breadcrumbs for a page.
*
Expand Down Expand Up @@ -141,24 +128,6 @@ public function generateIfExists(string $name = null, ...$params): array
}
}

/**
* Generate a set of breadcrumbs for a page, with an array of parameters.
*
* Returns an empty array if the page doesn't exist, instead of throwing an exception.
*
* @param string|null $name The name of the current page.
* @param array $params The parameters to pass to the closure for the current page.
* @return array The generated breadcrumbs.
*/
public function generateIfExistsArray(string $name, array $params = []): array
{
try {
return $this->generator->generate($this->callbacks, $name, $params);
} catch (InvalidBreadcrumbException $e) {
return [];
}
}

/**
* Render breadcrumbs for a page.
*
Expand All @@ -180,22 +149,6 @@ public function render(string $name = null, ...$params): string
return $this->view->render($this->viewName, $breadcrumbs);
}

/**
* Render breadcrumbs for a page, with an array of parameters.
*
* @param string|null $name The name of the current page.
* @param array $params The parameters to pass to the closure for the current page.
* @return string The generated HTML.
* @throws InvalidBreadcrumbException if the name is (or any ancestor names are) not registered.
* @throws InvalidViewException if no view has been set.
*/
public function renderArray(string $name, array $params = []): string
{
$breadcrumbs = $this->generator->generate($this->callbacks, $name, $params);

return $this->view->render($this->viewName, $breadcrumbs);
}

/**
* Render breadcrumbs for a page.
*
Expand Down Expand Up @@ -226,27 +179,6 @@ public function renderIfExists(string $name = null, ...$params): string
return $this->view->render($this->viewName, $breadcrumbs);
}

/**
* Render breadcrumbs for a page, with an array of parameters.
*
* Returns an empty string if the page doesn't exist, instead of throwing an exception.
*
* @param string|null $name The name of the current page.
* @param array $params The parameters to pass to the closure for the current page.
* @return string The generated HTML.
* @throws InvalidViewException if no view has been set.
*/
public function renderIfExistsArray(string $name, array $params = []): string
{
try {
$breadcrumbs = $this->generator->generate($this->callbacks, $name, $params);
} catch (InvalidBreadcrumbException $e) {
return '';
}

return $this->view->render($this->viewName, $breadcrumbs);
}

/**
* Set the current route name and parameters to use when calling render() or generate() with no parameters.
*
Expand All @@ -259,19 +191,6 @@ public function setCurrentRoute(string $name, ...$params) //: void
$this->currentRoute->set($name, $params);
}

/**
* Set the current route name and parameters to use when calling render() or generate() with no parameters, with an
* array of parameters.
*
* @param string $name The name of the current page.
* @param array $params The parameters to pass to the closure for the current page.
* @return void
*/
public function setCurrentRouteArray(string $name, array $params = []) //: void
{
$this->currentRoute->set($name, $params);
}

/**
* Clear the previously set route name and parameters to use when calling render() or generate() with no parameters.
*
Expand Down
14 changes: 0 additions & 14 deletions tests/unit/GeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,6 @@ public function testParent_name_params()
], 'sample', []);
}

// $breadcrumbs->parentArray($name, $params)
public function testParentArray_name_params()
{
$breadcrumbs = $this->generator->generate([
'parent' => function ($breadcrumbs, $num, $text) {
$this->assertSame(1, $num);
$this->assertSame('blah', $text);
},
'sample' => function ($breadcrumbs) {
$breadcrumbs->parentArray('parent', [1, 'blah']);
},
], 'sample', []);
}

// $breadcrumb->first
// $breadcrumb->last
public function testFirstLast()
Expand Down
102 changes: 0 additions & 102 deletions tests/unit/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,6 @@ public function testGenerate_name_params()
$this->assertSame(['generated'], $this->manager->generate('sample', 1, 'blah'));
}

// Breadcrumbs::generateArray($name, $params) -> array
public function testGenerateArray_name_params()
{
$fn = $this->register('sample');

$this->generator
->shouldReceive('generate')
->with(['sample' => $fn], 'sample', [1, 'blah'])
->once()
->andReturn(['generated']);;

$this->assertSame(['generated'], $this->manager->generateArray('sample', [1, 'blah']));
}

// Breadcrumbs::generateIfExists() -> array
public function testGenerateIfExists_existing()
{
Expand Down Expand Up @@ -207,31 +193,6 @@ public function testGenerateIfExists_name_params_nonexistant()
$this->assertSame([], $this->manager->generateIfExists('sample', 1, 'blah'));
}

// Breadcrumbs::generateIfExistsArray($name, $params) -> array
public function testGenerateIfExistsArray_name_params_existing()
{
$fn = $this->register('sample');

$this->generator
->shouldReceive('generate')
->with(['sample' => $fn], 'sample', [1, 'blah'])
->once()
->andReturn(['generated']);

$this->assertSame(['generated'], $this->manager->generateIfExistsArray('sample', [1, 'blah']));
}

public function testGenerateIfExistsArray_name_params_nonexistant()
{
$this->generator
->shouldReceive('generate')
->with([], 'sample', [1, 'blah'])
->once()
->andThrow(InvalidBreadcrumbException::class, 'Breadcrumb not found with name "sample"');

$this->assertSame([], $this->manager->generateIfExistsArray('sample', [1, 'blah']));
}

// Breadcrumbs::render() -> array
public function testRender()
{
Expand Down Expand Up @@ -292,25 +253,6 @@ public function testRender_name_params()
$this->assertSame('rendered', $this->manager->render('sample', 1, 'blah'));
}

// Breadcrumbs::renderArray($name, $params) -> array
public function testRenderArray_name_params()
{
$fn = $this->register('sample');

$this->generator
->shouldReceive('generate')
->with(['sample' => $fn], 'sample', [1, 'blah'])
->once()
->andReturn(['generated']);;
$this->view
->shouldReceive('render')
->with('view', ['generated'])
->once()
->andReturn('rendered');

$this->assertSame('rendered', $this->manager->renderArray('sample', [1, 'blah']));
}

// Breadcrumbs::renderIfExists() -> array
public function testRenderIfExists_existing()
{
Expand Down Expand Up @@ -431,39 +373,6 @@ public function testRenderIfExists_name_params_nonexistant()
$this->assertSame('', $this->manager->renderIfExists('sample', 1, 'blah'));
}

// Breadcrumbs::renderIfExistsArray($name, $params) -> array
public function testRenderIfExistsArray_name_params_existing()
{
$fn = $this->register('sample');

$this->generator
->shouldReceive('generate')
->with(['sample' => $fn], 'sample', [1, 'blah'])
->once()
->andReturn(['generated']);
$this->view
->shouldReceive('render')
->with('view', ['generated'])
->once()
->andReturn('rendered');

$this->assertSame('rendered', $this->manager->renderIfExistsArray('sample', [1, 'blah']));
}

public function testRenderIfExistsArray_name_params_nonexistant()
{
$this->generator
->shouldReceive('generate')
->with([], 'sample', [1, 'blah'])
->once()
->andThrow(InvalidBreadcrumbException::class, 'Breadcrumb not found with name "sample"');
$this->view
->shouldReceive('render')
->never();

$this->assertSame('', $this->manager->renderIfExistsArray('sample', [1, 'blah']));
}

// Breadcrumbs::setCurrentRoute($name)
public function testSetCurrentRoute_name()
{
Expand All @@ -486,17 +395,6 @@ public function testSetCurrentRoute_name_params()
$this->manager->setCurrentRoute('sample', 1, 'blah');
}

// Breadcrumbs::setCurrentRouteArray($name, $params)
public function testSetCurrentRouteArray_name_params()
{
$this->currentRoute
->shouldReceive('set')
->with('sample', [1, 'blah'])
->once();

$this->manager->setCurrentRouteArray('sample', [1, 'blah']);
}

// Breadcrumbs::clearCurrentRoute()
public function testClearCurrentRoute()
{
Expand Down

0 comments on commit 9fba0ef

Please sign in to comment.