Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
[cs] Use PHP short array syntax
Browse files Browse the repository at this point in the history
Since PHP 5.4 arrays can be defined with brackets ([]) instead the  function
  • Loading branch information
Maks3w committed Jun 5, 2015
1 parent 5a0aebc commit fa4c8a9
Show file tree
Hide file tree
Showing 24 changed files with 149 additions and 148 deletions.
1 change: 1 addition & 0 deletions .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ $config->fixers(
'object_operator',
'php_closing_tag',
'remove_lines_between_uses',
'short_array_syntax',
'short_tag',
'standardize_not_equal',
'trailing_spaces',
Expand Down
6 changes: 3 additions & 3 deletions src/Adapter/Callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ public function authenticate()
try {
$identity = call_user_func($callback, $this->getIdentity(), $this->getCredential());
} catch (Exception $e) {
return new Result(Result::FAILURE_UNCATEGORIZED, null, array($e->getMessage()));
return new Result(Result::FAILURE_UNCATEGORIZED, null, [$e->getMessage()]);
}

if (! $identity) {
return new Result(Result::FAILURE, null, array('Authentication failure'));
return new Result(Result::FAILURE, null, ['Authentication failure']);
}

return new Result(Result::SUCCESS, $identity, array('Authentication success'));
return new Result(Result::SUCCESS, $identity, ['Authentication success']);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Adapter/DbTable/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,11 @@ protected function authenticateSetup()
throw new Exception\RuntimeException($exception);
}

$this->authenticateResultInfo = array(
$this->authenticateResultInfo = [
'code' => AuthenticationResult::FAILURE,
'identity' => $this->identity,
'messages' => array()
);
'messages' => []
];

