Converted API from Class to Trait

This commit is contained in:
Sys 2021-06-19 22:16:25 +02:00
parent d406940453
commit 032684b93a
No known key found for this signature in database
GPG Key ID: 3CD2C29F8AB39BFD
2 changed files with 7 additions and 10 deletions

View File

@ -47,7 +47,7 @@ if (is_dir($output)) {
echo '> Extracting JSON scheme.' . PHP_EOL; echo '> Extracting JSON scheme.' . PHP_EOL;
$data = $generator->toJson(); $data = $generator->toJson();
} catch (Exception $e) { } catch (Exception $e) {
echo '> ERROR: Unable to extract scheme:' . $e->getMessage() . PHP_EOL; echo '> ERROR: Unable to extract scheme: ' . $e->getMessage() . PHP_EOL;
exit(1); exit(1);
} }
} else { } else {
@ -65,7 +65,7 @@ if (is_dir($output)) {
echo '> Extracting JSON scheme.' . PHP_EOL; echo '> Extracting JSON scheme.' . PHP_EOL;
$data = $generator->toJson(); $data = $generator->toJson();
} catch (Exception $e) { } catch (Exception $e) {
echo '> ERROR: Unable to extract scheme:' . $e->getMessage() . PHP_EOL; echo '> ERROR: Unable to extract scheme: ' . $e->getMessage() . PHP_EOL;
exit(1); exit(1);
} }
echo sprintf('> Outputting PHP stubs to %s.%s', realpath($output), PHP_EOL); echo sprintf('> Outputting PHP stubs to %s.%s', realpath($output), PHP_EOL);

View File

@ -177,23 +177,20 @@ class StubCreator
$file = new PhpFile; $file = new PhpFile;
$file->addComment('@noinspection PhpUnused'); $file->addComment('@noinspection PhpUnused');
$file->addComment('@noinspection PhpUnusedParameterInspection'); $file->addComment('@noinspection PhpUnusedParameterInspection');
$file->addComment('@noinspection PhpIncompatibleReturnTypeInspection');
$file->addComment('@noinspection PhpVoidFunctionResultUsedInspection');
$phpNamespace = $file->addNamespace($this->namespace); $phpNamespace = $file->addNamespace($this->namespace);
$apiClass = $phpNamespace->addClass('API') $apiClass = $phpNamespace->addClass('API')
->setType('class'); ->setTrait();
$apiClass->addMethod('__construct') $apiClass->addMethod('__construct')
->setPublic() ->setPublic()
->addPromotedParameter('client') ->setAbstract();
->setType('\GuzzleHttp\Client')
->setPrivate();
$sendRequest = $apiClass->addMethod('sendRequest') $sendRequest = $apiClass->addMethod('sendRequest')
->setPublic(); ->setPublic()
->setAbstract()
->setReturnType(Type::MIXED);
$sendRequest->addParameter('method') $sendRequest->addParameter('method')
->setType(Type::STRING); ->setType(Type::STRING);
$sendRequest->addParameter('args') $sendRequest->addParameter('args')
->setType(Type::ARRAY); ->setType(Type::ARRAY);
$sendRequest->addBody('//TODO: add your logic here');
foreach ($this->scheme['methods'] as $method) { foreach ($this->scheme['methods'] as $method) {
$function = $apiClass->addMethod($method['name']) $function = $apiClass->addMethod($method['name'])
->setPublic() ->setPublic()