Skip to content

PHP 7.2 Compatibility (+ updated php-cs-fixer & PHPUnit) #184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Feb 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 19 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
if (!file_exists(__DIR__.'/src')) {
exit(0);
}
return PhpCsFixer\Config::create()
->setRules(
[
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'protected_to_private' => false
]
)
->setUsingCache(false)
->setRiskyAllowed(true)
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__.'/src')
->append([__FILE__, __DIR__.'/samples'])
);
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ language: php

sudo: false

dist: precise

cache:
directories:
- $HOME/.composer/cache
Expand All @@ -12,6 +10,7 @@ matrix:
include:
- php: 7.0
- php: 7.1
- php: 7.2
- php: nightly
allow_failures:
- php: nightly
Expand All @@ -25,7 +24,7 @@ before_install:
before_script:
- composer install --prefer-source
- vendor/bin/parallel-lint --exclude vendor .
- vendor/bin/php-cs-fixer fix --dry-run --diff --level psr2 .
- vendor/bin/php-cs-fixer fix --dry-run --diff
- phpenv config-add ./xdebug.ini

after_script:
Expand Down
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,26 @@ OpenStack services, and versions of services, are supported.

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

## Backward incompatibility

Due to new [object typehint](https://wiki.php.net/rfc/object-typehint) since PHP 7.2, `Object` is a reserved keyword
thus class `OpenStack\ObjectStore\v1\Models\Object` had to be renamed to
`OpenStack\ObjectStore\v1\Models\StorageObject`. See [#184](https://github.com/php-opencloud/openstack/pull/184) for
details.

### Version Guidance

| Version | Status | PHP Version | Life span |
| --------- | --------------------------- | ------------- | ----------------------- |
| `^2.0` | Maintained (Bug fixes only) | `^=7.0,<7.2` | March 2016 - March 2018 |
| `^3.0` | Latest | `^7.0` | March 2018 - March 2020 |

## Getting help

- Meet us on Slack: https://phpopencloud.slack.com ([Get your invitation](https://slackpass.io/phpopencloud))
- Meet us on Slack: https://phpopencloud.slack.com ([Get your invitation](https://launchpass.com/phpopencloud))
- Report and issue: https://github.com/php-opencloud/openstack/issues

## Requirements
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@
"justinrainbow/json-schema": "~5.2"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"phpunit/phpunit": "^6.5",
"sami/sami": "dev-master",
"psr/log": "~1.0",
"satooshi/php-coveralls": "~1.0",
"jakub-onderka/php-parallel-lint": "0.*",
"friendsofphp/php-cs-fixer": "^1.0"
"friendsofphp/php-cs-fixer": "^2.9"
}
}
12 changes: 6 additions & 6 deletions doc/services/object-store/v1/objects.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Download an object
------------------

.. sample:: object_store/v1/objects/download.php
.. refdoc:: OpenStack/ObjectStore/v1/Models/Object.html#method_download
.. refdoc:: OpenStack/ObjectStore/v1/Models/StorageObject.html#method_download

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

.. sample:: object_store/v1/objects/copy.php
.. refdoc:: OpenStack/ObjectStore/v1/Models/Object.html#method_copy
.. refdoc:: OpenStack/ObjectStore/v1/Models/StorageObject.html#method_copy

Delete object
-------------

.. sample:: object_store/v1/objects/delete.php
.. refdoc:: OpenStack/ObjectStore/v1/Models/Object.html#method_delete
.. refdoc:: OpenStack/ObjectStore/v1/Models/StorageObject.html#method_delete

Get metadata
------------

.. sample:: object_store/v1/objects/get_metadata.php
.. refdoc:: OpenStack/ObjectStore/v1/Models/Object.html#method_getMetadata
.. refdoc:: OpenStack/ObjectStore/v1/Models/StorageObject.html#method_getMetadata

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

.. sample:: object_store/v1/objects/reset_metadata.php
.. refdoc:: OpenStack/ObjectStore/v1/Models/Object.html#method_resetMetadata
.. refdoc:: OpenStack/ObjectStore/v1/Models/StorageObject.html#method_resetMetadata

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