return true;
}
Expand All @@ -317,7 +317,7 @@ protected function authenticateQuerySelect(Sql\Select $dbSelect)
$statement = $sql->prepareStatementForSqlObject($dbSelect);
try {
$result = $statement->execute();
$resultIdentities = array();
$resultIdentities = [];
// iterate result, most cross platform way
foreach ($result as $row) {
// ZF-6428 - account for db engines that by default return uppercase column names
Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/DbTable/CallbackCheckAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected function authenticateCreateSelect()
// get select
$dbSelect = clone $this->getDbSelect();
$dbSelect->from($this->tableName)
->columns(array(Sql\Select::SQL_STAR))
->columns([Sql\Select::SQL_STAR])
->where(new SqlOp($this->identityColumn, '=', $this->identity));

return $dbSelect;
Expand Down
6 changes: 3 additions & 3 deletions src/Adapter/DbTable/CredentialTreatmentAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ protected function authenticateCreateSelect()

$credentialExpression = new SqlExpr(
'(CASE WHEN ?' . ' = ' . $this->credentialTreatment . ' THEN 1 ELSE 0 END) AS ?',
array($this->credentialColumn, $this->credential, 'zend_auth_credential_match'),
array(SqlExpr::TYPE_IDENTIFIER, SqlExpr::TYPE_VALUE, SqlExpr::TYPE_IDENTIFIER)
[$this->credentialColumn, $this->credential, 'zend_auth_credential_match'],
[SqlExpr::TYPE_IDENTIFIER, SqlExpr::TYPE_VALUE, SqlExpr::TYPE_IDENTIFIER]
);

// get select
$dbSelect = clone $this->getDbSelect();
$dbSelect->from($this->tableName)
->columns(array('*', $credentialExpression))
->columns(['*', $credentialExpression])
->where(new SqlOp($this->identityColumn, '=', $this->identity));

return $dbSelect;
Expand Down
12 changes: 6 additions & 6 deletions src/Adapter/Digest.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function setPassword($password)
*/
public function authenticate()
{
$optionsRequired = array('filename', 'realm', 'identity', 'credential');
$optionsRequired = ['filename', 'realm', 'identity', 'credential'];
foreach ($optionsRequired as $optionRequired) {
if (null === $this->$optionRequired) {
throw new Exception\RuntimeException("Option '$optionRequired' must be set before authentication");
Expand All @@ -164,14 +164,14 @@ public function authenticate()
$id = "$this->identity:$this->realm";
$idLength = strlen($id);

$result = array(
$result = [
'code' => AuthenticationResult::FAILURE,
'identity' => array(
'identity' => [
'realm' => $this->realm,
'username' => $this->identity,
),
'messages' => array()
);
],
'messages' => []
];

while (($line = fgets($fileHandle)) !== false) {
$line = trim($line);
Expand Down
24 changes: 12 additions & 12 deletions src/Adapter/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Http implements AdapterInterface
*
* @var array
*/
protected $supportedSchemes = array('basic', 'digest');
protected $supportedSchemes = ['basic', 'digest'];

/**
* List of schemes this class will accept from the client
Expand Down Expand Up @@ -102,7 +102,7 @@ class Http implements AdapterInterface
*
* @var array
*/
protected $supportedAlgos = array('MD5');
protected $supportedAlgos = ['MD5'];

/**
* The actual algorithm to use. Defaults to MD5
Expand All @@ -117,7 +117,7 @@ class Http implements AdapterInterface
*
* @var array
*/
protected $supportedQops = array('auth');
protected $supportedQops = ['auth'];

/**
* Whether or not to do Proxy Authentication instead of origin server
Expand Down Expand Up @@ -346,8 +346,8 @@ public function authenticate()
$this->response->setStatusCode(400);
return new Authentication\Result(
Authentication\Result::FAILURE_UNCATEGORIZED,
array(),
array('Client requested an incorrect or unsupported authentication scheme')
[],
['Client requested an incorrect or unsupported authentication scheme']
);
}

Expand Down Expand Up @@ -418,8 +418,8 @@ public function challengeClient()
}
return new Authentication\Result(
Authentication\Result::FAILURE_CREDENTIAL_INVALID,
array(),
array('Invalid or absent credentials; challenging client')
[],
['Invalid or absent credentials; challenging client']
);
}

Expand Down Expand Up @@ -503,7 +503,7 @@ protected function _basicAuth($header)
&& !is_array($result)
&& CryptUtils::compareStrings($result, $creds[1])
) {
$identity = array('username' => $creds[0], 'realm' => $this->realm);
$identity = ['username' => $creds[0], 'realm' => $this->realm];
return new Authentication\Result(Authentication\Result::SUCCESS, $identity);
} elseif (is_array($result)) {
return new Authentication\Result(Authentication\Result::SUCCESS, $result);
Expand Down Expand Up @@ -533,8 +533,8 @@ protected function _digestAuth($header)
$this->response->setStatusCode(400);
return new Authentication\Result(
Authentication\Result::FAILURE_UNCATEGORIZED,
array(),
array('Invalid Authorization header format')
[],
['Invalid Authorization header format']
);
}

Expand Down Expand Up @@ -594,7 +594,7 @@ protected function _digestAuth($header)
// If our digest matches the client's let them in, otherwise return
// a 401 code and exit to prevent access to the protected resource.
if (CryptUtils::compareStrings($digest, $data['response'])) {
$identity = array('username' => $data['username'], 'realm' => $data['realm']);
$identity = ['username' => $data['username'], 'realm' => $data['realm']];
return new Authentication\Result(Authentication\Result::SUCCESS, $identity);
}

Expand Down Expand Up @@ -658,7 +658,7 @@ protected function _calcOpaque()
protected function _parseDigestAuth($header)
{
$temp = null;
$data = array();
$data = [];

// See ZF-1052. Detect invalid usernames instead of just returning a
// 400 code.
Expand Down
4 changes: 2 additions & 2 deletions src/Adapter/Http/ApacheResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function resolve($username, $realm, $password = null)
fclose($fp);

if (!isset($matchedHash)) {
return new AuthResult(AuthResult::FAILURE_IDENTITY_NOT_FOUND, null, array('Username not found in provided htpasswd file'));
return new AuthResult(AuthResult::FAILURE_IDENTITY_NOT_FOUND, null, ['Username not found in provided htpasswd file']);
}

// Plaintext password
Expand All @@ -166,6 +166,6 @@ public function resolve($username, $realm, $password = null)
return new AuthResult(AuthResult::SUCCESS, $username);
}

return new AuthResult(AuthResult::FAILURE_CREDENTIAL_INVALID, null, array('Passwords did not match.'));
return new AuthResult(AuthResult::FAILURE_CREDENTIAL_INVALID, null, ['Passwords did not match.']);
}
}
20 changes: 10 additions & 10 deletions src/Adapter/Ldap.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Ldap extends AbstractAdapter
* @param string $identity The username of the account being authenticated
* @param string $credential The password of the account being authenticated
*/
public function __construct(array $options = array(), $identity = null, $credential = null)
public function __construct(array $options = [], $identity = null, $credential = null)
{
$this->setOptions($options);
if ($identity !== null) {
Expand Down Expand Up @@ -74,7 +74,7 @@ public function getOptions()
*/
public function setOptions($options)
{
$this->options = is_array($options) ? $options : array();
$this->options = is_array($options) ? $options : [];
if (array_key_exists('identity', $this->options)) {
$this->options['username'] = $this->options['identity'];
}
Expand Down Expand Up @@ -152,7 +152,7 @@ public function setLdap(ZendLdap\Ldap $ldap)
{
$this->ldap = $ldap;

$this->setOptions(array($ldap->getOptions()));
$this->setOptions([$ldap->getOptions()]);

return $this;
}
Expand Down Expand Up @@ -182,7 +182,7 @@ protected function getAuthorityName()
*/
public function authenticate()
{
$messages = array();
$messages = [];
$messages[0] = ''; // reserved
$messages[1] = ''; // reserved

Expand All @@ -207,7 +207,7 @@ public function authenticate()

$code = AuthenticationResult::FAILURE;
$messages[0] = "Authority not found: $username";
$failedAuthorities = array();
$failedAuthorities = [];

/* Iterate through each server and try to authenticate the supplied
* credentials against it.
Expand Down Expand Up @@ -326,15 +326,15 @@ public function authenticate()
*/
protected function prepareOptions(ZendLdap\Ldap $ldap, array $options)
{
$adapterOptions = array(
$adapterOptions = [
'group' => null,
'groupDn' => $ldap->getBaseDn(),
'groupScope' => ZendLdap\Ldap::SEARCH_SCOPE_SUB,
'groupAttr' => 'cn',
'groupFilter' => 'objectClass=groupOfUniqueNames',
'memberAttr' => 'uniqueMember',
'memberIsDn' => true
);
];
foreach ($adapterOptions as $key => $value) {
if (array_key_exists($key, $options)) {
$value = $options[$key];
Expand All @@ -344,11 +344,11 @@ protected function prepareOptions(ZendLdap\Ldap $ldap, array $options)
$value = (int) $value;
if (in_array(
$value,
array(
[
ZendLdap\Ldap::SEARCH_SCOPE_BASE,
ZendLdap\Ldap::SEARCH_SCOPE_ONE,
ZendLdap\Ldap::SEARCH_SCOPE_SUB,
),
],
true
)) {
$adapterOptions[$key] = $value;
Expand Down Expand Up @@ -416,7 +416,7 @@ protected function checkGroupMembership(ZendLdap\Ldap $ldap, $canonicalName, $dn
* @param array $omitAttribs
* @return stdClass|bool
*/
public function getAccountObject(array $returnAttribs = array(), array $omitAttribs = array())
public function getAccountObject(array $returnAttribs = [], array $omitAttribs = [])
{
if (!$this->authenticatedDn) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Result
* @param mixed $identity
* @param array $messages
*/
public function __construct($code, $identity, array $messages = array())
public function __construct($code, $identity, array $messages = [])
{
$this->code = (int) $code;
$this->identity = $identity;
Expand Down
2 changes: 1 addition & 1 deletion src/Storage/Chain.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function add(StorageInterface $storage, $priority = 1)
*/
public function isEmpty()
{
$storageWithHigherPriority = array();
$storageWithHigherPriority = [];

// Loop invariant: $storageWithHigherPriority contains all storage with higher priorty
// than the current one.
Expand Down
4 changes: 2 additions & 2 deletions src/Validator/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ class Authentication extends AbstractValidator
* Error Messages
* @var array
*/
protected $messageTemplates = array(
protected $messageTemplates = [
self::IDENTITY_NOT_FOUND => 'Invalid identity',
self::IDENTITY_AMBIGUOUS => 'Identity is ambiguous',
self::CREDENTIAL_INVALID => 'Invalid password',
self::UNCATEGORIZED => 'Authentication failed',
self::GENERAL => 'Authentication failed',
);
];

/**
* Authentication Adapter
Expand Down
8 changes: 4 additions & 4 deletions test/Adapter/CallbackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function testAuthenticateResultIfCallbackThrows()
$result = $adapter->authenticate();
$this->assertFalse($result->isValid());
$this->assertEquals(Result::FAILURE_UNCATEGORIZED, $result->getCode());
$this->assertEquals(array($exception->getMessage()), $result->getMessages());
$this->assertEquals([$exception->getMessage()], $result->getMessages());
}

/**
Expand All @@ -128,7 +128,7 @@ public function testAuthenticateResultIfCallbackReturnsFalsy()
{
$that = $this;
$adapter = $this->adapter;
$falsyValues = array(false, null, '', '0', array(), 0, 0.0);
$falsyValues = [false, null, '', '0', [], 0, 0.0];
array_map(function ($falsy) use ($that, $adapter) {
$callback = function () use ($falsy) {
return $falsy;
Expand All @@ -137,7 +137,7 @@ public function testAuthenticateResultIfCallbackReturnsFalsy()
$result = $adapter->authenticate();
$that->assertFalse($result->isValid());
$that->assertEquals(Result::FAILURE, $result->getCode());
$that->assertEquals(array('Authentication failure'), $result->getMessages());
$that->assertEquals(['Authentication failure'], $result->getMessages());
}, $falsyValues);
}

Expand All @@ -155,6 +155,6 @@ public function testAuthenticateResultIfCallbackReturnsIdentity()
$this->assertTrue($result->isValid());
$this->assertEquals(Result::SUCCESS, $result->getCode());
$this->assertEquals('identity', $result->getIdentity());
$this->assertEquals(array('Authentication success'), $result->getMessages());
$this->assertEquals(['Authentication success'], $result->getMessages());
}
}
8 changes: 4 additions & 4 deletions test/Adapter/DbTable/CallbackCheckAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function testGetSpecificResultRow()
$this->_adapter->setIdentity('my_username');
$this->_adapter->setCredential('my_password');
$this->_adapter->authenticate();
$resultRow = $this->_adapter->getResultRowObject(array('username', 'real_name'));
$resultRow = $this->_adapter->getResultRowObject(['username', 'real_name']);
$this->assertEquals('O:8:"stdClass":2:{s:8:"username";s:11:"my_username";s:9:"real_name";s:12:"My Real Name";}',
serialize($resultRow));
}
Expand Down Expand Up @@ -344,10 +344,10 @@ public function testEqualUsernamesDifferentPasswordShouldAuthenticateWhenFlagIsS
}


protected function _setupDbAdapter($optionalParams = array())
protected function _setupDbAdapter($optionalParams = [])
{
$params = array('driver' => 'pdo_sqlite',
'dbname' => getenv('TESTS_ZEND_AUTH_ADAPTER_DBTABLE_PDO_SQLITE_DATABASE'));
$params = ['driver' => 'pdo_sqlite',
'dbname' => getenv('TESTS_ZEND_AUTH_ADAPTER_DBTABLE_PDO_SQLITE_DATABASE')];

if (!empty($optionalParams)) {
$params['options'] = $optionalParams;
Expand Down
Loading

0 comments on commit fa4c8a9

Please sign in to comment.