Skip to content

Commit

Permalink
Auto-fix CS
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Jun 28, 2020
1 parent 5e6b4ae commit f502ae4
Show file tree
Hide file tree
Showing 24 changed files with 81 additions and 43 deletions.
2 changes: 2 additions & 0 deletions src/Auth/AclAdapter/IniAclAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function getAcl(array $availableRoles, array $config): array {
$role = mb_substr($role, 1);
if (!array_key_exists($role, $availableRoles)) {
unset($roles[$roleId]);

continue;
}

Expand All @@ -52,6 +53,7 @@ public function getAcl(array $availableRoles, array $config): array {
// Prevent undefined roles appearing in the iniMap
if (!array_key_exists($role, $availableRoles) && $role !== '*') {
unset($roles[$roleId]);

continue;
}
if ($role === '*') {
Expand Down
18 changes: 11 additions & 7 deletions src/Auth/AclTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ trait AclTrait {
* Finds the authorization adapter to use for this request.
*
* @param string $adapter Acl adapter to load.
* @return \TinyAuth\Auth\AclAdapter\AclAdapterInterface
* @throws \Cake\Core\Exception\Exception
* @throws \InvalidArgumentException
* @return \TinyAuth\Auth\AclAdapter\AclAdapterInterface
*/
protected function _loadAclAdapter($adapter) {
if ($this->_aclAdapter !== null) {
Expand Down Expand Up @@ -82,8 +82,8 @@ protected function _loadAclAdapter($adapter) {
*
* @param array $user User data
* @param array $params Request params
* @return bool Success
* @throws \Cake\Core\Exception\Exception
* @return bool Success
*/
protected function _checkUser(array $user, array $params) {
if ($this->getConfig('includeAuthentication') && $this->_isPublic($params)) {
Expand Down Expand Up @@ -341,8 +341,8 @@ protected function _isPublic(array $params) {
* Hack to get the auth data here for hasAccess().
* We re-use the cached data for performance reasons.
*
* @return array
* @throws \Cake\Core\Exception\Exception
* @return array
*/
protected function _getAuth() {
if ($this->auth) {
Expand Down Expand Up @@ -426,6 +426,7 @@ protected function _constructIniKey($params) {
if (!empty($params['plugin'])) {
$res = $params['plugin'] . ".$res";
}

return $res;
}

Expand All @@ -435,8 +436,8 @@ protected function _constructIniKey($params) {
* Will look for a roles array in
* Configure first, tries database roles table next.
*
* @return int[] List with all available roles
* @throws \Cake\Core\Exception\Exception
* @return int[] List with all available roles
*/
protected function _getAvailableRoles() {
if ($this->_roles !== null) {
Expand Down Expand Up @@ -496,8 +497,8 @@ protected function _getAvailableRoles() {
* in multi-role mode)
*
* @param array $user The user to get the roles for
* @return int[] List with all role ids belonging to the user
* @throws \Cake\Core\Exception\Exception
* @return int[] List with all role ids belonging to the user
*/
protected function _getUserRoles($user) {
// Single-role from session
Expand All @@ -513,6 +514,7 @@ protected function _getUserRoles($user) {
if (!isset($user[$this->getConfig('roleColumn')])) {
return [];
}

return $this->_mapped([$user[$this->getConfig('roleColumn')]]);
}

Expand All @@ -522,6 +524,7 @@ protected function _getUserRoles($user) {
if (isset($userRoles[0]['id'])) {
$userRoles = Hash::extract($userRoles, '{n}.id');
}

return $this->_mapped((array)$userRoles);
}

Expand All @@ -532,6 +535,7 @@ protected function _getUserRoles($user) {
if (isset($userRoles[0][$this->getConfig('roleColumn')])) {
$userRoles = Hash::extract($userRoles, '{n}.' . $this->getConfig('roleColumn'));
}

return $this->_mapped((array)$userRoles);
}

Expand All @@ -550,8 +554,8 @@ protected function _getUserRoles($user) {
protected function _pivotTableName() {
$pivotTableName = $this->getConfig('pivotTable');
if (!$pivotTableName) {
list(, $rolesTableName) = pluginSplit($this->getConfig('rolesTable'));
list(, $usersTableName) = pluginSplit($this->getConfig('usersTable'));
[, $rolesTableName] = pluginSplit($this->getConfig('rolesTable'));
[, $usersTableName] = pluginSplit($this->getConfig('usersTable'));
$tables = [
$usersTableName,
$rolesTableName,
Expand Down
2 changes: 2 additions & 0 deletions src/Auth/AllowAdapter/IniAllowAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function getAllow(array $config): array {
$action = trim($action);
if ($action === '') {
unset($actions[$k]);

continue;
}
$actions[$k] = $action;
Expand All @@ -39,6 +40,7 @@ public function getAllow(array $config): array {
$denied = mb_substr($action, 0, 1) === '!';
if ($denied) {
$auth[$key]['deny'][] = mb_substr($action, 1);

continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Auth/AllowTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ protected function _getAllow($path = null) {
* Finds the authentication adapter to use for this request.
*
* @param string $adapter Acl adapter to load.
* @return \TinyAuth\Auth\AllowAdapter\AllowAdapterInterface
* @throws \Cake\Core\Exception\Exception
* @throws \InvalidArgumentException
* @return \TinyAuth\Auth\AllowAdapter\AllowAdapterInterface
*/
protected function _loadAllowAdapter($adapter) {
if ($this->_allowAdapter !== null) {
Expand Down
4 changes: 4 additions & 0 deletions src/Auth/AuthUserTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function id() {
*/
public function isMe($userId) {
$field = $this->getConfig('idColumn');

return $userId && (string)$userId === (string)$this->user($field);
}

Expand All @@ -73,6 +74,7 @@ public function user($key = null) {
if ($key === null) {
return $user;
}

return Hash::get($user, $key);
}

Expand Down Expand Up @@ -116,6 +118,7 @@ public function hasRole($expectedRole, $providedRoles = null) {
if (array_key_exists($expectedRole, $roles) || in_array($expectedRole, $roles)) {
return true;
}

return false;
}

Expand Down Expand Up @@ -159,6 +162,7 @@ public function hasRoles($expectedRoles, $oneRoleIsEnough = true, $providedRoles
if ($count === count($expectedRoles)) {
return true;
}

return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Component/AuthComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace TinyAuth\Controller\Component;

use Cake\Controller\ComponentRegistry;
use Cake\Controller\Component\AuthComponent as CakeAuthComponent;
use Cake\Controller\ComponentRegistry;
use RuntimeException;
use TinyAuth\Auth\AclTrait;
use TinyAuth\Auth\AllowTrait;
Expand Down
1 change: 1 addition & 0 deletions src/Middleware/RequestAuthorizationMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
$can = $service->can($identity, $this->getConfig('method'), $request);
if (!$can) {
$result = new Result($can, 'Can not ' . $this->getConfig('method') . ' request');

throw new ForbiddenException($result);
}

Expand Down
8 changes: 5 additions & 3 deletions src/Panel/AuthPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class AuthPanel extends DebugPanel {
use AllowTrait;
use InstanceConfigTrait;

const ICON_RESTRICTED = "\u{1f512}";
const ICON_PUBLIC = "\u{1f513}";
public const ICON_RESTRICTED = "\u{1f512}";
public const ICON_PUBLIC = "\u{1f513}";

/**
* Defines which plugin this panel is from so the element can be located.
Expand Down Expand Up @@ -57,7 +57,7 @@ public function __construct() {
* @return void
*/
public function shutdown(EventInterface $event) {
/** @var \Cake\Controller\Controller $controller */
/** @var \Cake\Controller\Controller $controller */
$controller = $event->getSubject();
$request = $controller->getRequest();

Expand Down Expand Up @@ -102,6 +102,7 @@ public function data() {
$data = [
'isPublic' => $this->isPublic,
];

return $this->_data + $data;
}

Expand Down Expand Up @@ -143,6 +144,7 @@ protected function _injectRole(array $user, $role, $id) {
$pivotTableName = $this->_pivotTableName();
if (isset($user[$pivotTableName])) {
$user[$pivotTableName] = [$role => $id];

return $user;
}

Expand Down
1 change: 1 addition & 0 deletions src/Sync/Syncer.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function syncAcl(Arguments $args, ConsoleIo $io) {
$io->info($string);
$io->info('=== ' . $config['aclFile'] . ' end ===');
}

return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Utility/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class Cache {

use StaticConfigTrait;

const KEY_ALLOW = 'allow';
const KEY_ACL = 'acl';
public const KEY_ALLOW = 'allow';
public const KEY_ACL = 'acl';

/**
* @var array
Expand Down
6 changes: 4 additions & 2 deletions src/Utility/Utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function deconstructIniKey($key) {
];

if (strpos($key, '.') !== false) {
list($res['plugin'], $key) = explode('.', $key);
[$res['plugin'], $key] = explode('.', $key);
}
$lastSlashPos = strrpos($key, '/');
if ($lastSlashPos !== false) {
Expand All @@ -29,6 +29,7 @@ public static function deconstructIniKey($key) {
$key = substr($key, $lastSlashPos + 1);
}
$res['controller'] = $key;

return $res;
}

Expand Down Expand Up @@ -56,8 +57,8 @@ public static function parseFiles($paths, $file) {
* Returns the ini file as an array.
*
* @param string $ini Full path to the ini file
* @return array List
* @throws \Cake\Core\Exception\Exception
* @return array List
*/
public static function parseFile($ini) {
if (!file_exists($ini)) {
Expand All @@ -77,6 +78,7 @@ public static function parseFile($ini) {
if (!is_array($iniArray)) {
throw new Exception(sprintf('Invalid TinyAuth config file (%s)', $ini));
}

return $iniArray;
}

Expand Down
4 changes: 2 additions & 2 deletions src/View/Helper/AuthUserHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public function __construct(View $View, array $config = []) {
* `includeAuthentication` config and make sure all actions are whitelisted in auth allow INI file.
*
* @param array $url
* @return bool
* @throws \Cake\Core\Exception\Exception
* @return bool
*/
public function hasAccess(array $url) {
if (isset($url['_name'])) {
Expand Down Expand Up @@ -138,8 +138,8 @@ protected function _default($title, array $options) {
}

/**
* @return array
* @throws \Cake\Core\Exception\Exception
* @return array
*/
protected function _getUser() {
$authUser = $this->_View->get('_authUser');
Expand Down
21 changes: 14 additions & 7 deletions tests/TestCase/Controller/Component/AuthComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public function setUp(): void {
* @return void
*/
public function testValid() {
$request = new ServerRequest(['params' => [
$request = new ServerRequest([
'params' => [
'controller' => 'Users',
'action' => 'view',
'plugin' => null,
Expand All @@ -63,7 +64,8 @@ public function testValid() {
* @return void
*/
public function testValidAnyAction() {
$request = new ServerRequest(['params' => [
$request = new ServerRequest([
'params' => [
'plugin' => 'Extras',
'controller' => 'Offers',
'action' => 'index',
Expand All @@ -87,7 +89,8 @@ public function testValidAnyAction() {
* @return void
*/
public function testDeniedActionInController() {
$request = new ServerRequest(['params' => [
$request = new ServerRequest([
'params' => [
'plugin' => 'Extras',
'controller' => 'Offers',
'action' => 'denied',
Expand All @@ -113,7 +116,8 @@ public function testDeniedActionInController() {
* @return void
*/
public function testDeniedAction() {
$request = new ServerRequest(['params' => [
$request = new ServerRequest([
'params' => [
'plugin' => 'Extras',
'controller' => 'Offers',
'action' => 'superPrivate',
Expand All @@ -139,7 +143,8 @@ public function testDeniedAction() {
* @return void
*/
public function testValidActionNestedPrefix() {
$request = new ServerRequest(['params' => [
$request = new ServerRequest([
'params' => [
'plugin' => null,
'prefix' => 'Admin/MyPrefix',
'controller' => 'MyTest',
Expand All @@ -162,7 +167,8 @@ public function testValidActionNestedPrefix() {
* @return void
*/
public function testDeniedActionNestedPrefix() {
$request = new ServerRequest(['params' => [
$request = new ServerRequest([
'params' => [
'plugin' => null,
'prefix' => 'admin/my_prefix',
'controller' => 'MyTest',
Expand All @@ -187,7 +193,8 @@ public function testDeniedActionNestedPrefix() {
* @return void
*/
public function testInvalid() {
$request = new ServerRequest(['params' => [
$request = new ServerRequest([
'params' => [
'controller' => 'FooBar',
'action' => 'index',
'plugin' => null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace TinyAuth\Test\TestCase\Controller\Component;

use Cake\Controller\ComponentRegistry;
use Cake\Controller\Component\AuthComponent;
use Cake\Controller\ComponentRegistry;
use Cake\Controller\Controller;
use Cake\Core\Configure;
use Cake\Event\Event;
Expand Down
Loading

0 comments on commit f502ae4

Please sign in to comment.