.. sample:: object_store/v1/objects/merge_metadata.php
.. refdoc:: OpenStack/ObjectStore/v1/Models/Object.html#method_mergeMetadata
.. refdoc:: OpenStack/ObjectStore/v1/Models/StorageObject.html#method_mergeMetadata

In order to merge a set of new metadata values with the existing metadata set, you can use this operation. Any existing
metadata items which are not specified in the new set will be preserved. For example, say an account has the following
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="./vendor/autoload.php" colors="true">
<phpunit bootstrap="./vendor/autoload.php" colors="true" strict="true">

<testsuites>
<testsuite name="OpenStack">
Expand Down
2 changes: 1 addition & 1 deletion samples/object_store/v1/objects/create.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
'content' => '{objectContent}',
];

/** @var \OpenStack\ObjectStore\v1\Models\Object $object */
/** @var \OpenStack\ObjectStore\v1\Models\StorageObject $object */
$object = $openstack->objectStoreV1()
->getContainer('{containerName}')
->createObject($options);
2 changes: 1 addition & 1 deletion samples/object_store/v1/objects/create_from_stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
'stream' => $stream,
];

/** @var \OpenStack\ObjectStore\v1\Models\Object $object */
/** @var \OpenStack\ObjectStore\v1\Models\StorageObject $object */
$object = $openstack->objectStoreV1()
->getContainer('{containerName}')
->createObject($options);
2 changes: 1 addition & 1 deletion samples/object_store/v1/objects/create_large_object.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
$options['segmentContainer'] = 'test_segments';


/** @var \OpenStack\ObjectStore\v1\Models\Object $object */
/** @var \OpenStack\ObjectStore\v1\Models\StorageObject $object */
$object = $openstack->objectStoreV1()
->getContainer('test')
->createLargeObject($options);
2 changes: 1 addition & 1 deletion samples/object_store/v1/objects/get.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'scope' => ['project' => ['id' => '{projectId}']]
]);

/** @var \OpenStack\ObjectStore\v1\Models\Object $object */
/** @var \OpenStack\ObjectStore\v1\Models\StorageObject $object */
$object = $openstack->objectStoreV1()
->getContainer('{containerName}')
->getObject('{objectName}');
2 changes: 1 addition & 1 deletion samples/object_store/v1/objects/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
->getContainer('{containerName}');

