Skip to content

Commit 2346777

Browse files
authored
Merge pull request #184 from mrwogu/php-7.2
PHP 7.2 Compatibility (+ updated php-cs-fixer & PHPUnit)
2 parents cdfcd5e + 756a8f8 commit 2346777

File tree

34 files changed

+149
-72
lines changed

34 files changed

+149
-72
lines changed

.php_cs.dist

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
if (!file_exists(__DIR__.'/src')) {
3+
exit(0);
4+
}
5+
return PhpCsFixer\Config::create()
6+
->setRules(
7+
[
8+
'@PSR2' => true,
9+
'array_syntax' => ['syntax' => 'short'],
10+
'protected_to_private' => false
11+
]
12+
)
13+
->setUsingCache(false)
14+
->setRiskyAllowed(true)
15+
->setFinder(
16+
PhpCsFixer\Finder::create()
17+
->in(__DIR__.'/src')
18+
->append([__FILE__, __DIR__.'/samples'])
19+
);

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ before_install:
2424
before_script:
2525
- composer install --prefer-source
2626
- vendor/bin/parallel-lint --exclude vendor .
27-
- vendor/bin/php-cs-fixer fix --dry-run --diff --level psr2 .
27+
- vendor/bin/php-cs-fixer fix --dry-run --diff
2828
- phpenv config-add ./xdebug.ini
2929

3030
after_script:

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,23 @@ OpenStack services, and versions of services, are supported.
1212

