Code style fixes
All checks were successful
timw4mail/HummingBirdAnimeClient/pipeline/head This commit looks good

This commit is contained in:
Timothy Warren 2021-02-10 13:59:37 -05:00
parent b7a2eafc0d
commit ebd7f811ee
4 changed files with 77 additions and 71 deletions

View File

@ -293,74 +293,6 @@ abstract class APIRequestBuilder {
return $this; return $this;
} }
/**
* Create a GraphQL query and return the Request object
*
* @param string $name
* @param array $variables
* @return Request
*/
public function queryRequest(string $name, array $variables = []): Request
{
$file = realpath("{$this->filePath}/Queries/{$name}.graphql");
if ( ! file_exists($file))
{
throw new LogicException('GraphQL query file does not exist.');
}
$query = file_get_contents($file);
$body = [
'query' => $query
];
if ( ! empty($variables))
{
$body['variables'] = [];
foreach($variables as $key => $val)
{
$body['variables'][$key] = $val;
}
}
return $this->setUpRequest('POST', $this->baseUrl, [
'body' => $body,
]);
}
/**
* Create a GraphQL mutation request, and return the Request object
*
* @param string $name
* @param array $variables
* @return Request
* @throws Throwable
*/
public function mutateRequest (string $name, array $variables = []): Request
{
$file = "{$this->filePath}/Mutations/{$name}.graphql";
if ( ! file_exists($file))
{
throw new LogicException('GraphQL mutation file does not exist.');
}
$query = file_get_contents($file);
$body = [
'query' => $query
];
if (!empty($variables)) {
$body['variables'] = [];
foreach ($variables as $key => $val)
{
$body['variables'][$key] = $val;
}
}
return $this->setUpRequest('POST', $this->baseUrl, [
'body' => $body,
]);
}
/** /**
* Create the full request url * Create the full request url
* *

View File

@ -31,6 +31,7 @@ use const Aviat\AnimeClient\USER_AGENT;
use Aviat\AnimeClient\API\APIRequestBuilder; use Aviat\AnimeClient\API\APIRequestBuilder;
use LogicException; use LogicException;
use Throwable;
final class RequestBuilder extends APIRequestBuilder { final class RequestBuilder extends APIRequestBuilder {
use ContainerAware; use ContainerAware;
@ -117,7 +118,7 @@ final class RequestBuilder extends APIRequestBuilder {
*/ */
public function runQuery(string $name, array $variables = []): array public function runQuery(string $name, array $variables = []): array
{ {
$file = realpath(__DIR__ . "/Queries/{$name}.graphql"); $file = __DIR__ . "/Queries/{$name}.graphql";
if ( ! file_exists($file)) if ( ! file_exists($file))
{ {
throw new LogicException('GraphQL query file does not exist.'); throw new LogicException('GraphQL query file does not exist.');
@ -150,8 +151,8 @@ final class RequestBuilder extends APIRequestBuilder {
*/ */
public function mutateRequest (string $name, array $variables = []): Request public function mutateRequest (string $name, array $variables = []): Request
{ {
$file = realpath(__DIR__ . "/Mutations/{$name}.graphql"); $file = __DIR__ . "/Mutations/{$name}.graphql";
if (!file_exists($file)) if ( ! file_exists($file))
{ {
throw new LogicException('GraphQL mutation file does not exist.'); throw new LogicException('GraphQL mutation file does not exist.');
} }

View File

@ -200,6 +200,74 @@ final class RequestBuilder extends APIRequestBuilder {
return $response; return $response;
} }
/**
* Create a GraphQL query and return the Request object
*
* @param string $name
* @param array $variables
* @return Request
*/
public function queryRequest(string $name, array $variables = []): Request
{
$file = realpath("{$this->filePath}/Queries/{$name}.graphql");
if ( ! file_exists($file))
{
throw new LogicException('GraphQL query file does not exist.');
}
$query = file_get_contents($file);
$body = [
'query' => $query
];
if ( ! empty($variables))
{
$body['variables'] = [];
foreach($variables as $key => $val)
{
$body['variables'][$key] = $val;
}
}
return $this->setUpRequest('POST', $this->baseUrl, [
'body' => $body,
]);
}
/**
* Create a GraphQL mutation request, and return the Request object
*
* @param string $name
* @param array $variables
* @return Request
* @throws Throwable
*/
public function mutateRequest (string $name, array $variables = []): Request
{
$file = "{$this->filePath}/Mutations/{$name}.graphql";
if ( ! file_exists($file))
{
throw new LogicException('GraphQL mutation file does not exist.');
}
$query = file_get_contents($file);
$body = [
'query' => $query
];
if (!empty($variables)) {
$body['variables'] = [];
foreach ($variables as $key => $val)
{
$body['variables'][$key] = $val;
}
}
return $this->setUpRequest('POST', $this->baseUrl, [
'body' => $body,
]);
}
/** /**
* Make a request * Make a request
* *

View File

@ -48,6 +48,11 @@ function loadConfig(string $path): array
$output = []; $output = [];
$files = glob("{$path}/*.toml"); $files = glob("{$path}/*.toml");
if ( ! is_array($files))
{
return [];
}
foreach ($files as $file) foreach ($files as $file)
{ {
$key = str_replace('.toml', '', basename($file)); $key = str_replace('.toml', '', basename($file));