Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation menu item referencing internal Find Rules page #2514

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions resources/views/docs/section.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,32 @@
<ul class="mt-3">
<li>
<a
href="{{ action(\App\Controller\DocumentationController::class) }}"
href="{{ action(\App\Controller\DocumentationController::class) }}"
>Introduction</a>
</li>
</ul>

@foreach ($documentations_sections_by_category as $category => $documentation_sections)
@foreach ($documentation_menu_categories as $category => $documentation_menu_items)
<hr class="border-line">

<h4 class="mt-4 mb-3">{{ $category }}</h4>

<ul>
@foreach ($documentation_sections as $documentation_section)
@foreach ($documentation_menu_items as $documentation_menu_item)
@php
/** @var $documentation_section \App\ValueObject\DocumentationSection */
/** @var $documentation_menu_item \App\Documentation\DocumentationMenuItem */
@endphp

<li>
@if ($documentation_section->isNew())
@if ($documentation_menu_item->isNew())
<div class="badge text-white bg-danger">NEW</div>
&nbsp;
@endif

<a href="{{ action(\App\Controller\DocumentationController::class, ['section' => $documentation_section->getSlug()]) }}"
class="{{ $documentation_section->isNew() ? 'text-bold' : '' }}"
<a href="{{ $documentation_menu_item->getHref() }}"
class="{{ $documentation_menu_item->isNew() ? 'text-bold' : '' }}"
>
{{ $documentation_section->getName() }}

{{ $documentation_menu_item->getLabel() }}

</a>
</li>
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/DocumentationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __invoke(string $section = 'introduction'): View
return \view('docs/section', [
'section_title' => $this->documentationMenuFactory->createSectionTitle($section),
'section_markdown_contents' => $markdownContents,
'documentations_sections_by_category' => $this->documentationMenuFactory->create(),
'documentation_menu_categories' => $this->documentationMenuFactory->create(),
]);
}
}
67 changes: 44 additions & 23 deletions src/Documentation/DocumentationMenuFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,68 @@

namespace App\Documentation;

use App\ValueObject\DocumentationSection;
use App\Controller\FilterRectorController;