1313
* [Official documentation](http://docs.os.php-opencloud.com/)
1414
* [Reference documentation](http://refdocs.os.php-opencloud.com)
15-
* [Developer support](https://developer.rackspace.com/)
16-
* [Mailing list](https://groups.google.com/forum/#!forum/php-opencloud)
1715
* [Contributing guide](/CONTRIBUTING.md)
1816
* [Code of Conduct](/CODE_OF_CONDUCT.md)
1917

18+
## Backward incompatibility
19+
20+
Due to new [object typehint](https://wiki.php.net/rfc/object-typehint) since PHP 7.2, `Object` is a reserved keyword
21+
thus class `OpenStack\ObjectStore\v1\Models\Object` had to be renamed to
22+
`OpenStack\ObjectStore\v1\Models\StorageObject`. See [#184](https://github.com/php-opencloud/openstack/pull/184) for
23+
details.
24+
25+
### Version Guidance
26+
27+
| Version | Status | PHP Version | Life span |
28+
| --------- | --------------------------- | ------------- | ----------------------- |
29+
| `^2.0` | Maintained (Bug fixes only) | `^=7.0,<7.2` | March 2016 - March 2018 |
30+
| `^3.0` | Latest | `^7.0` | March 2018 - March 2020 |
31+
2032
## Getting help
2133

2234
- Meet us on Slack: https://phpopencloud.slack.com ([Get your invitation](https://launchpass.com/phpopencloud))

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@
4444
"justinrainbow/json-schema": "~5.2"
4545
},
4646
"require-dev": {
47-
"phpunit/phpunit": "~4.0",
47+
"phpunit/phpunit": "^6.5",
4848
"sami/sami": "dev-master",
4949
"psr/log": "~1.0",
5050
"satooshi/php-coveralls": "~1.0",
5151
"jakub-onderka/php-parallel-lint": "0.*",
52-
"friendsofphp/php-cs-fixer": "^1.0"
52+
"friendsofphp/php-cs-fixer": "^2.9"
5353
}
5454
}

doc/services/object-store/v1/objects.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Download an object
2727
------------------
2828

2929
.. sample:: object_store/v1/objects/download.php
30-
.. refdoc:: OpenStack/ObjectStore/v1/Models/Object.html#method_download
30+
.. refdoc:: OpenStack/ObjectStore/v1/Models/StorageObject.html#method_download
3131

3232
As you will notice, a Stream_ object is returned by this call. For more information about dealing with streams, please
3333
consult `Guzzle's docs`_.
@@ -88,19 +88,19 @@ Copy object
8888
-----------
8989

9090
.. sample:: object_store/v1/objects/copy.php
91-
.. refdoc:: OpenStack/ObjectStore/v1/Models/Object.html#method_copy
91+
.. refdoc:: OpenStack/ObjectStore/v1/Models/StorageObject.html#method_copy
9292

9393
Delete object
9494
-------------
9595

9696
.. sample:: object_store/v1/objects/delete.php
97-
.. refdoc:: OpenStack/ObjectStore/v1/Models/Object.html#method_delete
97+
.. refdoc:: OpenStack/ObjectStore/v1/Models/StorageObject.html#method_delete
9898

9999
Get metadata
100100
------------
101101

102102
.. sample:: object_store/v1/objects/get_metadata.php
103-
.. refdoc:: OpenStack/ObjectStore/v1/Models/Object.html#method_getMetadata
103+
.. refdoc:: OpenStack/ObjectStore/v1/Models/StorageObject.html#method_getMetadata
104104

105105
The returned value will be a standard associative array, or hash, containing arbitrary key/value pairs. These will
106106
correspond to the values set either when the object was created, or when a previous ``mergeMetadata`` or
@@ -110,7 +110,7 @@ Replace all metadata with new values
110110
------------------------------------
111111

112112
.. sample:: object_store/v1/objects/reset_metadata.php
113-
.. refdoc:: OpenStack/ObjectStore/v1/Models/Object.html#method_resetMetadata
113+
.. refdoc:: OpenStack/ObjectStore/v1/Models/StorageObject.html#method_resetMetadata
114114

115115
In order to replace all existing metadata with a set of new values, you can use this operation. Any existing metadata
116116
items which not specified in the new set will be removed. For example, say an account has the following metadata
@@ -140,7 +140,7 @@ Merge new metadata values with existing
140140
---------------------------------------
141141

142142
.. sample:: object_store/v1/objects/merge_metadata.php
143-
.. refdoc:: OpenStack/ObjectStore/v1/Models/Object.html#method_mergeMetadata
143+
.. refdoc:: OpenStack/ObjectStore/v1/Models/StorageObject.html#method_mergeMetadata
144144

145145
In order to merge a set of new metadata values with the existing metadata set, you can use this operation. Any existing
146146
metadata items which are not specified in the new set will be preserved. For example, say an account has the following

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit bootstrap="./vendor/autoload.php" colors="true">
2+
<phpunit bootstrap="./vendor/autoload.php" colors="true" strict="true">
33

44
<testsuites>
55
<testsuite name="OpenStack">

samples/object_store/v1/objects/create.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
'content' => '{objectContent}',
1818
];
1919

20-
/** @var \OpenStack\ObjectStore\v1\Models\Object $object */
20+
/** @var \OpenStack\ObjectStore\v1\Models\StorageObject $object */
2121
$object = $openstack->objectStoreV1()
2222
->getContainer('{containerName}')
2323
->createObject($options);

samples/object_store/v1/objects/create_from_stream.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
'stream' => $stream,
2323
];
2424

25-
/** @var \OpenStack\ObjectStore\v1\Models\Object $object */
25+
/** @var \OpenStack\ObjectStore\v1\Models\StorageObject $object */
2626
$object = $openstack->objectStoreV1()
2727
->getContainer('{containerName}')
2828
->createObject($options);

samples/object_store/v1/objects/create_large_object.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
$options['segmentContainer'] = 'test_segments';
2828

2929

30-
/** @var \OpenStack\ObjectStore\v1\Models\Object $object */
30+
/** @var \OpenStack\ObjectStore\v1\Models\StorageObject $object */
3131
$object = $openstack->objectStoreV1()
3232
->getContainer('test')
3333
->createLargeObject($options);

samples/object_store/v1/objects/get.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
'scope' => ['project' => ['id' => '{projectId}']]
1313
]);
1414

15-
/** @var \OpenStack\ObjectStore\v1\Models\Object $object */
15+
/** @var \OpenStack\ObjectStore\v1\Models\StorageObject $object */
1616
$object = $openstack->objectStoreV1()
1717
->getContainer('{containerName}')
1818
->getObject('{objectName}');

samples/object_store/v1/objects/list.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
->getContainer('{containerName}');
1717

1818
foreach ($container->listObjects() as $object) {
19-
/** @var \OpenStack\ObjectStore\v1\Models\Object $object */
19+
/** @var \OpenStack\ObjectStore\v1\Models\StorageObject $object */
2020
}

src/Common/Api/Parameter.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ private function validateEnums($userValues)
207207
{
208208
if (!empty($this->enum) && $this->type == 'string' && !in_array($userValues, $this->enum)) {
209209
throw new \Exception(sprintf(
210-
'The only permitted values are %s. You provided %s', implode(', ', $this->enum), print_r($userValues, true)
210+
'The only permitted values are %s. You provided %s',
211+
implode(', ', $this->enum),
212+
print_r($userValues, true)
211213
));
212214
}
213215
}
@@ -217,7 +219,10 @@ private function validateType($userValues)
217219
if (!$this->hasCorrectType($userValues)) {
218220
throw new \Exception(sprintf(
219221
'The key provided "%s" has the wrong value type. You provided %s (%s) but was expecting %s',
220-
$this->name, print_r($userValues, true), gettype($userValues), $this->type
222+
$this->name,
223+
print_r($userValues, true),
224+
gettype($userValues),
225+
$this->type
221226
));
222227
}
223228
}

