Skip to content

Commit a3fbe53

Browse files
author
Jamie Hannaford
committed
Shift to PHP 7
1 parent d549dd4 commit a3fbe53

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+222
-190
lines changed

src/Common/Api/AbstractApi.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
<?php
1+
<?php declare(strict_types = 1);
22

33
namespace OpenCloud\Common\Api;
44

55
abstract class AbstractApi implements ApiInterface
66
{
77
protected $params;
88

9-
protected function isRequired(array $param)
9+
protected function isRequired(array $param): array
1010
{
1111
return array_merge($param, ['required' => true]);
1212
}
1313

14-
protected function notRequired(array $param)
14+
protected function notRequired(array $param): array
1515
{
1616
return array_merge($param, ['required' => false]);
1717
}
1818

19-
protected function query(array $param)
19+
protected function query(array $param): array
2020
{
2121
return array_merge($param, ['location' => AbstractParams::QUERY]);
2222
}
2323

24-
protected function url(array $param)
24+
protected function url(array $param): array
2525
{
2626
return array_merge($param, ['location' => AbstractParams::URL]);
2727
}
2828

29-
public function documented(array $param)
29+
public function documented(array $param): array
3030
{
3131
return array_merge($param, ['required' => true]);
3232
}

src/Common/Api/AbstractParams.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
namespace OpenCloud\Common\Api;
44

@@ -21,12 +21,12 @@ abstract class AbstractParams
2121
const INT_TYPE = 'integer';
2222
const INTEGER_TYPE = self::INT_TYPE;
2323

24-
public static function isSupportedLocation($val)
24+
public static function isSupportedLocation(string $val): bool
2525
{
2626
return in_array($val, [self::QUERY, self::HEADER, self::URL, self::JSON, self::RAW]);
2727
}
2828

29-
public function limit()
29+
public function limit(): array
3030
{
3131
return [
3232
'type' => self::INT_TYPE,
@@ -38,7 +38,7 @@ public function limit()
3838
];
3939
}
4040

41-
public function marker()
41+
public function marker(): array
4242
{
4343
return [
4444
'type' => 'string',
@@ -51,7 +51,7 @@ public function marker()
5151
];
5252
}
5353

54-
public function id($type)
54+
public function id(string $type): array
5555
{
5656
return [
5757
'description' => sprintf("The unique ID, or identifier, for the %s", $type),
@@ -60,7 +60,7 @@ public function id($type)
6060
];
6161
}
6262

63-
public function idPath()
63+
public function idPath(): array
6464
{
6565
return [
6666
'type' => self::STRING_TYPE,
@@ -69,7 +69,7 @@ public function idPath()
6969
];
7070
}
7171

72-
public function name($resource)
72+
public function name(string $resource): array
7373
{
7474
return [
7575
'description' => sprintf("The name of the %s", $resource),
@@ -79,7 +79,7 @@ public function name($resource)
7979
}
8080

8181

82-
public function sortDir()
82+
public function sortDir(): array
8383
{
8484
return [
8585
'type' => self::STRING_TYPE,
@@ -89,12 +89,12 @@ public function sortDir()
8989
];
9090
}
9191

92-
public function sortKey()
92+
public function sortKey(): array
9393
{
9494
return [
9595
'type' => self::STRING_TYPE,
9696
'location' => self::QUERY,
9797
'description' => "Sorts by one or more sets of attribute and sort direction combinations.",
9898
];
9999
}
100-
}
100+
}

src/Common/Api/ApiInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
namespace OpenCloud\Common\Api;
44

src/Common/Api/Operation.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
namespace OpenCloud\Common\Api;
44

5-
use GuzzleHttp\Utils;
6-
75
/**
86
* This class represents an OpenCloud API operation. It encapsulates most aspects of the REST operation: its HTTP
97
* method, the URL path, its top-level JSON key, and all of its {@see Parameter} objects.
@@ -49,15 +47,15 @@ public function __construct(array $definition)
4947
/**
5048
* @return string
5149
*/
52-
public function getPath()
50+
public function getPath(): string
5351
{
5452
return $this->path;
5553
}
5654

5755
/**
5856
* @return string
5957
*/
60-
public function getMethod()
58+
public function getMethod(): string
6159
{
6260
return $this->method;
6361
}
@@ -69,7 +67,7 @@ public function getMethod()
6967
*
7068
* @return bool
7169
*/
72-
public function hasParam($key)
70+
public function hasParam(string $key): bool
7371
{
7472
return isset($this->params[$key]);
7573
}
@@ -79,17 +77,17 @@ public function hasParam($key)
7977
*
8078
* @return Parameter
8179
*/
82-
public function getParam($name)
80+
public function getParam(string $name)
8381
{
8482
return isset($this->params[$name]) ? $this->params[$name] : null;
8583
}
8684

