Test
This commit is contained in:
commit
53f65de9d4
88 changed files with 3596 additions and 694 deletions
30
server/vendor/php-opencloud/common/.travis.yml
vendored
Normal file
30
server/vendor/php-opencloud/common/.travis.yml
vendored
Normal file
|
@ -0,0 +1,30 @@
|
|||
language: php
|
||||
|
||||
sudo: false
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.composer/cache
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- php: 7.0
|
||||
- php: nightly
|
||||
allow_failures:
|
||||
- php: nightly
|
||||
fast_finish: true
|
||||
|
||||
before_install:
|
||||
- composer self-update
|
||||
|
||||
before_script:
|
||||
- composer install --prefer-source
|
||||
- vendor/bin/parallel-lint --exclude vendor .
|
||||
- vendor/bin/php-cs-fixer fix --dry-run --diff --level psr2 .
|
||||
|
||||
after_script:
|
||||
- php vendor/bin/coveralls -v
|
||||
|
||||
notifications:
|
||||
email:
|
||||
- jamie.hannaford@rackspace.com
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace OpenCloud\Common\Api;
|
||||
|
||||
|
@ -6,27 +6,27 @@ abstract class AbstractApi implements ApiInterface
|
|||
{
|
||||
protected $params;
|
||||
|
||||
protected function isRequired(array $param)
|
||||
protected function isRequired(array $param): array
|
||||
{
|
||||
return array_merge($param, ['required' => true]);
|
||||
}
|
||||
|
||||
protected function notRequired(array $param)
|
||||
protected function notRequired(array $param): array
|
||||
{
|
||||
return array_merge($param, ['required' => false]);
|
||||
}
|
||||
|
||||
protected function query(array $param)
|
||||
protected function query(array $param): array
|
||||
{
|
||||
return array_merge($param, ['location' => AbstractParams::QUERY]);
|
||||
}
|
||||
|
||||
protected function url(array $param)
|
||||
protected function url(array $param): array
|
||||
{
|
||||
return array_merge($param, ['location' => AbstractParams::URL]);
|
||||
}
|
||||
|
||||
public function documented(array $param)
|
||||
public function documented(array $param): array
|
||||
{
|
||||
return array_merge($param, ['required' => true]);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace OpenCloud\Common\Api;
|
||||
|
||||
|
@ -21,12 +21,12 @@ abstract class AbstractParams
|
|||
const INT_TYPE = 'integer';
|
||||
const INTEGER_TYPE = self::INT_TYPE;
|
||||
|
||||
public static function isSupportedLocation($val)
|
||||
public static function isSupportedLocation(string $val): bool
|
||||
{
|
||||
return in_array($val, [self::QUERY, self::HEADER, self::URL, self::JSON, self::RAW]);
|
||||
}
|
||||
|
||||
public function limit()
|
||||
public function limit(): array
|
||||
{
|
||||
return [
|
||||
'type' => self::INT_TYPE,
|
||||
|
@ -38,7 +38,7 @@ DESC
|
|||
];
|
||||
}
|
||||
|
||||
public function marker()
|
||||
public function marker(): array
|
||||
{
|
||||
return [
|
||||
'type' => 'string',
|
||||
|
@ -51,7 +51,7 @@ DESC
|
|||
];
|
||||
}
|
||||
|
||||
public function id($type)
|
||||
public function id(string $type): array
|
||||
{
|
||||
return [
|
||||
'description' => sprintf("The unique ID, or identifier, for the %s", $type),
|
||||
|
@ -60,7 +60,7 @@ DESC
|
|||
];
|
||||
}
|
||||
|
||||
public function idPath()
|
||||
public function idPath(): array
|
||||
{
|
||||
return [
|
||||
'type' => self::STRING_TYPE,
|
||||
|
@ -69,7 +69,7 @@ DESC
|
|||
];
|
||||
}
|
||||
|
||||
public function name($resource)
|
||||
public function name(string $resource): array
|
||||
{
|
||||
return [
|
||||
'description' => sprintf("The name of the %s", $resource),
|
||||
|
@ -79,7 +79,7 @@ DESC
|
|||
}
|
||||
|
||||
|
||||
public function sortDir()
|
||||
public function sortDir(): array
|
||||
{
|
||||
return [
|
||||
'type' => self::STRING_TYPE,
|
||||
|
@ -89,7 +89,7 @@ DESC
|
|||
];
|
||||
}
|
||||
|
||||
public function sortKey()
|
||||
public function sortKey(): array
|
||||
{
|
||||
return [
|
||||
'type' => self::STRING_TYPE,
|
||||
|
@ -97,4 +97,4 @@ DESC
|
|||
'description' => "Sorts by one or more sets of attribute and sort direction combinations.",
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace OpenCloud\Common\Api;
|
||||
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace OpenCloud\Common\Api;
|
||||
|
||||
use GuzzleHttp\Utils;
|
||||
|
||||
/**
|
||||
* This class represents an OpenCloud API operation. It encapsulates most aspects of the REST operation: its HTTP
|
||||
* method, the URL path, its top-level JSON key, and all of its {@see Parameter} objects.
|
||||
|
@ -49,7 +47,7 @@ class Operation
|
|||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPath()
|
||||
public function getPath(): string
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
|
@ -57,7 +55,7 @@ class Operation
|
|||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMethod()
|
||||
public function getMethod(): string
|
||||
{
|
||||
return $this->method;
|
||||
}
|
||||
|
@ -69,7 +67,7 @@ class Operation
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasParam($key)
|
||||
public function hasParam(string $key): bool
|
||||
{
|
||||
return isset($this->params[$key]);
|
||||
}
|
||||
|
@ -79,7 +77,7 @@ class Operation
|
|||
*
|
||||
* @return Parameter
|
||||
*/
|
||||
public function getParam($name)
|
||||
public function getParam(string $name)
|
||||
{
|
||||
return isset($this->params[$name]) ? $this->params[$name] : null;
|
||||
}
|
||||
|
@ -87,9 +85,9 @@ class Operation
|
|||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getJsonKey()
|
||||
public function getJsonKey(): string
|
||||
{
|
||||
return $this->jsonKey;
|
||||
return $this->jsonKey ?: '';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -100,7 +98,7 @@ class Operation
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function toParamArray(array $data)
|
||||
public static function toParamArray(array $data): array
|
||||
{
|
||||
$params = [];
|
||||
|
||||
|
@ -121,7 +119,7 @@ class Operation
|
|||
* @return bool TRUE if validation passes
|
||||
* @throws \Exception If validate fails
|
||||
*/
|
||||
public function validate(array $userValues)
|
||||
public function validate(array $userValues): bool
|
||||
{
|
||||
foreach ($this->params as $paramName => $param) {
|
||||
if (array_key_exists($paramName, $userValues)) {
|
||||
|
@ -133,4 +131,4 @@ class Operation
|
|||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace OpenCloud\Common\Api;
|
||||
|
||||
use GuzzleHttp\Promise\PromiseInterface;
|
||||
use GuzzleHttp\Psr7\Uri;
|
||||
use function GuzzleHttp\uri_template;
|
||||
use GuzzleHttp\ClientInterface;
|
||||
use GuzzleHttp\Promise\Promise;
|
||||
|
@ -60,12 +62,12 @@ abstract class Operator implements OperatorInterface
|
|||
*
|
||||
* @return Operation
|
||||
*/
|
||||
public function getOperation(array $definition)
|
||||
public function getOperation(array $definition): Operation
|
||||
{
|
||||
return new Operation($definition);
|
||||
}
|
||||
|
||||
protected function sendRequest(Operation $operation, array $userValues = [], $async = false)
|
||||
protected function sendRequest(Operation $operation, array $userValues = [], bool $async = false)
|
||||
{
|
||||
$operation->validate($userValues);
|
||||
|
||||
|
@ -79,7 +81,7 @@ abstract class Operator implements OperatorInterface
|
|||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function execute(array $definition, array $userValues = [])
|
||||
public function execute(array $definition, array $userValues = []): ResponseInterface
|
||||
{
|
||||
return $this->sendRequest($this->getOperation($definition), $userValues);
|
||||
}
|
||||
|
@ -87,7 +89,7 @@ abstract class Operator implements OperatorInterface
|
|||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function executeAsync(array $definition, array $userValues = [])
|
||||
public function executeAsync(array $definition, array $userValues = []): PromiseInterface
|
||||
{
|
||||
return $this->sendRequest($this->getOperation($definition), $userValues, true);
|
||||
}
|
||||
|
@ -95,7 +97,7 @@ abstract class Operator implements OperatorInterface
|
|||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function model($class, $data = null)
|
||||
public function model(string $class, $data = null): ResourceInterface
|
||||
{
|
||||
$model = new $class($this->client, $this->api);
|
||||
|
||||
|
@ -121,13 +123,13 @@ abstract class Operator implements OperatorInterface
|
|||
*
|
||||
* @return static
|
||||
*/
|
||||
public function newInstance()
|
||||
public function newInstance(): self
|
||||
{
|
||||
return new static($this->client, $this->api);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \GuzzleHttp\Psr7\Uri
|
||||
* @return \GuzzleHttp\Psr7\Uri:null
|
||||
*/
|
||||
protected function getHttpBaseUrl()
|
||||
{
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace OpenCloud\Common\Api;
|
||||
|
||||
use GuzzleHttp\ClientInterface;
|
||||
use GuzzleHttp\Promise\PromiseInterface;
|
||||
use OpenCloud\Common\Resource\ResourceInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* An operator is any resource or service that can invoke and send REST operations. In other words, it
|
||||
|
@ -28,7 +31,7 @@ interface OperatorInterface
|
|||
*
|
||||
* @return \Psr\Http\Message\ResponseInterface
|
||||
*/
|
||||
public function execute(array $definition, array $userValues = []);
|
||||
public function execute(array $definition, array $userValues = []): ResponseInterface;
|
||||
|
||||
/**
|
||||
* A convenience method that assembles an operation and asynchronously sends it to the remote API
|
||||
|
@ -38,7 +41,7 @@ interface OperatorInterface
|
|||
*
|
||||
* @return \GuzzleHttp\Promise\PromiseInterface
|
||||
*/
|
||||
public function executeAsync(array $definition, array $userValues = []);
|
||||
public function executeAsync(array $definition, array $userValues = []): PromiseInterface;
|
||||
|
||||
/**
|
||||
* @param string $name The name of the model class.
|
||||
|
@ -47,5 +50,5 @@ interface OperatorInterface
|
|||
*
|
||||
* @return \OpenCloud\Common\Resource\ResourceInterface
|
||||
*/
|
||||
public function model($name, $data = null);
|
||||
public function model(string $name, $data = null): ResourceInterface;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace OpenCloud\Common\Api;
|
||||
|
||||
|
@ -42,7 +42,7 @@ class Parameter
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
private $name = '';
|
||||
|
||||
/**
|
||||
* The alias for this parameter. Although the user will always interact with the human-friendly $name property,
|
||||
|
@ -50,7 +50,7 @@ class Parameter
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
private $sentAs;
|
||||
private $sentAs = '';
|
||||
|
||||
/**
|
||||
* For array parameters (for example, an array of security group names when creating a server), each array element
|
||||
|
@ -79,7 +79,7 @@ class Parameter
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
private $type;
|
||||
private $type = '';
|
||||
|
||||
/**
|
||||
* Indicates whether this parameter requires a value from the user.
|
||||
|
@ -94,7 +94,7 @@ class Parameter
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
private $location;
|
||||
private $location = '';
|
||||
|
||||
/**
|
||||
* Relevant to "json" location parameters only. This property allows for deep nesting through the use of
|
||||
|
@ -102,14 +102,14 @@ class Parameter
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
private $path;
|
||||
private $path = '';
|
||||
|
||||
/**
|
||||
* Allows for the prefixing of parameter names.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $prefix;
|
||||
private $prefix = '';
|
||||
|
||||
/**
|
||||
* The enum values for which this param is restricted.
|
||||
|
@ -151,7 +151,7 @@ class Parameter
|
|||
private function stockProperties(array $data)
|
||||
{
|
||||
if (isset($data['properties'])) {
|
||||
if (stripos($this->name, 'metadata') !== false) {
|
||||
if ($this->name && stripos($this->name, 'metadata') !== false) {
|
||||
$this->properties = new Parameter($data['properties']);
|
||||
} else {
|
||||
foreach ($data['properties'] as $name => $property) {
|
||||
|
@ -166,7 +166,7 @@ class Parameter
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->sentAs ?: $this->name;
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ class Parameter
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isRequired()
|
||||
public function isRequired(): bool
|
||||
{
|
||||
return $this->required === true;
|
||||
}
|
||||
|
@ -189,7 +189,7 @@ class Parameter
|
|||
* @return bool TRUE if the validation passes
|
||||
* @throws \Exception If validation fails
|
||||
*/
|
||||
public function validate($userValues)
|
||||
public function validate($userValues): bool
|
||||
{
|
||||
$this->validateEnums($userValues);
|
||||
$this->validateType($userValues);
|
||||
|
@ -245,9 +245,9 @@ class Parameter
|
|||
* @returns Parameter
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function getNestedProperty($key)
|
||||
private function getNestedProperty($key): Parameter
|
||||
{
|
||||
if (stripos($this->name, 'metadata') !== false && $this->properties instanceof Parameter) {
|
||||
if ($this->name && stripos($this->name, 'metadata') !== false && $this->properties instanceof Parameter) {
|
||||
return $this->properties;
|
||||
} elseif (isset($this->properties[$key])) {
|
||||
return $this->properties[$key];
|
||||
|
@ -264,7 +264,7 @@ class Parameter
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function hasCorrectType($userValue)
|
||||
private function hasCorrectType($userValue): bool
|
||||
{
|
||||
// Helper fn to see whether an array is associative (i.e. a JSON object)
|
||||
$isAssociative = function ($value) {
|
||||
|
@ -293,7 +293,7 @@ class Parameter
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isArray()
|
||||
public function isArray(): bool
|
||||
{
|
||||
return $this->type == 'array' && $this->itemSchema instanceof Parameter;
|
||||
}
|
||||
|
@ -303,12 +303,12 @@ class Parameter
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isObject()
|
||||
public function isObject(): bool
|
||||
{
|
||||
return $this->type == 'object' && !empty($this->properties);
|
||||
}
|
||||
|
||||
public function getLocation()
|
||||
public function getLocation(): string
|
||||
{
|
||||
return $this->location;
|
||||
}
|
||||
|
@ -320,7 +320,7 @@ class Parameter
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasLocation($value)
|
||||
public function hasLocation($value): bool
|
||||
{
|
||||
return $this->location == $value;
|
||||
}
|
||||
|
@ -330,7 +330,7 @@ class Parameter
|
|||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getPath()
|
||||
public function getPath(): string
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
|
@ -338,7 +338,7 @@ class Parameter
|
|||
/**
|
||||
* Retrieves the common schema that an array parameter applies to all its child elements.
|
||||
*
|
||||
* @return Parameter
|
||||
* @return Parameter|null
|
||||
*/
|
||||
public function getItemSchema()
|
||||
{
|
||||
|
@ -350,7 +350,7 @@ class Parameter
|
|||
*
|
||||
* @param string $name
|
||||
*/
|
||||
public function setName($name)
|
||||
public function setName(string $name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
@ -362,7 +362,7 @@ class Parameter
|
|||
*
|
||||
* @return null|Parameter
|
||||
*/
|
||||
public function getProperty($name)
|
||||
public function getProperty(string $name)
|
||||
{
|
||||
if ($this->properties instanceof Parameter) {
|
||||
$this->properties->setName($name);
|
||||
|
@ -377,12 +377,12 @@ class Parameter
|
|||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getPrefix()
|
||||
public function getPrefix(): string
|
||||
{
|
||||
return $this->prefix;
|
||||
}
|
||||
|
||||
public function getPrefixedName()
|
||||
public function getPrefixedName(): string
|
||||
{
|
||||
return $this->prefix . $this->getName();
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace OpenCloud\Common;
|
||||
|
||||
|
@ -38,7 +38,7 @@ trait ArrayAccessTrait
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function offsetExists($offset)
|
||||
public function offsetExists(string $offset): bool
|
||||
{
|
||||
return isset($this->internalState[$offset]);
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ trait ArrayAccessTrait
|
|||
*
|
||||
* @param string $offset
|
||||
*/
|
||||
public function offsetUnset($offset)
|
||||
public function offsetUnset(string $offset)
|
||||
{
|
||||
unset($this->internalState[$offset]);
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ trait ArrayAccessTrait
|
|||
*
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function offsetGet($offset)
|
||||
public function offsetGet(string $offset)
|
||||
{
|
||||
return $this->offsetExists($offset) ? $this->internalState[$offset] : null;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace OpenCloud\Common\Auth;
|
||||
|
||||
|
@ -14,10 +14,13 @@ use Psr\Http\Message\RequestInterface;
|
|||
*/
|
||||
class AuthHandler
|
||||
{
|
||||
/** @var callable */
|
||||
private $nextHandler;
|
||||
|
||||
/** @var callable */
|
||||
private $tokenGenerator;
|
||||
|
||||
/** @var Token */
|
||||
private $token;
|
||||
|
||||
/**
|
||||
|
@ -66,7 +69,7 @@ class AuthHandler
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function shouldIgnore(RequestInterface $request)
|
||||
private function shouldIgnore(RequestInterface $request): bool
|
||||
{
|
||||
return strpos((string) $request->getUri(), 'tokens') !== false && $request->getMethod() == 'POST';
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace OpenCloud\Common\Auth;
|
||||
|
||||
|
@ -16,5 +16,5 @@ interface Catalog
|
|||
*
|
||||
* @returns string
|
||||
*/
|
||||
public function getServiceUrl($name, $type, $region, $urlType);
|
||||
public function getServiceUrl(string $name, string $type, string $region, string $urlType): string;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace OpenCloud\Common\Auth;
|
||||
|
||||
|
@ -9,5 +9,5 @@ interface IdentityService
|
|||
*
|
||||
* @return array The FIRST key is {@see Token} instance, the SECOND key is a {@see Catalog} instance
|
||||
*/
|
||||
public function authenticate(array $options);
|
||||
public function authenticate(array $options): array;
|
||||
}
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace OpenCloud\Common\Auth;
|
||||
|
||||
interface Token
|
||||
{
|
||||
public function getId();
|
||||
public function getId(): string;
|
||||
|
||||
/**
|
||||
* Indicates whether the token has expired or not.
|
||||
*
|
||||
* @return bool TRUE if the token has expired, FALSE if it is still valid
|
||||
*/
|
||||
public function hasExpired();
|
||||
public function hasExpired(): bool;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace OpenCloud\Common\Error;
|
||||
|
||||
|
@ -28,12 +28,12 @@ class BadResponseError extends BaseError
|
|||
$this->response = $response;
|
||||
}
|
||||
|
||||
public function getRequest()
|
||||
public function getRequest(): RequestInterface
|
||||
{
|
||||
return $this->request;
|
||||
}
|
||||
|
||||
public function getResponse()
|
||||
public function getResponse(): ResponseInterface
|
||||
{
|
||||
return $this->response;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace OpenCloud\Common\Error;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace OpenCloud\Common\Error;
|
||||
|
||||
|
@ -48,7 +48,7 @@ class Builder
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
private function header($name)
|
||||
private function header(string $name): string
|
||||
{
|
||||
return sprintf("%s\n%s\n", $name, str_repeat('~', strlen($name)));
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ class Builder
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function linkIsValid($link)
|
||||
private function linkIsValid(string $link): bool
|
||||
{
|
||||
$link = $this->docDomain . $link;
|
||||
|
||||
|
@ -78,7 +78,7 @@ class Builder
|
|||
* @codeCoverageIgnore
|
||||
* @return string
|
||||
*/
|
||||
public function str(MessageInterface $message)
|
||||
public function str(MessageInterface $message): string
|
||||
{
|
||||
if ($message instanceof RequestInterface) {
|
||||
$msg = trim($message->getMethod() . ' '
|
||||
|
@ -112,7 +112,7 @@ class Builder
|
|||
*
|
||||
* @return BadResponseError
|
||||
*/
|
||||
public function httpError(RequestInterface $request, ResponseInterface $response)
|
||||
public function httpError(RequestInterface $request, ResponseInterface $response): BadResponseError
|
||||
{
|
||||
$message = $this->header('HTTP Error');
|
||||
|
||||
|
@ -138,7 +138,7 @@ class Builder
|
|||
return $e;
|
||||
}
|
||||
|
||||
private function getStatusCodeMessage($statusCode)
|
||||
private function getStatusCodeMessage(int $statusCode): string
|
||||
{
|
||||
$errors = [
|
||||
400 => 'Please ensure that your input values are valid and well-formed. ',
|
||||
|
@ -159,7 +159,7 @@ class Builder
|
|||
*
|
||||
* @return UserInputError
|
||||
*/
|
||||
public function userInputError($expectedType, $userValue, $furtherLink = null)
|
||||
public function userInputError(string $expectedType, $userValue, string $furtherLink = null): UserInputError
|
||||
{
|
||||
$message = $this->header('User Input Error');
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace OpenCloud\Common\Error;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace OpenCloud\Common\Error;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace OpenCloud\Common;
|
||||
|
||||
|
@ -25,7 +25,7 @@ trait HydratorStrategyTrait
|
|||
}
|
||||
}
|
||||
|
||||
private function set($key, $property, array $data, callable $fn = null)
|
||||
private function set(string $key, $property, array $data, callable $fn = null)
|
||||
{
|
||||
if (isset($data[$key]) && property_exists($this, $property)) {
|
||||
$value = $fn ? call_user_func($fn, $data[$key]) : $data[$key];
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace OpenCloud\Common;
|
||||
|
||||
|
@ -42,7 +42,7 @@ class JsonPath
|
|||
* @param $path The XPath to use
|
||||
* @param $value The new value of the node
|
||||
*/
|
||||
public function set($path, $value)
|
||||
public function set(string $path, $value)
|
||||
{
|
||||
$this->jsonStructure = $this->setPath($path, $value, $this->jsonStructure);
|
||||
}
|
||||
|
@ -53,9 +53,10 @@ class JsonPath
|
|||
* @param $path
|
||||
* @param $value
|
||||
* @param $json
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function setPath($path, $value, $json)
|
||||
private function setPath(string $path, $value, array $json): array
|
||||
{
|
||||
$nodes = explode('.', $path);
|
||||
$point = array_shift($nodes);
|
||||
|
@ -87,9 +88,10 @@ class JsonPath
|
|||
* Get a path's value. If no path can be matched, NULL is returned.
|
||||
*
|
||||
* @param $path
|
||||
*
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function get($path)
|
||||
public function get(string $path)
|
||||
{
|
||||
return $this->getPath($path, $this->jsonStructure);
|
||||
}
|
||||
|
@ -99,9 +101,10 @@ class JsonPath
|
|||
*
|
||||
* @param $path
|
||||
* @param $json
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
private function getPath($path, $json)
|
||||
private function getPath(string $path, $json)
|
||||
{
|
||||
$nodes = explode('.', $path);
|
||||
$point = array_shift($nodes);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace OpenCloud\Common\JsonSchema;
|
||||
|
||||
|
@ -13,7 +13,7 @@ class JsonPatch
|
|||
return (new static)->makeDiff($src, $dest);
|
||||
}
|
||||
|
||||
public function makeDiff($srcStruct, $desStruct, $path = '')
|
||||
public function makeDiff($srcStruct, $desStruct, string $path = ''): array
|
||||
{
|
||||
$changes = [];
|
||||
|
||||
|
@ -28,7 +28,7 @@ class JsonPatch
|
|||
return $changes;
|
||||
}
|
||||
|
||||
protected function handleArray($srcStruct, $desStruct, $path)
|
||||
protected function handleArray(array $srcStruct, array $desStruct, string $path): array
|
||||
{
|
||||
$changes = [];
|
||||
|
||||
|
@ -53,7 +53,7 @@ class JsonPatch
|
|||
return $changes;
|
||||
}
|
||||
|
||||
protected function handleObject($srcStruct, $desStruct, $path)
|
||||
protected function handleObject(\stdClass $srcStruct, \stdClass $desStruct, string $path): array
|
||||
{
|
||||
$changes = [];
|
||||
|
||||
|
@ -76,12 +76,12 @@ class JsonPatch
|
|||
return $changes;
|
||||
}
|
||||
|
||||
protected function shouldPartiallyReplace($o1, $o2)
|
||||
protected function shouldPartiallyReplace(\stdClass $o1, \stdClass $o2): bool
|
||||
{
|
||||
return count(array_diff_key((array) $o1, (array) $o2)) < count($o1);
|
||||
}
|
||||
|
||||
protected function arrayDiff(array $a1, array $a2)
|
||||
protected function arrayDiff(array $a1, array $a2): array
|
||||
{
|
||||
$result = [];
|
||||
|
||||
|
@ -94,8 +94,10 @@ class JsonPatch
|
|||
return $result;
|
||||
}
|
||||
|
||||
protected function path($root, $path)
|
||||
protected function path(string $root, $path): string
|
||||
{
|
||||
$path = (string) $path;
|
||||
|
||||
if ($path === '_empty_') {
|
||||
$path = '';
|
||||
}
|
||||
|
@ -103,7 +105,7 @@ class JsonPatch
|
|||
return rtrim($root, '/') . '/' . ltrim($path, '/');
|
||||
}
|
||||
|
||||
protected function makePatch($op, $path, $val = null)
|
||||
protected function makePatch(string $op, string $path, $val = null): array
|
||||
{
|
||||
switch ($op) {
|
||||
default:
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace OpenCloud\Common\JsonSchema;
|
||||
|
||||
|
@ -6,7 +6,10 @@ use JsonSchema\Validator;
|
|||
|
||||
class Schema
|
||||
{
|
||||
/** @var object */
|
||||
private $body;
|
||||
|
||||
/** @var Validator */
|
||||
private $validator;
|
||||
|
||||
public function __construct($body, Validator $validator = null)
|
||||
|
@ -15,7 +18,7 @@ class Schema
|
|||
$this->validator = $validator ?: new Validator();
|
||||
}
|
||||
|
||||
public function getPropertyPaths()
|
||||
public function getPropertyPaths(): array
|
||||
{
|
||||
$paths = [];
|
||||
|
||||
|
@ -26,7 +29,7 @@ class Schema
|
|||
return $paths;
|
||||
}
|
||||
|
||||
public function normalizeObject($subject, array $aliases)
|
||||
public function normalizeObject($subject, array $aliases): \stdClass
|
||||
{
|
||||
$out = new \stdClass;
|
||||
|
||||
|
@ -49,17 +52,17 @@ class Schema
|
|||
$this->validator->check($data, $this->body);
|
||||
}
|
||||
|
||||
public function isValid()
|
||||
public function isValid(): bool
|
||||
{
|
||||
return $this->validator->isValid();
|
||||
}
|
||||
|
||||
public function getErrors()
|
||||
public function getErrors(): array
|
||||
{
|
||||
return $this->validator->getErrors();
|
||||
}
|
||||
|
||||
public function getErrorString()
|
||||
public function getErrorString(): string
|
||||
{
|
||||
$msg = "Provided values do not validate. Errors:\n";
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace OpenCloud\Common\Resource;
|
||||
|
||||
|
@ -60,7 +60,7 @@ abstract class AbstractResource extends Operator implements ResourceInterface
|
|||
*
|
||||
* @return $this|ResourceInterface
|
||||
*/
|
||||
public function populateFromResponse(ResponseInterface $response)
|
||||
public function populateFromResponse(ResponseInterface $response): self
|
||||
{
|
||||
if (strpos($response->getHeaderLine('Content-Type'), 'application/json') === 0) {
|
||||
$json = Utils::jsonDecode($response);
|
||||
|
@ -79,12 +79,12 @@ abstract class AbstractResource extends Operator implements ResourceInterface
|
|||
*
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function populateFromArray(array $array)
|
||||
public function populateFromArray(array $array): self
|
||||
{
|
||||
$reflClass = new \ReflectionClass($this);
|
||||
|
||||
foreach ($array as $key => $val) {
|
||||
$propertyName = isset($this->aliases[$key]) ? $this->aliases[$key] : $key;
|
||||
$propertyName = (string) (isset($this->aliases[$key]) ? $this->aliases[$key] : $key);
|
||||
|
||||
if (property_exists($this, $propertyName)) {
|
||||
if ($type = $this->extractTypeFromDocBlock($reflClass, $propertyName)) {
|
||||
|
@ -94,9 +94,11 @@ abstract class AbstractResource extends Operator implements ResourceInterface
|
|||
$this->$propertyName = $val;
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function parseDocBlockValue($type, $val)
|
||||
private function parseDocBlockValue(string $type, $val)
|
||||
{
|
||||
if (strpos($type, '[]') === 0 && is_array($val)) {
|
||||
$array = [];
|
||||
|
@ -113,7 +115,7 @@ abstract class AbstractResource extends Operator implements ResourceInterface
|
|||
return $val;
|
||||
}
|
||||
|
||||
private function isNotNativeType($type)
|
||||
private function isNotNativeType(string $type): bool
|
||||
{
|
||||
return !in_array($type, [
|
||||
'string', 'bool', 'boolean', 'double', 'null', 'array', 'object', 'int', 'integer', 'float', 'numeric',
|
||||
|
@ -121,7 +123,7 @@ abstract class AbstractResource extends Operator implements ResourceInterface
|
|||
]);
|
||||
}
|
||||
|
||||
private function normalizeModelClass($class)
|
||||
private function normalizeModelClass(string $class): string
|
||||
{
|
||||
if (strpos($class, '\\') === false) {
|
||||
$currentNamespace = (new \ReflectionClass($this))->getNamespaceName();
|
||||
|
@ -131,7 +133,7 @@ abstract class AbstractResource extends Operator implements ResourceInterface
|
|||
return $class;
|
||||
}
|
||||
|
||||
private function extractTypeFromDocBlock(\ReflectionClass $reflClass, $propertyName)
|
||||
private function extractTypeFromDocBlock(\ReflectionClass $reflClass, string $propertyName)
|
||||
{
|
||||
$docComment = $reflClass->getProperty($propertyName)->getDocComment();
|
||||
|
||||
|
@ -174,7 +176,7 @@ abstract class AbstractResource extends Operator implements ResourceInterface
|
|||
return $this->execute($definition, $this->getAttrs(array_keys($definition['params'])));
|
||||
}
|
||||
|
||||
private function getResourcesKey()
|
||||
private function getResourcesKey(): string
|
||||
{
|
||||
$resourcesKey = $this->resourcesKey;
|
||||
|
||||
|
@ -189,7 +191,7 @@ abstract class AbstractResource extends Operator implements ResourceInterface
|
|||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function enumerate(array $def, array $userVals = [], callable $mapFn = null)
|
||||
public function enumerate(array $def, array $userVals = [], callable $mapFn = null): \Generator
|
||||
{
|
||||
$operation = $this->getOperation($def);
|
||||
|
||||
|
@ -217,7 +219,7 @@ abstract class AbstractResource extends Operator implements ResourceInterface
|
|||
return $iterator();
|
||||
}
|
||||
|
||||
public function extractMultipleInstances(ResponseInterface $response, $key = null)
|
||||
public function extractMultipleInstances(ResponseInterface $response, string $key = null): array
|
||||
{
|
||||
$key = $key ?: $this->getResourcesKey();
|
||||
$resourcesData = Utils::jsonDecode($response)[$key];
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace OpenCloud\Common\Resource;
|
||||
|
||||
|
@ -15,5 +15,5 @@ interface Creatable
|
|||
* @param array $userOptions
|
||||
* @return self
|
||||
*/
|
||||
public function create(array $userOptions);
|
||||
public function create(array $userOptions): Creatable;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace OpenCloud\Common\Resource;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace OpenCloud\Common\Resource;
|
||||
|
||||
|
@ -12,7 +12,7 @@ interface HasMetadata
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMetadata();
|
||||
public function getMetadata(): array;
|
||||
|
||||
/**
|
||||
* Merges a set of new values with those which already exist (on the remote API) for a resource. For example, if
|
||||
|
@ -32,7 +32,7 @@ interface HasMetadata
|
|||
*
|
||||
* @param array $metadata The new metadata items
|
||||
*
|
||||
* @return mixed
|
||||
* @return void
|
||||
*/
|
||||
public function mergeMetadata(array $metadata);
|
||||
|
||||
|
@ -52,7 +52,7 @@ interface HasMetadata
|
|||
*
|
||||
* @param array $metadata The new metadata items
|
||||
*
|
||||
* @return mixed
|
||||
* @return void
|
||||
*/
|
||||
public function resetMetadata(array $metadata);
|
||||
|
||||
|
@ -63,5 +63,5 @@ interface HasMetadata
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public function parseMetadata(ResponseInterface $response);
|
||||
public function parseMetadata(ResponseInterface $response): array;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace OpenCloud\Common\Resource;
|
||||
|
||||
|
@ -24,7 +24,7 @@ trait HasWaiterTrait
|
|||
* or exceed this timeout, the blocking operation will immediately cease.
|
||||
* @param int $sleepPeriod The amount of time to pause between each HTTP request.
|
||||
*/
|
||||
public function waitUntil($status, $timeout = 60, $sleepPeriod = 1)
|
||||
public function waitUntil(string $status, $timeout = 60, int $sleepPeriod = 1)
|
||||
{
|
||||
$startTime = time();
|
||||
|
||||
|
@ -53,7 +53,7 @@ trait HasWaiterTrait
|
|||
* is provided, the timeout will never be considered.
|
||||
* @param int $sleepPeriod The amount of time to pause between each HTTP request.
|
||||
*/
|
||||
public function waitWithCallback(callable $fn, $timeout = 60, $sleepPeriod = 1)
|
||||
public function waitWithCallback(callable $fn, $timeout = 60, int $sleepPeriod = 1)
|
||||
{
|
||||
$startTime = time();
|
||||
|
||||
|
@ -78,7 +78,7 @@ trait HasWaiterTrait
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function shouldHalt($timeout, $startTime)
|
||||
private function shouldHalt($timeout, int $startTime)
|
||||
{
|
||||
if ($timeout === false) {
|
||||
return false;
|
||||
|
@ -100,7 +100,7 @@ trait HasWaiterTrait
|
|||
$this->waitUntil('ACTIVE', $timeout);
|
||||
}
|
||||
|
||||
public function waitUntilDeleted($timeout = 60, $sleepPeriod = 1)
|
||||
public function waitUntilDeleted($timeout = 60, int $sleepPeriod = 1)
|
||||
{
|
||||
$startTime = time();
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace OpenCloud\Common\Resource;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace OpenCloud\Common\Resource;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace OpenCloud\Common\Resource;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace OpenCloud\Common\Resource;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace OpenCloud\Common\Resource;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace OpenCloud\Common\Service;
|
||||
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
<?php
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace OpenCloud\Common\Service;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\ClientInterface;
|
||||
use GuzzleHttp\Middleware as GuzzleMiddleware;
|
||||
use OpenCloud\Common\Auth\IdentityService;
|
||||
use OpenCloud\Common\Auth\Token;
|
||||
use OpenCloud\Common\Transport\HandlerStack;
|
||||
use OpenCloud\Common\Transport\Middleware;
|
||||
use OpenCloud\Common\Transport\Utils;
|
||||
use OpenCloud\Identity\v3\Service;
|
||||
|
||||
/**
|
||||
* A Builder for easily creating OpenCloud services.
|
||||
|
@ -54,7 +54,7 @@ class Builder
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getClasses($serviceName, $serviceVersion)
|
||||
private function getClasses(string $serviceName, int $serviceVersion)
|
||||
{
|
||||
$rootNamespace = sprintf("%s\\%s\\v%d", $this->rootNamespace, $serviceName, $serviceVersion);
|
||||
|
||||
|
@ -70,19 +70,18 @@ class Builder
|
|||
* directly - this setup includes the configuration of the HTTP client's base URL, and the
|
||||
* attachment of an authentication handler.
|
||||
*
|
||||
* @param $serviceName The name of the service as it appears in the OpenCloud\* namespace
|
||||
* @param $serviceVersion The major version of the service
|
||||
* @param array $serviceOptions The service-specific options to use
|
||||
* @param string $serviceName The name of the service as it appears in the OpenCloud\* namespace
|
||||
* @param int $serviceVersion The major version of the service
|
||||
* @param array $serviceOptions The service-specific options to use
|
||||
*
|
||||
* @return \OpenCloud\Common\Service\ServiceInterface
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function createService($serviceName, $serviceVersion, array $serviceOptions = [])
|
||||
public function createService(string $serviceName, int $serviceVersion, array $serviceOptions = []): ServiceInterface
|
||||
{
|
||||
$options = $this->mergeOptions($serviceOptions);
|
||||
|
||||
$this->stockIdentityService($options);
|
||||
$this->stockAuthHandler($options);
|
||||
$this->stockHttpClient($options, $serviceName);
|
||||
|
||||
|
@ -91,7 +90,7 @@ class Builder
|
|||
return new $serviceClass($options['httpClient'], new $apiClass());
|
||||
}
|
||||
|
||||
private function stockHttpClient(array &$options, $serviceName)
|
||||
private function stockHttpClient(array &$options, string $serviceName)
|
||||
{
|
||||
if (!isset($options['httpClient']) || !($options['httpClient'] instanceof ClientInterface)) {
|
||||
if (strcasecmp($serviceName, 'identity') === 0) {
|
||||
|
@ -121,16 +120,9 @@ class Builder
|
|||
}
|
||||
}
|
||||
|
||||
private function stockIdentityService(array &$options)
|
||||
{
|
||||
if (!isset($options['identityService'])) {
|
||||
$httpClient = $this->httpClient($options['authUrl'], HandlerStack::create());
|
||||
$options['identityService'] = Service::factory($httpClient);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $options
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function stockAuthHandler(array &$options)
|
||||
|
@ -142,14 +134,14 @@ class Builder
|
|||
}
|
||||
}
|
||||
|
||||
private function getStack(callable $authHandler, Token $token = null)
|
||||
private function getStack(callable $authHandler, Token $token = null): HandlerStack
|
||||
{
|
||||
$stack = HandlerStack::create();
|
||||
$stack->push(Middleware::authHandler($authHandler, $token));
|
||||
return $stack;
|
||||
}
|
||||
|
||||
private function httpClient($baseUrl, HandlerStack $stack)
|
||||
private function httpClient(string $baseUrl, HandlerStack $stack): ClientInterface
|
||||
{
|
||||
return new Client([
|
||||
'base_uri' => Utils::normalizeUrl($baseUrl),
|
||||
|
@ -157,7 +149,7 @@ class Builder
|
|||
]);
|
||||
}
|
||||
|
||||
private function mergeOptions(array $serviceOptions)
|
||||
private function mergeOptions(array $serviceOptions): array
|
||||
{
|
||||
$options = array_merge($this->defaults, $this->globalOptions, $serviceOptions);
|
||||
|
||||
|
@ -165,6 +157,12 @@ class Builder
|
|||
throw new \InvalidArgumentException('"authUrl" is a required option');
|
||||
}
|
||||
|
||||
if (!isset($options['identityService']) || !($options['identityService'] instanceof IdentityService)) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'"identityService" must be specified and implement %s', IdentityService::class
|
||||
));
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace OpenCloud\Common\Service;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace OpenCloud\Common\Transport;
|
||||
|
||||
|
@ -7,7 +7,7 @@ use GuzzleHttp\HandlerStack as GuzzleStack;
|
|||
|
||||
class HandlerStack extends GuzzleStack
|
||||
{
|
||||
public static function create(callable $handler = null)
|
||||
public static function create(callable $handler = null): self
|
||||
{
|
||||
$stack = new self($handler ?: choose_handler());
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace OpenCloud\Common\Transport;
|
||||
|
||||
|
@ -22,7 +22,7 @@ class JsonSerializer
|
|||
*
|
||||
* @return array|mixed
|
||||
*/
|
||||
private function stockValue(Parameter $param, $userValue, $json)
|
||||
private function stockValue(Parameter $param, $userValue, array $json): array
|
||||
{
|
||||
$name = $param->getName();
|
||||
if ($path = $param->getPath()) {
|
||||
|
@ -46,7 +46,7 @@ class JsonSerializer
|
|||
*
|
||||
* @return array|mixed
|
||||
*/
|
||||
private function stockArrayJson(Parameter $param, $userValue)
|
||||
private function stockArrayJson(Parameter $param, array $userValue): array
|
||||
{
|
||||
$elems = [];
|
||||
foreach ($userValue as $item) {
|
||||
|
@ -63,7 +63,7 @@ class JsonSerializer
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
private function stockObjectJson(Parameter $param, $userValue)
|
||||
private function stockObjectJson(Parameter $param, \stdClass $userValue): array
|
||||
{
|
||||
$object = [];
|
||||
foreach ($userValue as $key => $val) {
|
||||
|
@ -82,12 +82,12 @@ class JsonSerializer
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public function stockJson(Parameter $param, $userValue, $json)
|
||||
public function stockJson(Parameter $param, $userValue, array $json): array
|
||||
{
|
||||
if ($param->isArray()) {
|
||||
$userValue = $this->stockArrayJson($param, $userValue);
|
||||
} elseif ($param->isObject()) {
|
||||
$userValue = $this->stockObjectJson($param, $userValue);
|
||||
$userValue = $this->stockObjectJson($param, (object) $userValue);
|
||||
}
|
||||
// Populate the final value
|
||||
return $this->stockValue($param, $userValue, $json);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace OpenCloud\Common\Transport;
|
||||
|
||||
|
@ -9,13 +9,15 @@ use OpenCloud\Common\Auth\AuthHandler;
|
|||
use OpenCloud\Common\Auth\Token;
|
||||
use OpenCloud\Common\Error\Builder;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\LogLevel;
|
||||
|
||||
final class Middleware
|
||||
{
|
||||
/**
|
||||
* @return callable
|
||||
*/
|
||||
public static function httpErrors()
|
||||
public static function httpErrors(): callable
|
||||
{
|
||||
return function (callable $handler) {
|
||||
return function ($request, array $options) use ($handler) {
|
||||
|
@ -37,7 +39,7 @@ final class Middleware
|
|||
*
|
||||
* @return callable
|
||||
*/
|
||||
public static function authHandler(callable $tokenGenerator, Token $token = null)
|
||||
public static function authHandler(callable $tokenGenerator, Token $token = null): callable
|
||||
{
|
||||
return function (callable $handler) use ($tokenGenerator, $token) {
|
||||
return new AuthHandler($handler, $tokenGenerator, $token);
|
||||
|
@ -47,7 +49,7 @@ final class Middleware
|
|||
/**
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function history(array &$container)
|
||||
public static function history(array &$container): callable
|
||||
{
|
||||
return GuzzleMiddleware::history($container);
|
||||
}
|
||||
|
@ -55,7 +57,7 @@ final class Middleware
|
|||
/**
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function retry(callable $decider, callable $delay = null)
|
||||
public static function retry(callable $decider, callable $delay = null): callable
|
||||
{
|
||||
return GuzzleMiddleware::retry($decider, $delay);
|
||||
}
|
||||
|
@ -63,7 +65,7 @@ final class Middleware
|
|||
/**
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function log(LoggerInterface $logger, MessageFormatter $formatter, $logLevel = LogLevel::INFO)
|
||||
public static function log(LoggerInterface $logger, MessageFormatter $formatter, $logLevel = LogLevel::INFO): callable
|
||||
{
|
||||
return GuzzleMiddleware::log($logger, $formatter, $logLevel);
|
||||
}
|
||||
|
@ -71,7 +73,7 @@ final class Middleware
|
|||
/**
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function prepareBody()
|
||||
public static function prepareBody(): callable
|
||||
{
|
||||
return GuzzleMiddleware::prepareBody();
|
||||
}
|
||||
|
@ -79,7 +81,7 @@ final class Middleware
|
|||
/**
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function mapRequest(callable $fn)
|
||||
public static function mapRequest(callable $fn): callable
|
||||
{
|
||||
return GuzzleMiddleware::mapRequest($fn);
|
||||
}
|
||||
|
@ -87,7 +89,7 @@ final class Middleware
|
|||
/**
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function mapResponse(callable $fn)
|
||||
public static function mapResponse(callable $fn): callable
|
||||
{
|
||||
return GuzzleMiddleware::mapResponse($fn);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace OpenCloud\Common\Transport;
|
||||
|
||||
|
@ -17,7 +17,7 @@ class RequestSerializer
|
|||
$this->jsonSerializer = $jsonSerializer ?: new JsonSerializer();
|
||||
}
|
||||
|
||||
public function serializeOptions(Operation $operation, array $userValues = [])
|
||||
public function serializeOptions(Operation $operation, array $userValues = []): array
|
||||
{
|
||||
$options = ['headers' => []];
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace OpenCloud\Common\Transport;
|
||||
|
||||
|
@ -8,7 +8,7 @@ use Psr\Http\Message\UriInterface;
|
|||
|
||||
class Utils
|
||||
{
|
||||
public static function jsonDecode(ResponseInterface $response, $assoc = true)
|
||||
public static function jsonDecode(ResponseInterface $response, bool $assoc = true)
|
||||
{
|
||||
$jsonErrors = [
|
||||
JSON_ERROR_DEPTH => 'JSON_ERROR_DEPTH - Maximum stack depth exceeded',
|
||||
|
@ -40,11 +40,11 @@ class Utils
|
|||
* Method for flattening a nested array.
|
||||
*
|
||||
* @param array $data The nested array
|
||||
* @param null $key The key to extract
|
||||
* @param string $key The key to extract
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function flattenJson($data, $key = null)
|
||||
public static function flattenJson($data, string $key = null)
|
||||
{
|
||||
return (!empty($data) && $key && isset($data[$key])) ? $data[$key] : $data;
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ class Utils
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function normalizeUrl($url)
|
||||
public static function normalizeUrl(string $url): string
|
||||
{
|
||||
if (strpos($url, 'http') === false) {
|
||||
$url = 'http://' . $url;
|
||||
|
@ -76,12 +76,12 @@ class Utils
|
|||
*
|
||||
* @return UriInterface
|
||||
*/
|
||||
public static function addPaths(UriInterface $uri, ...$paths)
|
||||
public static function addPaths(UriInterface $uri, ...$paths): UriInterface
|
||||
{
|
||||
return uri_for(rtrim((string) $uri, '/') . '/' . implode('/', $paths));
|
||||
}
|
||||
|
||||
public static function appendPath(UriInterface $uri, $path)
|
||||
public static function appendPath(UriInterface $uri, $path): UriInterface
|
||||
{
|
||||
return uri_for(rtrim((string) $uri, '/') . '/' . $path);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace OpenCloud\integration;
|
||||
namespace OpenCloud\Integration;
|
||||
|
||||
use Psr\Log\AbstractLogger;
|
||||
|
||||
|
|
|
@ -1,16 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace OpenCloud\integration;
|
||||
namespace OpenCloud\Integration;
|
||||
|
||||
class Runner
|
||||
{
|
||||
private $basePath;
|
||||
private $logger;
|
||||
private $services = [];
|
||||
private $namespace;
|
||||
|
||||
public function __construct($basePath)
|
||||
public function __construct($basePath, $testNamespace)
|
||||
{
|
||||
$this->basePath = $basePath;
|
||||
$this->namespace = $testNamespace;
|
||||
|
||||
$this->logger = new DefaultLogger();
|
||||
$this->assembleServicesFromSamples();
|
||||
}
|
||||
|
@ -73,15 +76,14 @@ class Runner
|
|||
*/
|
||||
private function getTest($serviceName, $version, $verbosity)
|
||||
{
|
||||
$namespace = (new \ReflectionClass($this))->getNamespaceName();
|
||||
$className = sprintf("%s\\%s\\%sTest", $namespace, Utils::toCamelCase($serviceName), ucfirst($version));
|
||||
$className = sprintf("%s\\%s\\%sTest", $this->namespace, Utils::toCamelCase($serviceName), ucfirst($version));
|
||||
|
||||
if (!class_exists($className)) {
|
||||
throw new \RuntimeException(sprintf("%s does not exist", $className));
|
||||
}
|
||||
|
||||
$basePath = $this->basePath . DIRECTORY_SEPARATOR . $serviceName . DIRECTORY_SEPARATOR . $version;
|
||||
$smClass = sprintf("%s\\SampleManager", $namespace);
|
||||
$smClass = sprintf("%s\\SampleManager", $this->namespace);
|
||||
$class = new $className($this->logger, new $smClass($basePath, $verbosity));
|
||||
|
||||
if (!($class instanceof TestInterface)) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace OpenCloud\integration;
|
||||
namespace OpenCloud\Integration;
|
||||
|
||||
interface SampleManagerInterface
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace OpenCloud\integration;
|
||||
namespace OpenCloud\Integration;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace OpenCloud\integration;
|
||||
namespace OpenCloud\Integration;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
|
|
|
@ -1,57 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace OpenCloud\integration;
|
||||
namespace OpenCloud\Integration;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use OpenCloud\Identity\v2\Api;
|
||||
use OpenCloud\Identity\v2\Service;
|
||||
use OpenCloud\Common\Transport\HandlerStack;
|
||||
use OpenCloud\Common\Transport\Utils as CommonUtils;
|
||||
|
||||
class Utils
|
||||
{
|
||||
public static function getAuthOptsV3()
|
||||
{
|
||||
return [
|
||||
'authUrl' => getenv('OS_AUTH_URL'),
|
||||
'region' => getenv('OS_REGION_NAME'),
|
||||
'user' => [
|
||||
'id' => getenv('OS_USER_ID'),
|
||||
'password' => getenv('OS_PASSWORD'),
|
||||
],
|
||||
'scope' => [
|
||||
'project' => [
|
||||
'id' => getenv('OS_PROJECT_ID'),
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public static function getAuthOptsV2()
|
||||
{
|
||||
$httpClient = new Client([
|
||||
'base_uri' => CommonUtils::normalizeUrl(getenv('OS_AUTH_URL')),
|
||||
'handler' => HandlerStack::create(),
|
||||
]);
|
||||
return [
|
||||
'authUrl' => getenv('OS_AUTH_URL'),
|
||||
'region' => getenv('OS_REGION_NAME'),
|
||||
'username' => getenv('OS_USERNAME'),
|
||||
'password' => getenv('OS_PASSWORD'),
|
||||
'tenantName' => getenv('OS_TENANT_NAME'),
|
||||
'identityService' => new Service($httpClient, new Api),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getAuthOpts(array $options = [])
|
||||
{
|
||||
$authOptions = getenv('OS_IDENTITY_API_VERSION') == '2.0'
|
||||
? self::getAuthOptsV2()
|
||||
: self::getAuthOptsV3();
|
||||
|
||||
return array_merge($authOptions, $options);
|
||||
}
|
||||
|
||||
public static function toCamelCase($word, $separator = '_')
|
||||
{
|
||||
return str_replace($separator, '', ucwords($word, $separator));
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
$rootDir = dirname(dirname(__DIR__));
|
||||
|
||||
require_once $rootDir . '/vendor/autoload.php';
|
||||
|
||||
$basePath = $rootDir . '/samples';
|
||||
|
||||
$runner = new \OpenCloud\Integration\Runner($basePath);
|
||||
$runner->runServices();
|
|
@ -10,7 +10,6 @@ use GuzzleHttp\Psr7\Uri;
|
|||
use OpenCloud\Common\Api\Operator;
|
||||
use OpenCloud\Common\Resource\AbstractResource;
|
||||
use OpenCloud\Common\Resource\ResourceInterface;
|
||||
use OpenCloud\Compute\v2\Models\Server;
|
||||
use OpenCloud\Test\Fixtures\ComputeV2Api;
|
||||
use OpenCloud\Test\TestCase;
|
||||
use Prophecy\Argument;
|
||||
|
@ -45,7 +44,7 @@ class OperatorTest extends TestCase
|
|||
|
||||
public function test_it_sends_a_request_when_operations_are_executed()
|
||||
{
|
||||
$this->client->request('GET', 'test', ['headers' => []])->willReturn(new Request('GET', 'test'));
|
||||
$this->client->request('GET', 'test', ['headers' => []])->willReturn(new Response());
|
||||
|
||||
$this->operator->execute($this->def, []);
|
||||
}
|
||||
|
|
|
@ -53,7 +53,11 @@ class AuthHandlerTest extends TestCase
|
|||
}
|
||||
}
|
||||
|
||||
class FakeToken implements Token {
|
||||
public function getId() {}
|
||||
public function hasExpired() {}
|
||||
class FakeToken implements Token
|
||||
{
|
||||
public function getId(): string
|
||||
{}
|
||||
|
||||
public function hasExpired(): bool
|
||||
{}
|
||||
}
|
|
@ -95,8 +95,8 @@ class SchemaTest extends TestCase
|
|||
|
||||
public function test_it_checks_validity()
|
||||
{
|
||||
$this->validator->isValid()->shouldBeCalled();
|
||||
$this->validator->isValid()->shouldBeCalled()->willReturn(true);
|
||||
|
||||
$this->schema->isValid();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -47,8 +47,8 @@ class JsonSerializerTest extends \PHPUnit_Framework_TestCase
|
|||
$itemSchema = $this->prophesize(Parameter::class);
|
||||
$itemSchema->isArray()->shouldBeCalled()->willReturn(false);
|
||||
$itemSchema->isObject()->shouldBeCalled()->willReturn(false);
|
||||
$itemSchema->getName()->shouldBeCalled()->willReturn(null);
|
||||
$itemSchema->getPath()->shouldBeCalled()->willReturn(null);
|
||||
$itemSchema->getName()->shouldBeCalled()->willReturn('');
|
||||
$itemSchema->getPath()->shouldBeCalled()->willReturn('');
|
||||
|
||||
$param->getItemSchema()->shouldBeCalled()->willReturn($itemSchema);
|
||||
|
||||
|
@ -67,7 +67,7 @@ class JsonSerializerTest extends \PHPUnit_Framework_TestCase
|
|||
$prop->isArray()->shouldBeCalled()->willReturn(false);
|
||||
$prop->isObject()->shouldBeCalled()->willReturn(false);
|
||||
$prop->getName()->shouldBeCalled()->willReturn('foo');
|
||||
$prop->getPath()->shouldBeCalled()->willReturn(null);
|
||||
$prop->getPath()->shouldBeCalled()->willReturn('');
|
||||
|
||||
$param = $this->prophesize(Parameter::class);
|
||||
$param->isArray()->shouldBeCalled()->willReturn(false);
|
||||
|
@ -78,7 +78,7 @@ class JsonSerializerTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
$expected = ['topLevel' => ['foo' => true]];
|
||||
|
||||
$json = $this->serializer->stockJson($param->reveal(), ['foo' => true], []);
|
||||
$json = $this->serializer->stockJson($param->reveal(), (object) ['foo' => true], []);
|
||||
|
||||
$this->assertEquals($expected, $json);
|
||||
}
|
||||
|
|
|
@ -53,7 +53,17 @@ class ComputeV2Api implements ApiInterface
|
|||
]
|
||||
],
|
||||
'name' => ['type' => 'string', 'required' => true],
|
||||
'metadata' => ['type' => 'object', 'location' => 'json'],
|
||||
'metadata' => [
|
||||
'type' => 'object',
|
||||
'location' => 'json',
|
||||
'description' => 'An arbitrary key/value pairing that will be used for metadata.',
|
||||
'properties' => [
|
||||
'type' => 'string',
|
||||
'description' => <<<TYPEOTHER
|
||||
The value being set for your key. Bear in mind that "key" is just an example, you can name it anything.
|
||||
TYPEOTHER
|
||||
]
|
||||
],
|
||||
'personality' => ['type' => 'string'],
|
||||
'blockDeviceMapping' => [
|
||||
'type' => 'array',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue