Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
sileence committed May 5, 2024
1 parent 69aeda8 commit e4f624a
Show file tree
Hide file tree
Showing 80 changed files with 369 additions and 714 deletions.
1 change: 1 addition & 0 deletions .phpunit.cache/test-results

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"description": "Enlighten your APIs with auto-generated documentation",
"type": "library",
"require": {
"php": "^7.3|^8.0",
"laravel/framework": "^7.28|^8.0|^9.0|^10.0",
"php": "^8.2",
"laravel/framework": "^11.0",
"ext-json": "*",
"guzzlehttp/guzzle": "^7.2"
},
"require-dev": {
"phpunit/phpunit": "^9.3|^9.5",
"orchestra/testbench": "^5.0|^6.0|^7.0",
"friendsofphp/php-cs-fixer": "^2.16|^3.1"
"phpunit/phpunit": "^11.0.1",
"orchestra/testbench": "^9.0",
"friendsofphp/php-cs-fixer": "^3.1"
},
"license": "MIT",
"authors": [
Expand Down
51 changes: 24 additions & 27 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false"
bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true"
convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false"
stopOnError="false" stopOnFailure="false" verbose="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
<testsuite name="Console">
<directory suffix="Test.php">./tests/Console</directory>
</testsuite>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
<testsuite name="Integration">
<directory suffix="Test.php">./tests/Integration</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_KEY" value="base64:CIjoXm7CcFbLOH9vTdexSSIJGB4tH8vNJ2jKbXcQI4w="/>
</php>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnError="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.1/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
<testsuite name="Console">
<directory suffix="Test.php">./tests/Console</directory>
</testsuite>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
<testsuite name="Integration">
<directory suffix="Test.php">./tests/Integration</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_KEY" value="base64:CIjoXm7CcFbLOH9vTdexSSIJGB4tH8vNJ2jKbXcQI4w="/>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled" />
</php>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
20 changes: 5 additions & 15 deletions src/CodeExamples/CodeExampleCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,12 @@
use Styde\Enlighten\ExampleCreator;
use Throwable;

class CodeExampleCreator
readonly class CodeExampleCreator
{
/**
* @var \Styde\Enlighten\ExampleCreator
*/
private $exampleCreator;

/**
* @var CodeInspector
*/
private $codeInspector;

public function __construct(ExampleCreator $exampleCreator, CodeInspector $codeInspector)
{
$this->exampleCreator = $exampleCreator;
$this->codeInspector = $codeInspector;
public function __construct(
private ExampleCreator $exampleCreator,
private CodeInspector $codeInspector,
) {
}

public function createSnippet(callable $callback, string $key = null)
Expand Down
16 changes: 5 additions & 11 deletions src/CodeExamples/CodeResultExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@

class CodeResultExporter
{
private $currentLevel;
private int $currentLevel;

/**
* @var CodeResultFormat
*/
private $format;

public function __construct(CodeResultFormat $format)
public function __construct(private readonly CodeResultFormat $format)
{
$this->format = $format;
}

public function export($snippet)
Expand All @@ -28,7 +22,7 @@ public function export($snippet)
);
}

private function exportValue($value)
private function exportValue($value): string
{
if (isset($value[ExampleSnippet::CLASS_NAME])) {
return $this->exportObject($value);
Expand All @@ -54,7 +48,7 @@ private function exportValue($value)
return '';
}

private function exportArray($items)
private function exportArray($items): string
{
$result = $this->format->symbol('[').$this->format->line();

Expand All @@ -70,7 +64,7 @@ private function exportArray($items)
return $result;
}

public function isAssoc(array $array)
public function isAssoc(array $array): bool
{
return array_keys($array) !== range(0, count($array) - 1);
}
Expand Down
5 changes: 1 addition & 4 deletions src/CodeExamples/CodeResultTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@

class CodeResultTransformer
{
/**
* @var int
*/
public static $maxNestedLevel = 5;
public static int $maxNestedLevel = 5;

public static function export($result)
{
Expand Down
4 changes: 2 additions & 2 deletions src/CodeExamples/PlainCodeResultFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class PlainCodeResultFormat extends BaseCodeResultFormat
{
public function block(string $code)
public function block(string $code): HtmlString
{
return new HtmlString('<pre>'.$code.'</pre>');
}
Expand Down Expand Up @@ -46,7 +46,7 @@ public function className(string $name): string
return $name;
}

public function propertyName(string $name)
public function propertyName(string $name): string
{
return $name;
}
Expand Down
15 changes: 5 additions & 10 deletions src/Console/Commands/ExportDocumentationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Styde\Enlighten\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Styde\Enlighten\Console\DocumentationExporter;
use Styde\Enlighten\Models\Run;
Expand All @@ -13,19 +14,13 @@ class ExportDocumentationCommand extends Command

protected $description = 'Export the documentation generated by Enlighten as static HTML files';

/**
* @var DocumentationExporter
*/
private $exporter;

public function __construct(DocumentationExporter $exporter)
public function __construct(private readonly DocumentationExporter $exporter)
{
parent::__construct();

$this->exporter = $exporter;
}

public function handle()
public function handle(): void
{
$runs = $this->getLatestRuns();

Expand All @@ -52,15 +47,15 @@ public function handle()
$this->info("`{$selectedRun->signature}` run exported!");
}

protected function getLatestRuns()
protected function getLatestRuns(): Collection
{
return Run::query()
->latest()
->take(5)
->get();
}

private function normalizeBaseUrl($url)
private function normalizeBaseUrl($url): string
{
if (Str::startsWith($url, ['http://', 'https://'])) {
return $url;
Expand Down
14 changes: 7 additions & 7 deletions src/Console/Commands/GenerateDocumentationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct()
$this->ignoreValidationErrors();
}

public function handle()
public function handle(): void
{
$runBuilder = app(RunBuilder::class);

Expand All @@ -43,7 +43,7 @@ public function handle()
}
}

private function addCustomBootstrapToGlobalArguments()
private function addCustomBootstrapToGlobalArguments(): void
{
$_SERVER['argv'] = array_merge(
array_slice($_SERVER['argv'], 0, 2),
Expand All @@ -60,7 +60,7 @@ private function runTests(): void
]);
}

private function printMissingSetupWarning()
private function printMissingSetupWarning(): void
{
$this->output->newLine();
$this->alert('The documentation was not generated');
Expand All @@ -69,7 +69,7 @@ private function printMissingSetupWarning()
$this->warn('Learn more: https://github.com/StydeNet/enlighten#installation');
}

private function printFailedExamples(RunContract $run)
private function printFailedExamples(RunContract $run): void
{
$failedExamples = $run->getFailedExamples();

Expand All @@ -79,7 +79,7 @@ private function printFailedExamples(RunContract $run)
}
}

private function printFailedExamplesHeader($examples)
private function printFailedExamplesHeader($examples): void
{
$this->output->newLine();
$this->error(sprintf(
Expand All @@ -89,7 +89,7 @@ private function printFailedExamplesHeader($examples)
));
}

private function printFailedExampleItems($examples)
private function printFailedExampleItems($examples): void
{
$examples->each(function ($example) {
$this->output->newLine();
Expand All @@ -98,7 +98,7 @@ private function printFailedExampleItems($examples)
});
}

private function printDocumentationLink(RunContract $run)
private function printDocumentationLink(RunContract $run): void
{
$this->output->newLine();
$this->line('⚡ Check your documentation at:');
Expand Down
4 changes: 2 additions & 2 deletions src/Console/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class InstallCommand extends Command

protected $description = 'Install and Enlighten automatically';

public function handle()
public function handle(): void
{
$this->publishBuildAndConfigFiles();

Expand All @@ -36,7 +36,7 @@ private function publishBuildAndConfigFiles(): void
$this->call('vendor:publish', ['--tag' => 'enlighten']);
}

private function setupEnlightenInTestCase()
private function setupEnlightenInTestCase(): bool
{
$appTestCase = File::get(base_path('tests/TestCase.php'));
$baseTestCase = File::get(__DIR__.'/stubs/BaseTestCase.php.stub');
Expand Down
9 changes: 2 additions & 7 deletions src/Console/ContentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,12 @@

class ContentRequest
{
/**
* @var HttpKernel
*/
private $httpKernel;

public function __construct(HttpKernel $httpKernel)
public function __construct(private readonly HttpKernel $httpKernel)
{
$this->httpKernel = $httpKernel;
}

public function getContent(string $url)
public function getContent(string $url): false|string
{
$symfonyRequest = SymfonyRequest::create($url, 'GET');

Expand Down
Loading

0 comments on commit e4f624a

Please sign in to comment.