Skip to content

Commit 7d21794

Browse files
committed
Merge pull request #39 from gaillard/master
Use php 5.4 array syntax.
2 parents fbe23f8 + 004abc4 commit 7d21794

File tree

8 files changed

+204
-241
lines changed

8 files changed

+204
-241
lines changed

build.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@
1111
require 'vendor/autoload.php';
1212

1313
$phpcsCLI = new PHP_CodeSniffer_CLI();
14-
$phpcsArguments = array(
15-
'standard' => array(__DIR__ . '/vendor/dominionenterprises/dws-coding-standard/DWS'),
16-
'files' => array('src', 'tests', 'build.php'),
14+
$phpcsArguments = [
15+
'standard' => [__DIR__ . '/vendor/dominionenterprises/dws-coding-standard/DWS'],
16+
'files' => ['src', 'tests', 'build.php'],
1717
'warningSeverity' => 0,
18-
);
18+
];
1919
$phpcsViolations = $phpcsCLI->process($phpcsArguments);
2020
if ($phpcsViolations > 0) {
2121
exit(1);
2222
}
2323

2424
$phpunitConfiguration = PHPUnit_Util_Configuration::getInstance(__DIR__ . '/phpunit.xml');
25-
$phpunitArguments = array('coverageHtml' => __DIR__ . '/coverage', 'configuration' => $phpunitConfiguration);
25+
$phpunitArguments = ['coverageHtml' => __DIR__ . '/coverage', 'configuration' => $phpunitConfiguration];
2626
$testRunner = new PHPUnit_TextUI_TestRunner();
2727
$result = $testRunner->doRun($phpunitConfiguration->getTestSuiteConfiguration(), $phpunitArguments);
2828
if (!$result->wasSuccessful()) {

src/Util.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111
final class Util
1212
{
13-
private static $_exceptionAliases = array('http' => '\DominionEnterprises\HttpException');
13+
private static $_exceptionAliases = ['http' => '\DominionEnterprises\HttpException'];
1414

1515
/**
1616
* Returns exception info in array.
@@ -19,34 +19,34 @@ final class Util
1919
*
2020
* @return array like:
2121
* <pre>
22-
* array(
22+
* [
2323
* 'type' => 'Exception',
2424
* 'message' => 'a message',
2525
* 'code' => 0,
2626
* 'file' => '/somePath',
2727
* 'line' => 434,
2828
* 'trace' => 'a stack trace',
29-
* )
29+
* ]
3030
* </pre>
3131
*/
3232
public static function getExceptionInfo(\Exception $e)
3333
{
34-
return array(
34+
return [
3535
'type' => get_class($e),
3636
'message' => $e->getMessage(),
3737
'code' => $e->getCode(),
3838
'file' => $e->getFile(),
3939
'line' => $e->getLine(),
4040
'trace' => $e->getTraceAsString(),
41-
);
41+
];
4242
}
4343

4444
/**
4545
* Ensures that $valueToEnsure is equal to $valueToCheck or it throws
4646
*
4747
* Can be used like: $result = ensure(true, is_string('boo'))
4848
* Or like: $result = ensure(true, is_string('boo'), 'the message')
49-
* Or like: $result = ensure(true, is_string('boo'), 'MyException', array('the message', 2))
49+
* Or like: $result = ensure(true, is_string('boo'), 'MyException', ['the message', 2])
5050
* Or like: $result = ensure(true, is_string('boo'), new MyException('the message', 2))
5151
*
5252
* @param mixed $valueToEnsure the value to throw on if $valueToCheck equals it
@@ -96,7 +96,7 @@ public static function ensure($valueToEnsure, $valueToCheck, $exception = null,
9696
*
9797
* Can be used like: $curl = ensureNot(false, curl_init('boo'))
9898
* Or like: $curl = ensureNot(false, curl_init('boo'), 'bad message')
99-
* Or like: $curl = ensureNot(false, curl_init('boo'), 'MyException', array('bad message', 2))
99+
* Or like: $curl = ensureNot(false, curl_init('boo'), 'MyException', ['bad message', 2])
100100
* Or like: $curl = ensureNot(false, curl_init('boo'), new MyException('bad message', 2))
101101
*
102102
* @param mixed $valueToThrowOn the value to throw on if $valueToCheck equals it
@@ -161,8 +161,8 @@ public static function raiseException($level, $message, $file = null, $line = nu
161161
/**
162162
* Throws an exception if specified variables are not of given types.
163163
*
164-
* @param array $typesToVariables like array('string' => array($var1, $var2), 'int' => array($var1, $var2))
165-
* or array('string' => $var1, 'integer' => array(1, $var2)). Supported types are the suffixes of the is_* functions such as string
164+
* @param array $typesToVariables like ['string' => [$var1, $var2], 'int' => [$var1, $var2]]
165+
* or ['string' => $var1, 'integer' => [1, $var2]]. Supported types are the suffixes of the is_* functions such as string
166166
* for is_string and int for is_int
167167
* @param bool $failOnWhitespace whether to fail strings if they are whitespace
168168
* @param bool $allowNulls whether to allow null values to pass through
@@ -187,7 +187,7 @@ public static function throwIfNotType(array $typesToVariables, $failOnWhitespace
187187
}
188188

189189
foreach ($typesToVariables as $type => $variablesOrVariable) {
190-
$variables = array($variablesOrVariable);
190+
$variables = [$variablesOrVariable];
191191
if (is_array($variablesOrVariable)) {
192192
$variables = $variablesOrVariable;
193193
}
@@ -292,7 +292,7 @@ public static function setExceptionAliases(array $aliases)
292292
* @throws \InvalidArgumentException if $method was not a string
293293
* @throws \InvalidArgumentException if $method was not static
294294
*/
295-
public static function callStatic($method, array $args = array())
295+
public static function callStatic($method, array $args = [])
296296
{
297297
if (!is_string($method)) {
298298
throw new \InvalidArgumentException('$method was not a string');

src/Util/Arrays.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static function get(array $array, $key, $default = null)
2525
}
2626

2727
/**
28-
* Simply returns an array value if the key isset, $default if it is not
28+
* Simply returns an array value if the key isset,4 $default if it is not
2929
*
3030
* @param array $array the array to be searched
3131
* @param string|integer $key the key to search for
@@ -107,15 +107,15 @@ public static function tryGet(array $array, $key, &$value)
107107
/**
108108
* Projects values of a key into an array.
109109
*
110-
* if $input = array(
111-
* array('key 1' => 'item 1 value 1', 'key 2' => 'item 1 value 2'),
112-
* array('key 1' => 'item 2 value 1', 'key 2' => 'item 2 value 2'),
113-
* array('key 1' => 'item 3 value 1'),
114-
* )
110+
* if $input = [
111+
* ['key 1' => 'item 1 value 1', 'key 2' => 'item 1 value 2'],
112+
* ['key 1' => 'item 2 value 1', 'key 2' => 'item 2 value 2'],
113+
* ['key 1' => 'item 3 value 1'],
114+
* ]
115115
* and $key = 'key 2'
116116
* and $strictKeyCheck = false
117117
*
118-
* then return array('item 1 value 2', 'item 2 value 2')
118+
* then return ['item 1 value 2', 'item 2 value 2']
119119
*
120120
* but if $strictKeyCheck = true then an InvalidArgumentException occurs since 'key 2' wasnt in item 3
121121
*
@@ -135,7 +135,7 @@ public static function project(array $input, $key, $strictKeyCheck = true)
135135
throw new \InvalidArgumentException('$strictKeyCheck was not a bool');
136136
}
137137

138-
$projection = array();
138+
$projection = [];
139139

140140
foreach ($input as $itemKey => $item) {
141141
if (!is_array($item)) {
@@ -164,7 +164,7 @@ public static function project(array $input, $key, $strictKeyCheck = true)
164164
*/
165165
public static function where(array $array, array $conditions)
166166
{
167-
$result = array();
167+
$result = [];
168168
foreach ($array as $item) {
169169
if (!is_array($item)) {
170170
throw new \InvalidArgumentException('a value in $array was not an array');
@@ -203,7 +203,7 @@ public static function where(array $array, array $conditions)
203203
* @throws \InvalidArgumentException if a value in $destination was not an array
204204
* @throws \Exception if $fieldName key already exists in a $destination array
205205
*/
206-
public static function embedInto(array $items, $fieldName, array $destination = array(), $overwrite = false)
206+
public static function embedInto(array $items, $fieldName, array $destination = [], $overwrite = false)
207207
{
208208
if (!is_string($fieldName)) {
209209
throw new \InvalidArgumentException('$fieldName was not a string');
@@ -225,7 +225,7 @@ public static function embedInto(array $items, $fieldName, array $destination =
225225

226226
$destination[$key][$fieldName] = $item;
227227
} else {
228-
$destination[$key] = array($fieldName => $item);
228+
$destination[$key] = [$fieldName => $item];
229229
}
230230
}
231231

@@ -272,7 +272,7 @@ public static function fillIfKeysExist(array $template, array $source)
272272
*/
273273
public static function extract(array $input, $keyIndex, $valueIndex, $duplicateBehavior = 'takeLast')
274274
{
275-
if (!in_array($duplicateBehavior, array('takeFirst', 'takeLast', 'throw'))) {
275+
if (!in_array($duplicateBehavior, ['takeFirst', 'takeLast', 'throw'])) {
276276
throw new \InvalidArgumentException("\$duplicateBehavior was not 'takeFirst', 'takeLast', or 'throw'");
277277
}
278278

@@ -284,7 +284,7 @@ public static function extract(array $input, $keyIndex, $valueIndex, $duplicateB
284284
throw new \InvalidArgumentException('$valueIndex was not a string or integer');
285285
}
286286

287-
$result = array();
287+
$result = [];
288288
foreach ($input as $index => $array) {
289289
if (!is_array($array)) {
290290
throw new \InvalidArgumentException('$arrays was not a multi-dimensional array');

src/Util/Http.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ final class Http
4949
*/
5050
public static function parseHeaders($rawHeaders)
5151
{
52-
Util::throwIfNotType(array('string' => $rawHeaders), true);
52+
Util::throwIfNotType(['string' => $rawHeaders], true);
5353

5454
set_error_handler('\DominionEnterprises\Util::raiseException');
5555
try {
56-
$headers = array();
56+
$headers = [];
5757
$rawHeaders = preg_replace("/\r\n[\t ]+/", ' ', trim($rawHeaders));
5858
$fields = explode("\r\n", $rawHeaders);
5959
foreach ($fields as $field) {
@@ -73,7 +73,7 @@ public static function parseHeaders($rawHeaders)
7373
}
7474

7575
if (!is_array($headers[$key])) {
76-
$headers[$key] = array($headers[$key]);
76+
$headers[$key] = [$headers[$key]];
7777
}
7878

7979
$headers[$key][] = $value;
@@ -101,11 +101,11 @@ public static function parseHeaders($rawHeaders)
101101
*
102102
* Example:
103103
* <code>
104-
* $parameters = array(
105-
* 'param1' => array('value', 'another value'),
104+
* $parameters = [
105+
* 'param1' => ['value', 'another value'],
106106
* 'param2' => 'a value',
107107
* 'param3' => false,
108-
* );
108+
* ];
109109
*
110110
* $queryString = \DominionEnterprises\HttpUtil::buildQueryString($parameters);
111111
*
@@ -123,7 +123,7 @@ public static function parseHeaders($rawHeaders)
123123
*/
124124
public static function buildQueryString(array $parameters)
125125
{
126-
$queryStrings = array();
126+
$queryStrings = [];
127127
foreach ($parameters as $parameterName => $parameterValue) {
128128
$parameterName = urlencode($parameterName);
129129

@@ -156,20 +156,20 @@ public static function buildQueryString(array $parameters)
156156
* @throws \InvalidArgumentException if $url was not a string
157157
* @throws \Exception if more than one value in a $collapsedParams param
158158
*/
159-
public static function getQueryParams($url, array $collapsedParams = array())
159+
public static function getQueryParams($url, array $collapsedParams = [])
160160
{
161161
if (!is_string($url)) {
162162
throw new \InvalidArgumentException('$url was not a string');
163163
}
164164

165165
$queryString = parse_url($url, PHP_URL_QUERY);
166166
if (!is_string($queryString)) {
167-
return array();
167+
return [];
168168
}
169169

170170
$collapsedParams = array_flip($collapsedParams);
171171

172-
$result = array();
172+
$result = [];
173173
foreach (explode('&', $queryString) as $arg) {
174174
$name = $arg;
175175
$value = '';
@@ -188,7 +188,7 @@ public static function getQueryParams($url, array $collapsedParams = array())
188188
continue;
189189
}
190190

191-
$result[$name] = array();
191+
$result[$name] = [];
192192
}
193193

194194
if ($collapsed) {
@@ -212,18 +212,18 @@ public static function getQueryParams($url, array $collapsedParams = array())
212212
* @throws \InvalidArgumentException if $url was not a string
213213
* @throws \Exception if a parameter is given as array but not included in the expected array argument
214214
*/
215-
public static function getQueryParamsCollapsed($url, array $expectedArrayParams = array())
215+
public static function getQueryParamsCollapsed($url, array $expectedArrayParams = [])
216216
{
217217
if (!is_string($url)) {
218218
throw new \InvalidArgumentException('$url was not a string');
219219
}
220220

221221
$queryString = parse_url($url, PHP_URL_QUERY);
222222
if (!is_string($queryString)) {
223-
return array();
223+
return [];
224224
}
225225

226-
$result = array();
226+
$result = [];
227227
foreach (explode('&', $queryString) as $arg) {
228228
$name = $arg;
229229
$value = '';
@@ -245,7 +245,7 @@ public static function getQueryParamsCollapsed($url, array $expectedArrayParams
245245
}
246246

247247
if (!is_array($result[$name])) {
248-
$result[$name] = array($result[$name]);
248+
$result[$name] = [$result[$name]];
249249
}
250250

251251
$result[$name][] = $value;

0 commit comments

Comments
 (0)