Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
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$
]));
}
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ composer require knplabs/github-api:^3.0 guzzlehttp/guzzle:^7.0.1 http-interop/h

## Advanced install

We are decoupled from any HTTP messaging client with help by [HTTPlug](https://httplug.io).
We are decoupled from any HTTP messaging client with help by [HTTPlug](https://httplug.io).

### Using a different http client

Expand All @@ -53,6 +53,14 @@ $client = Client::createWithHttpClient(new HttplugClient());

Read more about [using different clients in our docs](doc/customize.md).

## Code Completion (JetBrains PhpStorm)
To improve code-completion and ux approach in PhpStorm, advanced metadata is now added.

![Auto-Complete Api Names](https://user-images.githubusercontent.com/1327607/229752632-f1e4a1b3-a9f8-48be-9beb-d41927e96cde.png)

![Auto-Complete Api Methods](https://user-images.githubusercontent.com/1327607/229752677-3a2f3dc8-51d7-45b7-a7d0-0cde7ac145f7.png)


## Framework integrations

### Laravel
Expand Down
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",
"phpstan/phpdoc-parser": "^1.21"
},
"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
}
}
}
28 changes: 28 additions & 0 deletions generate-phpstorm-meta-file.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use PHPStan\PhpDocParser\Lexer\Lexer;
use PHPStan\PhpDocParser\Parser\ConstExprParser;
use PHPStan\PhpDocParser\Parser\PhpDocParser;
use PHPStan\PhpDocParser\Parser\TokenIterator;
use PHPStan\PhpDocParser\Parser\TypeParser;

require 'vendor/autoload.php';

$reflection = new ReflectionClass(\Github\Client::class);

$lexer = new Lexer();
$constExprParser = new ConstExprParser();
$typeParser = new TypeParser($constExprParser);
$phpDocParser = new PhpDocParser($typeParser, $constExprParser);

$tokens = new TokenIterator($lexer->tokenize($reflection->getDocComment()));
$phpDocNode = $phpDocParser->parse($tokens);

$replacements = '';
foreach ($phpDocNode->getTagsByName('@method') as $node) {
$replacements .= "\"{$node->value->methodName}\" => \Github\\{$node->value->returnType->name}::class,".PHP_EOL;
}

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