Skip to content

Commit 75e84c7

Browse files
authored
Backport: Object Storage retrieval: containerName and name missing (#… (php-opencloud#211)
* Backport: Object Storage retrieval: containerName and name missing (php-opencloud#210) * Repopulate instance from input array * Added unit tests * Fixed authentication v2 bug * Updated unit tests # Conflicts: # tests/unit/ObjectStore/v1/Models/ContainerTest.php * Fixed psr2
1 parent 801eaa7 commit 75e84c7

File tree

14 files changed

+119
-27
lines changed

14 files changed

+119
-27
lines changed

.php_cs.dist

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

.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:

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@
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
}

samples/identity/v2/authentication.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,23 @@
55
use GuzzleHttp\Client;
66
use GuzzleHttp\HandlerStack;
77
use OpenStack\Common\Transport\Utils as TransportUtils;
8+
use OpenStack\Identity\v2\Service;
89
use OpenStack\OpenStack;
910

1011
$authUrl = 'https://keystone.example.com:5000/v2.0';
1112

13+
$httpClient = new Client([
14+
'base_uri' => TransportUtils::normalizeUrl($authUrl),
15+
'handler' => HandlerStack::create(),
16+
]);
17+
1218
$options = [
1319
'authUrl' => $authUrl,
1420
'region' => 'RegionOne',
1521
'username' => 'foo',
1622
'password' => 'bar',
1723
'tenantName' => 'baz',
18-
'identityService' => new Client(
19-
[
20-
'base_uri' => TransportUtils::normalizeUrl($authUrl),
21-
'handler' => HandlerStack::create(),
22-
]
23-
),
24+
'identityService' => Service::factory($httpClient),
2425
];
2526

2627
/** @var OpenStack $openstack */

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/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
}

0 commit comments

Comments
 (0)