src/Common/Error/Builder.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,11 @@ public function httpError(RequestInterface $request, ResponseInterface $response
116116
{
117117
$message = $this->header('HTTP Error');
118118

119-
$message .= sprintf("The remote server returned a \"%d %s\" error for the following transaction:\n\n",
120-
$response->getStatusCode(), $response->getReasonPhrase());
119+
$message .= sprintf(
120+
"The remote server returned a \"%d %s\" error for the following transaction:\n\n",
121+
$response->getStatusCode(),
122+
$response->getReasonPhrase()
123+
);
121124

122125
$message .= $this->header('Request');
123126
$message .= trim($this->str($request)) . PHP_EOL . PHP_EOL;
@@ -163,8 +166,11 @@ public function userInputError(string $expectedType, $userValue, string $further
163166
{
164167
$message = $this->header('User Input Error');
165168

166-
$message .= sprintf("%s was expected, but the following value was passed in:\n\n%s\n",
167-
$expectedType, print_r($userValue, true));
169+
$message .= sprintf(
170+
"%s was expected, but the following value was passed in:\n\n%s\n",
171+
$expectedType,
172+
print_r($userValue, true)
173+
);
168174

169175
$message .= "Please ensure that the value adheres to the expectation above. ";
170176

src/Common/JsonSchema/JsonPatch.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ protected function handleObject(\stdClass $srcStruct, \stdClass $desStruct, stri
7878

7979
protected function shouldPartiallyReplace(\stdClass $o1, \stdClass $o2): bool
8080
{
81-
return count(array_diff_key((array) $o1, (array) $o2)) < count($o1);
81+
// NOTE: count(stdClass) always returns 1
82+
return count(array_diff_key((array) $o1, (array) $o2)) < 1;
8283
}
8384

8485
protected function arrayDiff(array $a1, array $a2): array

src/Common/Resource/AbstractResource.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ abstract class AbstractResource implements ResourceInterface, Serializable
4242
*
4343
* @return AbstractResource
4444
*/
45-
public function populateFromResponse(ResponseInterface $response): self
45+
public function populateFromResponse(ResponseInterface $response)
4646
{
4747
if (strpos($response->getHeaderLine('Content-Type'), 'application/json') === 0) {
4848
$json = Utils::jsonDecode($response);
@@ -61,7 +61,7 @@ public function populateFromResponse(ResponseInterface $response): self
6161
*
6262
* @return mixed|void
6363
*/
64-
public function populateFromArray(array $array): self
64+
public function populateFromArray(array $array)
6565
{
6666
$aliases = $this->getAliases();
6767

src/Common/Service/Builder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ private function mergeOptions(array $serviceOptions): array
166166

167167
if (!isset($options['identityService']) || !($options['identityService'] instanceof IdentityService)) {
168168
throw new \InvalidArgumentException(sprintf(
169-
'"identityService" must be specified and implement %s', IdentityService::class
169+
'"identityService" must be specified and implement %s',
170+
IdentityService::class
170171
));
171172
}
172173

src/Common/Transport/JsonSerializer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ private function serializeObjectValue($value)
101101
} elseif (!($value instanceof \stdClass)) {
102102
throw new \InvalidArgumentException(sprintf(
103103
'When an object value is provided, it must either be \stdClass or implement the Serializable '
104-
. 'interface, you provided %s', print_r($value, true)
104+
. 'interface, you provided %s',
105+
print_r($value, true)
105106
));
106107
}
107108
}

src/Identity/v2/Models/Catalog.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ public function getServiceUrl(
6161

6262
throw new \RuntimeException(sprintf(
6363
"Endpoint URL could not be found in the catalog for this service.\nName: %s\nType: %s\nRegion: %s\nURL type: %s",
64-
$serviceName, $serviceType, $region, $urlType
64+
$serviceName,
65+
$serviceType,
66+
$region,
67+
$urlType
6568
));
6669
}
6770
}

src/Identity/v3/Models/Catalog.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ public function getServiceUrl(string $name, string $type, string $region, string
5656

5757
throw new \RuntimeException(sprintf(
5858
"Endpoint URL could not be found in the catalog for this service.\nName: %s\nType: %s\nRegion: %s\nURL type: %s",
59-
$name, $type, $region, $urlType
59+
$name,
60+
$type,
61+
$region,
62+
$urlType
6063
));
6164
}
6265
}

src/Identity/v3/Service.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,13 @@ public function authenticate(array $options): array
5050
return [$token, $baseUrl];
5151
}
5252

53-
throw new \RuntimeException(sprintf("No service found with type [%s] name [%s] region [%s] interface [%s]",
54-
$type, $name, $region, $interface));
53+
throw new \RuntimeException(sprintf(
54+
"No service found with type [%s] name [%s] region [%s] interface [%s]",
55+
$type,
56+
$name,
57+
$region,
58+
$interface
59+
));
5560
}
5661

5762
/**

src/ObjectStore/v1/Models/Container.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function populateFromResponse(ResponseInterface $response): self
6161
public function listObjects(array $options = [], callable $mapFn = null): \Generator
6262
{
6363
$options = array_merge($options, ['name' => $this->name, 'format' => 'json']);
64-
return $this->model(Object::class)->enumerate($this->api->getContainer(), $options, $mapFn);
64+
return $this->model(StorageObject::class)->enumerate($this->api->getContainer(), $options, $mapFn);
6565
}
6666

6767
/**
@@ -136,17 +136,17 @@ public function getMetadata(): array
136136
}
137137

138138
/**
139-
* Retrieves an Object and populates its `name` and `containerName` properties according to the name provided and
139+
* Retrieves an StorageObject and populates its `name` and `containerName` properties according to the name provided and
140140
* the name of this container. A HTTP call will not be executed by default - you need to call
141-
* {@see Object::retrieve} or {@see Object::download} on the returned Object object to do that.
141+
* {@see StorageObject::retrieve} or {@see StorageObject::download} on the returned StorageObject object to do that.
142142
*
143143
* @param string $name The name of the object
144144
*
145-
* @return Object
145+
* @return StorageObject
146146
*/
147-
public function getObject($name): Object
147+
public function getObject($name): StorageObject
148148
{
149-
return $this->model(Object::class, ['containerName' => $this->name, 'name' => $name]);
149+
return $this->model(StorageObject::class, ['containerName' => $this->name, 'name' => $name]);
150150
}
151151

152152
/**
@@ -179,9 +179,9 @@ public function objectExists(string $name): bool
179179
*
180180
* @return Object
181181
*/
182-
public function createObject(array $data): Object
182+
public function createObject(array $data): StorageObject
183183
{
184-
return $this->model(Object::class)->create($data + ['containerName' => $this->name]);
184+
return $this->model(StorageObject::class)->create($data + ['containerName' => $this->name]);
185185
}
186186

187187
/**
@@ -195,9 +195,9 @@ public function createObject(array $data): Object
195195
* @param string $data['segmentPrefix'] The prefix that will come before each segment. If omitted, a default
196196
* is used: name/timestamp/filesize
197197
*
198-
* @return Object
198+
* @return StorageObject
199199
*/
200-
public function createLargeObject(array $data): Object
200+
public function createLargeObject(array $data): StorageObject
201201
{
202202
/** @var \Psr\Http\Message\StreamInterface $stream */
203203
$stream = $data['stream'];
@@ -218,7 +218,7 @@ public function createLargeObject(array $data): Object
218218
$count = 0;
219219

220220
while (!$stream->eof() && $count < round($stream->getSize() / $segmentSize)) {
221-
$promises[] = $this->model(Object::class)->createAsync([
221+
$promises[] = $this->model(StorageObject::class)->createAsync([
222222
'name' => sprintf("%s/%d", $segmentPrefix, ++$count),
223223
'stream' => new LimitStream($stream, $segmentSize, ($count - 1) * $segmentSize),
224224
'containerName' => $segmentContainer,

src/ObjectStore/v1/Models/Object.php renamed to src/ObjectStore/v1/Models/StorageObject.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/**
1515
* @property \OpenStack\ObjectStore\v1\Api $api
1616
*/
17-
class Object extends OperatorResource implements Creatable, Deletable, HasMetadata
17+
class StorageObject extends OperatorResource implements Creatable, Deletable, HasMetadata
1818
{
1919
use MetadataTrait;
2020

tests/integration/Compute/v2/CoreTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,8 @@ private function attachVolumeToServer()
672672

673673
$this->volume->waitUntil('in-use');
674674

675-
$this->logStep('Attached volume {volumeId} to server {serverId} with volume attachment id {volumeAttachmentId}',
675+
$this->logStep(
676+
'Attached volume {volumeId} to server {serverId} with volume attachment id {volumeAttachmentId}',
676677
array_merge($replacements, ['{volumeAttachmentId}' => $volumeAttachment->id])
677678
);
678679
}

0 commit comments

Comments
 (0)