Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Apply php-cs-fixer changes
  • Loading branch information
k0ka authored and github-actions[bot] committed Feb 5, 2024
commit 4c3f4d6f1f7b5e975e020af1324a0b1f3d2b5bfe
34 changes: 17 additions & 17 deletions src/Common/Error/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private function header(string $name): string
*/
private function linkIsValid(string $link): bool
{
$link = $this->docDomain . $link;
$link = $this->docDomain.$link;

try {
return $this->client->request('HEAD', $link)->getStatusCode() < 400;
Expand All @@ -69,16 +69,16 @@ private function linkIsValid(string $link): bool
public function str(MessageInterface $message, int $verbosity = 0): string
{
if ($message instanceof RequestInterface) {
$msg = trim($message->getMethod() . ' ' . $message->getRequestTarget());
$msg .= ' HTTP/' . $message->getProtocolVersion();
$msg = trim($message->getMethod().' '.$message->getRequestTarget());
$msg .= ' HTTP/'.$message->getProtocolVersion();
if (!$message->hasHeader('host')) {
$msg .= "\r\nHost: " . $message->getUri()->getHost();
$msg .= "\r\nHost: ".$message->getUri()->getHost();
}
} else {
if ($message instanceof ResponseInterface) {
$msg = 'HTTP/' . $message->getProtocolVersion() . ' '
. $message->getStatusCode() . ' '
. $message->getReasonPhrase();
$msg = 'HTTP/'.$message->getProtocolVersion().' '
.$message->getStatusCode().' '
.$message->getReasonPhrase();
} else {
throw new \InvalidArgumentException('Unknown message type');
}
Expand All @@ -89,15 +89,15 @@ public function str(MessageInterface $message, int $verbosity = 0): string
}

foreach ($message->getHeaders() as $name => $values) {
$msg .= "\r\n{$name}: " . implode(', ', $values);
$msg .= "\r\n{$name}: ".implode(', ', $values);
}

if ($verbosity < 2) {
return $msg;
}

if (ini_get('memory_limit') < 0 || $message->getBody()->getSize() < ini_get('memory_limit')) {
$msg .= "\r\n\r\n" . $message->getBody();
$msg .= "\r\n\r\n".$message->getBody();
}

return trim($msg);
Expand All @@ -106,7 +106,7 @@ public function str(MessageInterface $message, int $verbosity = 0): string
/**
* Helper method responsible for constructing and returning {@see BadResponseError} exceptions.
*
* @param RequestInterface $request The faulty request
* @param RequestInterface $request The faulty request
* @param ResponseInterface $response The error-filled response
*/
public function httpError(RequestInterface $request, ResponseInterface $response, int $verbosity = 0): BadResponseError
Expand All @@ -120,16 +120,16 @@ public function httpError(RequestInterface $request, ResponseInterface $response
);

$message .= $this->header('Request');
$message .= $this->str($request, $verbosity) . PHP_EOL . PHP_EOL;
$message .= $this->str($request, $verbosity).PHP_EOL.PHP_EOL;

$message .= $this->header('Response');
$message .= $this->str($response, $verbosity) . PHP_EOL . PHP_EOL;
$message .= $this->str($response, $verbosity).PHP_EOL.PHP_EOL;

$message .= $this->header('Further information');
$message .= $this->getStatusCodeMessage($response->getStatusCode());

$message .= 'Visit http://docs.php-opencloud.com/en/latest/http-codes for more information about debugging '
. 'HTTP status codes, or file a support issue on https://github.com/php-opencloud/openstack/issues.';
.'HTTP status codes, or file a support issue on https://github.com/php-opencloud/openstack/issues.';

$e = new BadResponseError($message);
$e->setRequest($request);
Expand All @@ -153,9 +153,9 @@ private function getStatusCodeMessage(int $statusCode): string
/**
* Helper method responsible for constructing and returning {@see UserInputError} exceptions.
*
* @param string $expectedType The type that was expected from the user
* @param mixed $userValue The incorrect value the user actually provided
* @param string|null $furtherLink a link to further information if necessary (optional)
* @param string $expectedType The type that was expected from the user
* @param mixed $userValue The incorrect value the user actually provided
* @param string|null $furtherLink a link to further information if necessary (optional)
*/
public function userInputError(string $expectedType, $userValue, string $furtherLink = null): UserInputError
{
Expand All @@ -170,7 +170,7 @@ public function userInputError(string $expectedType, $userValue, string $further
$message .= 'Please ensure that the value adheres to the expectation above. ';

if ($furtherLink && $this->linkIsValid($furtherLink)) {
$message .= sprintf('Visit %s for more information about input arguments. ', $this->docDomain . $furtherLink);
$message .= sprintf('Visit %s for more information about input arguments. ', $this->docDomain.$furtherLink);
}

$message .= 'If you run into trouble, please open a support issue on https://github.com/php-opencloud/openstack/issues.';
Expand Down
17 changes: 7 additions & 10 deletions src/Common/Service/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware as GuzzleMiddleware;
use OpenStack\Common\Auth\IdentityService;
use OpenStack\Common\Auth\Token;
use OpenStack\Common\Transport\HandlerStackFactory;
use OpenStack\Common\Transport\Middleware;
use OpenStack\Common\Transport\Utils;

/**
Expand All @@ -37,7 +34,7 @@ class Builder
private $defaults = ['urlType' => 'publicURL'];

/**
* @param array $globalOptions options that will be applied to every service created by this builder.
* @param array $globalOptions options that will be applied to every service created by this builder.
* Eventually they will be merged (and if necessary overridden) by the
* service-specific options passed in
* @param string $rootNamespace API classes' root namespace
Expand All @@ -50,8 +47,8 @@ public function __construct(array $globalOptions = [], $rootNamespace = 'OpenSta

private function getClasses($namespace)
{
$namespace = $this->rootNamespace . '\\' . $namespace;
$classes = [$namespace . '\\Api', $namespace . '\\Service'];
$namespace = $this->rootNamespace.'\\'.$namespace;
$classes = [$namespace.'\\Api', $namespace.'\\Service'];

foreach ($classes as $class) {
if (!class_exists($class)) {
Expand All @@ -68,8 +65,8 @@ private function getClasses($namespace)
* directly - this setup includes the configuration of the HTTP client's base URL, and the
* attachment of an authentication handler.
*
* @param string $namespace The namespace of the service
* @param array $serviceOptions The service-specific options to use
* @param string $namespace The namespace of the service
* @param array $serviceOptions The service-specific options to use
*/
public function createService(string $namespace, array $serviceOptions = []): ServiceInterface
{
Expand All @@ -88,12 +85,12 @@ private function stockHttpClient(array &$options, string $serviceName): void
if (!isset($options['httpClient']) || !($options['httpClient'] instanceof ClientInterface)) {
if (false !== stripos($serviceName, 'identity')) {
$baseUrl = $options['authUrl'];
$token = null;
$token = null;
} else {
[$token, $baseUrl] = $options['identityService']->authenticate($options);
}

$stack = HandlerStackFactory::createWithOptions(array_merge($options, ['token' => $token]));
$stack = HandlerStackFactory::createWithOptions(array_merge($options, ['token' => $token]));
$microVersion = $options['microVersion'] ?? null;

$options['httpClient'] = $this->httpClient($baseUrl, $stack, $options['catalogType'], $microVersion);
Expand Down
6 changes: 3 additions & 3 deletions src/Common/Transport/HandlerStackFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static function create(callable $handler = null): HandlerStack
}

/**
* Creates a new HandlerStack with the given options
* Creates a new HandlerStack with the given options.
*
* @param array{
* handler: callable,
Expand All @@ -37,11 +37,11 @@ public static function create(callable $handler = null): HandlerStack
*/
public static function createWithOptions(array $options): HandlerStack
{
$stack = new HandlerStack($options['handler'] ?? Utils::chooseHandler());
$stack = new HandlerStack($options['handler'] ?? Utils::chooseHandler());
$stack->push(Middleware::httpErrors($options['errorVerbosity'] ?? 0), 'http_errors');
$stack->push(GuzzleMiddleware::prepareBody(), 'prepare_body');

if (!empty($options['authHandler'])){
if (!empty($options['authHandler'])) {
$stack->push(Middleware::authHandler($options['authHandler'], $options['token'] ?? null));
}

Expand Down
3 changes: 1 addition & 2 deletions src/OpenStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace OpenStack;

use GuzzleHttp\Client;
use GuzzleHttp\Middleware as GuzzleMiddleware;
use OpenStack\Common\Service\Builder;
use OpenStack\Common\Transport\HandlerStackFactory;
use OpenStack\Common\Transport\Utils;
Expand Down Expand Up @@ -37,7 +36,7 @@ class OpenStack
public function __construct(array $options = [], Builder $builder = null)
{
$defaults = ['errorVerbosity' => 2];
$options = array_merge($defaults, $options);
$options = array_merge($defaults, $options);

if (!isset($options['identityService'])) {
$options['identityService'] = $this->getDefaultIdentityService($options);
Expand Down