/**
* @see \App\Tests\Documentation\DocumentationMenuFactoryTest
*/
final class DocumentationMenuFactory
{
public function __construct(
private DocumentationMenuItemFactory $documentationMenuItemFactory
) {
}

/**
* @return array<string, DocumentationSection[]>
* @return array<string, DocumentationMenuItem[]>
*/
public function create(): array
{
return [
'First Steps' => [
new DocumentationSection('integration-to-new-project', 'New Project', true),
new DocumentationSection('define-paths', 'Define Paths'),
new DocumentationSection('set-lists', 'Set Lists'),
new DocumentationSection('ignoring-rules-or-paths', 'Ignoring Rules or Paths'),
new DocumentationSection('import-names', 'Import Names'),
new DocumentationSection('configured-rules', 'Configured Rules'),
$this->documentationMenuItemFactory->createSection('integration-to-new-project', 'New Project', true),
$this->documentationMenuItemFactory->createSection('define-paths', 'Define Paths'),
$this->documentationMenuItemFactory->createSection('set-lists', 'Set Lists'),
$this->documentationMenuItemFactory->createInternalLink(FilterRectorController::class, 'Find Rules'),
$this->documentationMenuItemFactory->createSection(
'ignoring-rules-or-paths',
'Ignoring Rules or Paths'
),
$this->documentationMenuItemFactory->createSection('import-names', 'Import Names'),
$this->documentationMenuItemFactory->createSection('configured-rules', 'Configured Rules'),
],
'Configuration' => [
new DocumentationSection('static-reflection-and-autoload', 'Static Reflection And Autoload'),
new DocumentationSection('config-configuration', 'Config Configuration'),
new DocumentationSection('php-version-features', 'PHP Version Features'),
new DocumentationSection('commands', 'Commands', true),
new DocumentationSection('team-tools', 'Team Tools', true),
$this->documentationMenuItemFactory->createSection(
'static-reflection-and-autoload',
'Static Reflection And Autoload'
),
$this->documentationMenuItemFactory->createSection('config-configuration', 'Config Configuration'),
$this->documentationMenuItemFactory->createSection('php-version-features', 'PHP Version Features'),
$this->documentationMenuItemFactory->createSection('commands', 'Commands', true),
$this->documentationMenuItemFactory->createSection('team-tools', 'Team Tools', true),
],
'Testing and CI' => [
new DocumentationSection('cache-in-ci', 'Cache in CI'),
new DocumentationSection('debugging', 'Debugging'),
new DocumentationSection('troubleshooting-parallel', 'Troubleshooting Parallel'),
new DocumentationSection('reporting-issue-with-rector', 'Reporting Issue With Rector'),
$this->documentationMenuItemFactory->createSection('cache-in-ci', 'Cache in CI'),
$this->documentationMenuItemFactory->createSection('debugging', 'Debugging'),
$this->documentationMenuItemFactory->createSection(
'troubleshooting-parallel',
'Troubleshooting Parallel'
),
$this->documentationMenuItemFactory->createSection(
'reporting-issue-with-rector',
'Reporting Issue With Rector'
),
],
'Advanced' => [
new DocumentationSection('how-rector-works', 'How Rector Works'),
new DocumentationSection('custom-rule', 'Custom Rule'),
new DocumentationSection('writing-tests-for-custom-rule', 'Writing Tests For Custom Rule'),
new DocumentationSection('rules-overview', 'Rules Overview'),
new DocumentationSection('creating-a-node-visitor', 'Creating Node Visitor'),
new DocumentationSection('how-to-run-on-php-53', 'Run on PHP 5.3', true),
$this->documentationMenuItemFactory->createSection('how-rector-works', 'How Rector Works'),
$this->documentationMenuItemFactory->createSection('custom-rule', 'Custom Rule'),
$this->documentationMenuItemFactory->createSection(
'writing-tests-for-custom-rule',
'Writing Tests For Custom Rule'
),
$this->documentationMenuItemFactory->createSection('rules-overview', 'Rules Overview'),
$this->documentationMenuItemFactory->createSection('creating-a-node-visitor', 'Creating Node Visitor'),
$this->documentationMenuItemFactory->createSection('how-to-run-on-php-53', 'Run on PHP 5.3', true),
],
];
}
Expand Down
30 changes: 30 additions & 0 deletions src/Documentation/DocumentationMenuItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace App\Documentation;

class DocumentationMenuItem
{
public function __construct(
private string $href,
private string $label,
private bool $isNew = false,
) {
}

public function getHref(): string
{
return $this->href;
}

public function getLabel(): string
{
return $this->label;
}

public function isNew(): bool
{
return $this->isNew;
}
}
45 changes: 45 additions & 0 deletions src/Documentation/DocumentationMenuItemFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace App\Documentation;

use App\Controller\DocumentationController;
use Illuminate\Contracts\Routing\UrlGenerator;
use Illuminate\Routing\Controller;

final class DocumentationMenuItemFactory
{
public function __construct(
private UrlGenerator $urlGenerator
) {
}

public function createSection(string $slug, string $name, bool $isNew = false): DocumentationMenuItem
{
return new DocumentationMenuItem(
$this->urlGenerator->action(DocumentationController::class, [
'section' => $slug,
]),
$name,
$isNew
);

}

/**
* @param class-string<Controller>|list<class-string<Controller>|string> $actionController
*/
public function createInternalLink(
string|array $actionController,
string $label,
mixed $actionParameters = null,
bool $isNew = false,
): DocumentationMenuItem {
return new DocumentationMenuItem(
$this->urlGenerator->action($actionController, $actionParameters),
$label,
$isNew,
);
}
}
33 changes: 0 additions & 33 deletions src/ValueObject/DocumentationSection.php

This file was deleted.

15 changes: 12 additions & 3 deletions tests/Documentation/DocumentationMenuFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
namespace App\Tests\Documentation;

use App\Documentation\DocumentationMenuFactory;
use App\ValueObject\DocumentationSection;
use App\Documentation\DocumentationMenuItem;
use App\Documentation\DocumentationMenuItemFactory;
use Illuminate\Contracts\Routing\UrlGenerator;
use PHPUnit\Framework\TestCase;

final class DocumentationMenuFactoryTest extends TestCase
Expand All @@ -14,7 +16,14 @@ final class DocumentationMenuFactoryTest extends TestCase

protected function setUp(): void
{
$this->documentationMenuFactory = new DocumentationMenuFactory();
$urlGenerator = $this->createMock(UrlGenerator::class);
$urlGenerator->expects($this->any())
->method('action')
->willReturn('/index.html');

$this->documentationMenuFactory = new DocumentationMenuFactory(
new DocumentationMenuItemFactory($urlGenerator)
);
}

public function testSectionTitle(): void
Expand All @@ -29,7 +38,7 @@ public function testCategory(): void

foreach ($documentationSectionsByCategory as $category => $documentationSections) {
$this->assertIsString($category);
$this->assertContainsOnlyInstancesOf(DocumentationSection::class, $documentationSections);
$this->assertContainsOnlyInstancesOf(DocumentationMenuItem::class, $documentationSections);
}
}
}
Loading