foreach ($container->listObjects() as $object) {
/** @var \OpenStack\ObjectStore\v1\Models\Object $object */
/** @var \OpenStack\ObjectStore\v1\Models\StorageObject $object */
}
9 changes: 7 additions & 2 deletions src/Common/Api/Parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ private function validateEnums($userValues)
{
if (!empty($this->enum) && $this->type == 'string' && !in_array($userValues, $this->enum)) {
throw new \Exception(sprintf(
'The only permitted values are %s. You provided %s', implode(', ', $this->enum), print_r($userValues, true)
'The only permitted values are %s. You provided %s',
implode(', ', $this->enum),
print_r($userValues, true)
));
}
}
Expand All @@ -217,7 +219,10 @@ private function validateType($userValues)
if (!$this->hasCorrectType($userValues)) {
throw new \Exception(sprintf(
'The key provided "%s" has the wrong value type. You provided %s (%s) but was expecting %s',
$this->name, print_r($userValues, true), gettype($userValues), $this->type
$this->name,
print_r($userValues, true),
gettype($userValues),
$this->type
));
}
}
Expand Down
14 changes: 10 additions & 4 deletions src/Common/Error/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,11 @@ public function httpError(RequestInterface $request, ResponseInterface $response
{
$message = $this->header('HTTP Error');

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

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

$message .= sprintf("%s was expected, but the following value was passed in:\n\n%s\n",
$expectedType, print_r($userValue, true));
$message .= sprintf(
"%s was expected, but the following value was passed in:\n\n%s\n",
$expectedType,
print_r($userValue, true)
);

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

Expand Down
3 changes: 2 additions & 1 deletion src/Common/JsonSchema/JsonPatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ protected function handleObject(\stdClass $srcStruct, \stdClass $desStruct, stri

protected function shouldPartiallyReplace(\stdClass $o1, \stdClass $o2): bool
{
return count(array_diff_key((array) $o1, (array) $o2)) < count($o1);
// NOTE: count(stdClass) always returns 1
return count(array_diff_key((array) $o1, (array) $o2)) < 1;
}

protected function arrayDiff(array $a1, array $a2): array
Expand Down
4 changes: 2 additions & 2 deletions src/Common/Resource/AbstractResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ abstract class AbstractResource implements ResourceInterface, Serializable
*
* @return AbstractResource
*/
public function populateFromResponse(ResponseInterface $response): self
public function populateFromResponse(ResponseInterface $response)
{
if (strpos($response->getHeaderLine('Content-Type'), 'application/json') === 0) {
$json = Utils::jsonDecode($response);
Expand All @@ -61,7 +61,7 @@ public function populateFromResponse(ResponseInterface $response): self
*
* @return mixed|void
*/
public function populateFromArray(array $array): self
public function populateFromArray(array $array)
{
$aliases = $this->getAliases();

Expand Down
3 changes: 2 additions & 1 deletion src/Common/Service/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ private function mergeOptions(array $serviceOptions): array

if (!isset($options['identityService']) || !($options['identityService'] instanceof IdentityService)) {
throw new \InvalidArgumentException(sprintf(
'"identityService" must be specified and implement %s', IdentityService::class
'"identityService" must be specified and implement %s',
IdentityService::class
));
}

Expand Down
3 changes: 2 additions & 1 deletion src/Common/Transport/JsonSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ private function serializeObjectValue($value)
} elseif (!($value instanceof \stdClass)) {
throw new \InvalidArgumentException(sprintf(
'When an object value is provided, it must either be \stdClass or implement the Serializable '
. 'interface, you provided %s', print_r($value, true)
. 'interface, you provided %s',
print_r($value, true)
));
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/Identity/v2/Models/Catalog.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ public function getServiceUrl(

throw new \RuntimeException(sprintf(
"Endpoint URL could not be found in the catalog for this service.\nName: %s\nType: %s\nRegion: %s\nURL type: %s",
$serviceName, $serviceType, $region, $urlType
$serviceName,
$serviceType,
$region,
$urlType
));
}
}
5 changes: 4 additions & 1 deletion src/Identity/v3/Models/Catalog.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ public function getServiceUrl(string $name, string $type, string $region, string

throw new \RuntimeException(sprintf(
"Endpoint URL could not be found in the catalog for this service.\nName: %s\nType: %s\nRegion: %s\nURL type: %s",
$name, $type, $region, $urlType
$name,
$type,
$region,
$urlType
));
}
}
9 changes: 7 additions & 2 deletions src/Identity/v3/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@ public function authenticate(array $options): array
return [$token, $baseUrl];
}

throw new \RuntimeException(sprintf("No service found with type [%s] name [%s] region [%s] interface [%s]",
$type, $name, $region, $interface));
throw new \RuntimeException(sprintf(
"No service found with type [%s] name [%s] region [%s] interface [%s]",
$type,
$name,
$region,
$interface
));
}

/**
Expand Down
22 changes: 11 additions & 11 deletions src/ObjectStore/v1/Models/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function populateFromResponse(ResponseInterface $response): self
public function listObjects(array $options = [], callable $mapFn = null): \Generator
{
$options = array_merge($options, ['name' => $this->name, 'format' => 'json']);
return $this->model(Object::class)->enumerate($this->api->getContainer(), $options, $mapFn);
return $this->model(StorageObject::class)->enumerate($this->api->getContainer(), $options, $mapFn);
}

/**
Expand Down Expand Up @@ -136,17 +136,17 @@ public function getMetadata(): array
}

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

/**
Expand Down Expand Up @@ -179,9 +179,9 @@ public function objectExists(string $name): bool
*
* @return Object
*/
public function createObject(array $data): Object
public function createObject(array $data): StorageObject
{
return $this->model(Object::class)->create($data + ['containerName' => $this->name]);
return $this->model(StorageObject::class)->create($data + ['containerName' => $this->name]);
}

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

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