8785
/**
8886
* @return string
8987
*/
90-
public function getJsonKey()
88+
public function getJsonKey(): string
9189
{
92-
return $this->jsonKey;
90+
return $this->jsonKey ?: '';
9391
}
9492

9593
/**
@@ -100,7 +98,7 @@ public function getJsonKey()
10098
*
10199
* @return array
102100
*/
103-
public static function toParamArray(array $data)
101+
public static function toParamArray(array $data): array
104102
{
105103
$params = [];
106104

@@ -121,7 +119,7 @@ public static function toParamArray(array $data)
121119
* @return bool TRUE if validation passes
122120
* @throws \Exception If validate fails
123121
*/
124-
public function validate(array $userValues)
122+
public function validate(array $userValues): bool
125123
{
126124
foreach ($this->params as $paramName => $param) {
127125
if (array_key_exists($paramName, $userValues)) {
@@ -133,4 +131,4 @@ public function validate(array $userValues)
133131

134132
return true;
135133
}
136-
}
134+
}

src/Common/Api/Operator.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
namespace OpenCloud\Common\Api;
44

5+
use GuzzleHttp\Promise\PromiseInterface;
6+
use GuzzleHttp\Psr7\Uri;
57
use function GuzzleHttp\uri_template;
68
use GuzzleHttp\ClientInterface;
79
use GuzzleHttp\Promise\Promise;
@@ -60,12 +62,12 @@ public function __debugInfo()
6062
*
6163
* @return Operation
6264
*/
63-
public function getOperation(array $definition)
65+
public function getOperation(array $definition): Operation
6466
{
6567
return new Operation($definition);
6668
}
6769

68-
protected function sendRequest(Operation $operation, array $userValues = [], $async = false)
70+
protected function sendRequest(Operation $operation, array $userValues = [], bool $async = false)
6971
{
7072
$operation->validate($userValues);
7173

@@ -79,23 +81,23 @@ protected function sendRequest(Operation $operation, array $userValues = [], $as
7981
/**
8082
* {@inheritDoc}
8183
*/
82-
public function execute(array $definition, array $userValues = [])
84+
public function execute(array $definition, array $userValues = []): ResponseInterface
8385
{
8486
return $this->sendRequest($this->getOperation($definition), $userValues);
8587
}
8688

8789
/**
8890
* {@inheritDoc}
8991
*/
90-
public function executeAsync(array $definition, array $userValues = [])
92+
public function executeAsync(array $definition, array $userValues = []): PromiseInterface
9193
{
9294
return $this->sendRequest($this->getOperation($definition), $userValues, true);
9395
}
9496

9597
/**
9698
* {@inheritDoc}
9799
*/
98-
public function model($class, $data = null)
100+
public function model(string $class, $data = null): ResourceInterface
99101
{
100102
$model = new $class($this->client, $this->api);
101103

@@ -121,15 +123,15 @@ public function model($class, $data = null)
121123
*
122124
* @return static
123125
*/
124-
public function newInstance()
126+
public function newInstance(): self
125127
{
126128
return new static($this->client, $this->api);
127129
}
128130

129131
/**
130132
* @return \GuzzleHttp\Psr7\Uri
131133
*/
132-
protected function getHttpBaseUrl()
134+
protected function getHttpBaseUrl(): Uri
133135
{
134136
return $this->client->getConfig('base_uri');
135137
}

src/Common/Api/OperatorInterface.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
namespace OpenCloud\Common\Api;
44

55
use GuzzleHttp\ClientInterface;
6+
use GuzzleHttp\Promise\PromiseInterface;
7+
use OpenCloud\Common\Resource\ResourceInterface;
8+
use Psr\Http\Message\ResponseInterface;
69

710
/**
811
* An operator is any resource or service that can invoke and send REST operations. In other words, it
@@ -28,7 +31,7 @@ public function __construct(ClientInterface $client, ApiInterface $api);
2831
*
2932
* @return \Psr\Http\Message\ResponseInterface
3033
*/
31-
public function execute(array $definition, array $userValues = []);
34+
public function execute(array $definition, array $userValues = []): ResponseInterface;
3235

3336
/**
3437
* A convenience method that assembles an operation and asynchronously sends it to the remote API
@@ -38,7 +41,7 @@ public function execute(array $definition, array $userValues = []);
3841
*
3942
* @return \GuzzleHttp\Promise\PromiseInterface
4043
*/
41-
public function executeAsync(array $definition, array $userValues = []);
44+
public function executeAsync(array $definition, array $userValues = []): PromiseInterface;
4245

4346
/**
4447
* @param string $name The name of the model class.
@@ -47,5 +50,5 @@ public function executeAsync(array $definition, array $userValues = []);
4750
*
4851
* @return \OpenCloud\Common\Resource\ResourceInterface
4952
*/
50-
public function model($name, $data = null);
53+
public function model(string $name, $data = null): ResourceInterface;
5154
}

0 commit comments

Comments
 (0)