Skip to content

Commit

Permalink
Dev tools (#1243)
Browse files Browse the repository at this point in the history
* Add .gitattributes and .editorconfig
* Add basic fixer to ensure we have a @license docblock
* Add missing dev autoload config
  • Loading branch information
DerManoMann authored May 20, 2022
1 parent 117caa0 commit 46c3e4c
Show file tree
Hide file tree
Showing 10 changed files with 289 additions and 157 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
; top-most EditorConfig file
root = true

; Unix-style newlines
[*]
charset = utf-8
end_of_line = LF
insert_final_newline = true
trim_trailing_whitespace = true

[*.{php,json,yaml}]
indent_style = space
indent_size = 4
12 changes: 12 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/.* export-ignore
/tools/ export-ignore
/phpstan*.neon export-ignore
/phpunit.xml.dist export-ignore
/psalm*.xml export-ignore
/tests/ export-ignore

* text=auto eol=lf
*.json text whitespace=blank-at-eol,blank-at-eof,space-before-tab,tab-in-indent,tabwidth=4
*.md text whitespace=blank-at-eol,blank-at-eof
*.php text whitespace=blank-at-eol,blank-at-eof,space-before-tab,tab-in-indent,tabwidth=4 diff=php
*.yml text whitespace=blank-at-eol,blank-at-eof,space-before-tab,tab-in-indent,tabwidth=4
8 changes: 7 additions & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
<?php

use OpenApi\Tools\CSFixer\LicenseFixer;

$finder = PhpCsFixer\Finder::create()
->path('src')->name('*.php')
->path('tests')->name('*.php')
->path('Examples')->name('*.php')
//->exclude('tests/Fixtures')
->path('tools')->name('*.php')
->in(__DIR__)
;

return (new PhpCsFixer\Config())
->registerCustomFixers([
new LicenseFixer(),
])
->setRules([
'@PSR2' => true,
'@DoctrineAnnotation' => true,
'OpenApi/license' => true,
'array_syntax' => ['syntax' => 'short'],
'no_unused_imports' => true,
'blank_line_before_statement' => ['statements' => ['return']],
Expand Down
215 changes: 108 additions & 107 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,112 +1,113 @@
{
"name": "zircote/swagger-php",
"type": "library",
"license": "Apache-2.0",
"bin": [
"bin/openapi"
],
"description": "swagger-php - Generate interactive documentation for your RESTful API using phpdoc annotations",
"keywords": [
"json",
"rest",
"api",
"service discovery"
],
"homepage": "https://github.com/zircote/swagger-php/",
"authors": [
{
"name": "Robert Allen",
"email": "zircote@gmail.com"
},
{
"name": "Bob Fanger",
"email": "bfanger@gmail.com",
"homepage": "https://bfanger.nl"
},
{
"name": "Martin Rademacher",
"email": "mano@radebatz.net",
"homepage": "https://radebatz.net"
}
],
"config": {
"bin-dir": "bin",
"optimize-autoloader": true,
"sort-packages": true,
"allow-plugins": {
"composer/package-versions-deprecated": true
}
},
"minimum-stability": "stable",
"extra": {
"branch-alias": {
"dev-master": "4.x-dev"
}
},
"require": {
"php": ">=7.2",
"ext-json": "*",
"doctrine/annotations": "^1.7",
"psr/log": "^1.1 || ^2.0 || 3.0",
"symfony/finder": ">=2.2",
"symfony/yaml": ">=3.3"
},
"autoload": {
"psr-4": {
"OpenApi\\": "src"
}
},
"require-dev": {
"composer/package-versions-deprecated": "^1.11",
"friendsofphp/php-cs-fixer": "^2.17 || ^3.0",
"phpstan/phpstan": "^1.6",
"phpunit/phpunit": ">=8",
"vimeo/psalm": "^4.23"
},
"autoload-dev": {
"exclude-from-classmap": [
"/tests/Fixtures"
],
"psr-4": {
"OpenApi\\Tests\\": "tests/",
"AnotherNamespace\\": "tests/Fixtures/AnotherNamespace",
"OpenApi\\Tests\\Fixtures\\Annotations\\": "tests/Fixtures/Annotations"
}
},
"scripts-descriptions": {
"cs": "Fix all codestyle issues",
"lint": "Test codestyle",
"test": "Run all non-legacy and codestyle tests",
"testlegacy": "Run tests using the legacy TokenAnalyser",
"testall": "Run all tests (test + testlegacy)",
"analyse": "Run static analysis (phpstan/psalm)",
"spectral": "Run spectral lint over all .yaml files in the Examples folder",
"docs:refgen": "Rebuild the annotations/attributes reference markup files",
"docs:dev": "Run dev server for local development of gh-pages",
"docs:build": "Re-build static gh-pages"
},
"scripts": {
"cs": "php-cs-fixer fix --allow-risky=yes",
"lint": "@cs --dry-run",
"test": [
"phpunit",
"@lint"
"name": "zircote/swagger-php",
"type": "library",
"license": "Apache-2.0",
"bin": [
"bin/openapi"
],
"testlegacy": "export PHPUNIT_ANALYSER=legacy && phpunit",
"testall": [
"@test",
"@testlegacy"
"description": "swagger-php - Generate interactive documentation for your RESTful API using phpdoc annotations",
"keywords": [
"json",
"rest",
"api",
"service discovery"
],
"analyse": [
"phpstan analyse --memory-limit=2G",
"psalm"
"homepage": "https://github.com/zircote/swagger-php/",
"authors": [
{
"name": "Robert Allen",
"email": "zircote@gmail.com"
},
{
"name": "Bob Fanger",
"email": "bfanger@gmail.com",
"homepage": "https://bfanger.nl"
},
{
"name": "Martin Rademacher",
"email": "mano@radebatz.net",
"homepage": "https://radebatz.net"
}
],
"spectral": "for ff in `find Examples -name '*.yaml'`; do spectral lint $ff; done",
"docs:refgen": "php docs/refgen.php",
"docs:dev": "cd docs && npm run dev",
"docs:build": [
"@docs:refgen",
"cd docs && npm run build"
]
}
"config": {
"bin-dir": "bin",
"optimize-autoloader": true,
"sort-packages": true,
"allow-plugins": {
"composer/package-versions-deprecated": true
}
},
"minimum-stability": "stable",
"extra": {
"branch-alias": {
"dev-master": "4.x-dev"
}
},
"require": {
"php": ">=7.2",
"ext-json": "*",
"doctrine/annotations": "^1.7",
"psr/log": "^1.1 || ^2.0 || 3.0",
"symfony/finder": ">=2.2",
"symfony/yaml": ">=3.3"
},
"autoload": {
"psr-4": {
"OpenApi\\": "src"
}
},
"require-dev": {
"composer/package-versions-deprecated": "^1.11",
"friendsofphp/php-cs-fixer": "^2.17 || ^3.0",
"phpstan/phpstan": "^1.6",
"phpunit/phpunit": ">=8",
"vimeo/psalm": "^4.23"
},
"autoload-dev": {
"exclude-from-classmap": [
"/tests/Fixtures"
],
"psr-4": {
"OpenApi\\Tools\\": "tools/src/",
"OpenApi\\Tests\\": "tests/",
"AnotherNamespace\\": "tests/Fixtures/AnotherNamespace",
"OpenApi\\Tests\\Fixtures\\Annotations\\": "tests/Fixtures/Annotations"
}
},
"scripts-descriptions": {
"cs": "Fix all codestyle issues",
"lint": "Test codestyle",
"test": "Run all non-legacy and codestyle tests",
"testlegacy": "Run tests using the legacy TokenAnalyser",
"testall": "Run all tests (test + testlegacy)",
"analyse": "Run static analysis (phpstan/psalm)",
"spectral": "Run spectral lint over all .yaml files in the Examples folder",
"docs:refgen": "Rebuild the annotations/attributes reference markup files",
"docs:dev": "Run dev server for local development of gh-pages",
"docs:build": "Re-build static gh-pages"
},
"scripts": {
"cs": "php-cs-fixer fix --allow-risky=yes",
"lint": "@cs --dry-run",
"test": [
"phpunit",
"@lint"
],
"testlegacy": "export PHPUNIT_ANALYSER=legacy && phpunit",
"testall": [
"@test",
"@testlegacy"
],
"analyse": [
"phpstan analyse --memory-limit=2G",
"psalm"
],
"spectral": "for ff in `find Examples -name '*.yaml'`; do spectral lint $ff; done",
"docs:refgen": "php tools/refgen.php",
"docs:dev": "cd docs && npm run dev",
"docs:build": [
"@docs:refgen",
"cd docs && npm run build"
]
}
}
4 changes: 4 additions & 0 deletions src/Processors/CleanUnusedComponents.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php declare(strict_types=1);

/**
* @license Apache 2.0
*/

namespace OpenApi\Processors;

use OpenApi\Analysis;
Expand Down
4 changes: 4 additions & 0 deletions src/Processors/DocblockTrait.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

/**
* @license Apache 2.0
*/

namespace OpenApi\Processors;

use OpenApi\Annotations\AbstractAnnotation;
Expand Down
20 changes: 20 additions & 0 deletions tools/refgen.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php declare(strict_types=1);

require_once __DIR__ . '/../vendor/autoload.php';

use OpenApi\Tools\Docs\RefGenerator;

$refgen = new RefGenerator(__DIR__ . '/../');

foreach ($refgen->types() as $type) {
ob_start();

echo $refgen->preamble($type);
foreach ($refgen->classesForType($type) as $name => $details) {
echo $refgen->formatHeader($name, $type);
$method = "format{$type}Details";
echo $refgen->$method($name, $details['fqdn'], $details['filename']);
}

file_put_contents($refgen->docPath('reference/' . strtolower($type) . '.md'), ob_get_clean());
}
28 changes: 28 additions & 0 deletions tools/src/CSFixer/AbstractFixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php declare(strict_types=1);

/**
* @license Apache 2.0
*/

namespace OpenApi\Tools\CSFixer;

use PhpCsFixer\Fixer\FixerInterface;
use PhpCsFixer\Tokenizer\Tokens;

abstract class AbstractFixer implements FixerInterface
{
public function isCandidate(Tokens $tokens): bool
{
return true;
}

public function isRisky(): bool
{
return false;
}

public function supports(\SplFileInfo $file): bool
{
return $file->getExtension() == 'php';
}
}
Loading

0 comments on commit 46c3e4c

Please sign in to comment.