Skip to content

Commit

Permalink
feat: add script to auto-generate .phpstorm.meta.php file
Browse files Browse the repository at this point in the history
Signed-off-by: Hari Darshan Gorana <er.haridarshan@gmail.com>
  • Loading branch information
haridarshan committed May 22, 2023
1 parent 1e45f9d commit 490ad82
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 68 deletions.
66 changes: 0 additions & 66 deletions .phpstorm.meta.php

This file was deleted.

10 changes: 10 additions & 0 deletions .phpstorm.meta.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);

// see https://www.jetbrains.com/help/phpstorm/ide-advanced-metadata.html
namespace PHPSTORM_META {

override(\Github\Client::api(0), map([
$METHODS$
]));
}
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"psr/http-factory-implementation": "^1.0",
"psr/http-message": "^1.0",
"symfony/polyfill-php80": "^1.17",
"symfony/deprecation-contracts": "^2.2|^3.0"
"symfony/deprecation-contracts": "^2.2|^3.0",
"jasny/phpdoc-parser": "^1.0"
},
"require-dev": {
"symfony/cache": "^5.1.8",
Expand Down Expand Up @@ -58,7 +59,8 @@
"config": {
"allow-plugins": {
"phpstan/extension-installer": true,
"composer/package-versions-deprecated": true
"composer/package-versions-deprecated": true,
"php-http/discovery": true
}
}
}
26 changes: 26 additions & 0 deletions generate-phpstorm-meta-file.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

use Jasny\PhpdocParser\PhpdocParser;
use Jasny\PhpdocParser\Set\PhpDocumentor;

require 'vendor/autoload.php';

$reflection = new ReflectionClass(\Github\Client::class);
$parser = new PHPDocParser(PhpDocumentor::tags());
$meta = $parser->parse($reflection->getDocComment());

$replacements = "";
foreach($meta['methods'] as $method) {
$replacements .= "\"{$method['name']}\" => \Github\\{$method['return_type']}::class,".PHP_EOL;
}

$str = file_get_contents('./.phpstorm.meta.stub');
$str = str_replace('$METHODS$', $replacements, $str);
file_put_contents('.phpstorm.meta.1.php', $str);







0 comments on commit 490ad82

Please sign in to comment.