Skip to content

Commit

Permalink
Upgrade PHPStan, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
shalvah committed Jan 18, 2025
1 parent 8cba63e commit 0faa36a
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
extensions: dom, curl, libxml, mbstring, zip, pdo, sqlite, pdo_sqlite, bcmath, intl, gd

- name: Cache composer dependencies
uses: actions/cache@@v4
uses: actions/cache@v4
with:
path: vendor
key: composer-${{ hashFiles('composer.lock') }}
Expand Down
2 changes: 1 addition & 1 deletion camel/Camel.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static function loadUserDefinedEndpoints(string $folder): array

$userDefinedEndpoints = [];
foreach ($contents as $object) {
// Flysystem v1 had items as arrays; v2 has objects.
// todo Flysystem v1 had items as arrays; v2 has objects.
// v2 allows ArrayAccess, but when we drop v1 support (Laravel <9), we should switch to methods
if (
$object['type'] == 'file'
Expand Down
11 changes: 7 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"ext-json": "*",
"ext-pdo": "*",
"erusev/parsedown": "1.7.4",
"fakerphp/faker": "^1.9.1",
"fakerphp/faker": "^1.23.1",
"illuminate/console": "^8.0|^9.0|^10.0|^11.0",
"illuminate/routing": "^8.0|^9.0|^10.0|^11.0",
"illuminate/support": "^8.0|^9.0|^10.0|^11.0",
Expand All @@ -35,14 +35,14 @@
"symfony/yaml": "^5.4|^6.0|^7.0"
},
"require-dev": {
"brianium/paratest": "^6.0",
"brianium/paratest": "^v6.11.1",
"dms/phpunit-arraysubset-asserts": "^0.4",
"laravel/legacy-factories": "^1.3.0",
"league/fractal": "^0.20",
"nikic/fast-route": "^1.3",
"orchestra/testbench": "^6.0|^7.0|^8.0",
"pestphp/pest": "^1.21",
"phpstan/phpstan": "^1.0",
"phpstan/phpstan": "^2.1.1",
"phpunit/phpunit": "^9.0|^10.0",
"symfony/css-selector": "^5.4|^6.0",
"symfony/dom-crawler": "^5.4|^6.0"
Expand Down Expand Up @@ -78,7 +78,10 @@
"process-timeout": 600,
"allow-plugins": {
"pestphp/pest-plugin": true
}
},
"platform": {
"php": "8.1"
}
},
"replace": {
"mpociot/laravel-apidoc-generator": "*"
Expand Down
9 changes: 8 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
parameters:
level: 5
level: 6
reportUnmatchedIgnoredErrors: true
inferPrivatePropertyTypeFromConstructor: true
ignoreErrors:
- identifier: missingType.iterableValue
- identifier: missingType.return
- identifier: missingType.parameter
- identifier: missingType.generics
- identifier: missingType.property
path: src\Tools\Globals.php
- identifier: argument.templateType
- '#Call to an undefined method ReflectionType::getName\(\).#'
- '#Call to an undefined method Illuminate\\Contracts\\Filesystem\\Filesystem::path\(\)#'
- '#Call to an undefined method Illuminate\\Contracts\\Foundation\\Application::forgetInstance\(\)#'
Expand Down
1 change: 1 addition & 0 deletions src/Commands/GenerateDocumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function handle(RouteMatcherInterface $routeMatcher, GroupedEndpointsFact
$this->writeExampleCustomEndpoint();
}

/** @var Writer $writer */
$writer = app(Writer::class, ['config' => $this->docConfig, 'paths' => $this->paths]);
$writer->writeDocs($groupedEndpoints);

Expand Down
4 changes: 1 addition & 3 deletions src/Extracting/Shared/ResponseFileTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ public static function getResponseContents($filePath, array|string|null $merge):
return json_encode(array_merge(json_decode($content, true), json_decode($json, true)));
}

if (is_array($merge)) {
return json_encode(array_merge(json_decode($content, true), $merge));
}
return json_encode(array_merge(json_decode($content, true), $merge));
}

protected static function getFileContents($filePath): string
Expand Down
6 changes: 1 addition & 5 deletions src/Extracting/Shared/UrlParamsNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,7 @@ protected static function getRouteKeyForUrlParam(
*/
protected static function getInlineRouteKey(Route $route, string $paramName): ?string
{
// Was added in Laravel 7.x
if (method_exists($route, 'bindingFieldFor')) {
return $route->bindingFieldFor($paramName);
}
return null;
return $route->bindingFieldFor($paramName);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/GroupedEndpoints/GroupedEndpointsFromApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private function mergeAnyEndpointDataUpdates(ExtractedEndpointData $endpointData
protected function writeEndpointsToDisk(array $grouped): void
{
Utils::deleteFilesMatching(static::$camelDir, function ($file) {
/** @var $file array|\League\Flysystem\StorageAttributes */
/** @var array|\League\Flysystem\StorageAttributes $file */
return !Str::startsWith(basename($file['path']), 'custom.');
});
Utils::deleteDirectoryAndContents(static::$cacheDir);
Expand Down
10 changes: 7 additions & 3 deletions src/Writing/Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Knuckles\Scribe\Writing;

use Illuminate\Support\Facades\Storage;
use Knuckles\Camel\Output\OutputEndpointData;
use Knuckles\Scribe\Tools\ConsoleOutputUtils as c;
use Knuckles\Scribe\Tools\DocumentationConfig;
use Knuckles\Scribe\Tools\Globals;
Expand Down Expand Up @@ -46,9 +47,9 @@ public function __construct(protected DocumentationConfig $config, public PathCo
}

/**
* @param array[] $groupedEndpoints
* @param array<string,array> $groupedEndpoints
*/
public function writeDocs(array $groupedEndpoints)
public function writeDocs(array $groupedEndpoints): void
{
// The static assets (js/, css/, and images/) always go in public/docs/.
// For 'static' docs, the output files (index.html, collection.json) go in public/docs/.
Expand Down Expand Up @@ -178,12 +179,15 @@ protected function performFinalTasksForLaravelType(): void
$contents = str_replace('href="../docs/collection.json"', 'href="{{ route("' . $this->paths->outputPath('postman', '.') . '") }}"', $contents);
$contents = str_replace('href="../docs/openapi.yaml"', 'href="{{ route("' . $this->paths->outputPath('openapi', '.') . '") }}"', $contents);
$contents = str_replace('url="../docs/openapi.yaml"', 'url="{{ route("' . $this->paths->outputPath('openapi', '.') . '") }}"', $contents);
// With Elements theme, we'd have <elements-api apiDescriptionUrl="../docs/openapi.yaml"
// With Elements theme, we'd have <elements-api apiDescriptionUrl="../docs/openapi.yaml"
$contents = str_replace('Url="../docs/openapi.yaml"', 'Url="{{ route("' . $this->paths->outputPath('openapi', '.') . '") }}"', $contents);

file_put_contents("$this->laravelTypeOutputPath/index.blade.php", $contents);
}

/**
* @param array[] $groupedEndpoints
*/
public function writeHtmlDocs(array $groupedEndpoints): void
{
c::info('Writing ' . ($this->isStatic ? 'HTML' : 'Blade') . ' docs...');
Expand Down

0 comments on commit 0faa36a

Please sign in to comment.