Skip to content

Commit

Permalink
Code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
rotimi committed May 9, 2024
1 parent 90e77ad commit 18e53b6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"phpunit/phpunit": "^9.5.20",
"php-coveralls/php-coveralls": "^2.5.2",
"vimeo/psalm": "^5.15",
"rector/rector": "^0.19.0",
"rector/rector": "^1.0.0",
"php-mock/php-mock": "^2.4"
},
"autoload": {
Expand Down
21 changes: 15 additions & 6 deletions src/controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public function __construct(

$uri_path_parts = explode('/', $uri_path);

if( count($uri_path_parts) >= 1 && ($this->controller_name_from_uri === '') ) {
if( $this->controller_name_from_uri === '' ) {

$this->controller_name_from_uri = $uri_path_parts[0];
}
Expand All @@ -255,6 +255,9 @@ public function __construct(
$this->updateSelectedLanguage();
}

/**
* @psalm-suppress InvalidScalarArgument
*/
public function updateSelectedLanguage() : void {

$query_params = $this->request->getQueryParams();
Expand Down Expand Up @@ -284,7 +287,13 @@ public function updateSelectedLanguage() : void {
*/
$_SESSION[self::SESSN_PARAM_CURRENT_LOCALE_LANG] =
$query_params[self::GET_QUERY_PARAM_SELECTED_LANG];
} // else { // default lang is already preconfigured in dependencies file }
} elseif (
session_status() === PHP_SESSION_ACTIVE
&& array_key_exists(self::SESSN_PARAM_CURRENT_LOCALE_LANG, $_SESSION)
) {
$this->vespula_locale->setCode($_SESSION[self::SESSN_PARAM_CURRENT_LOCALE_LANG]);
}
// else { // default lang is already preconfigured in dependencies file }
}

/**
Expand Down Expand Up @@ -605,21 +614,21 @@ public function actionLogin() {
$auth = $this->vespula_auth; //get the auth object

/** @psalm-suppress MixedAssignment */
$username = sMVC_GetSuperGlobal('post', 'username');
$username = sMVC_GetSuperGlobal('post', 'username', '');

/** @psalm-suppress MixedAssignment */
$password = sMVC_GetSuperGlobal('post', 'password');
$password = sMVC_GetSuperGlobal('post', 'password', '');
$error_msg = '';

if( empty($username) ) {
if( $username === '' ) {
/**
* @psalm-suppress MixedOperand
*/
$error_msg .= $this->vespula_locale
->gettext('base_controller_action_login_empty_username_msg');
}

if( empty($password) ) {
if( $password === '' ) {

$error_msg .= (($error_msg === ''))? '' : '<br>';
/**
Expand Down
10 changes: 5 additions & 5 deletions tests/BaseControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1567,6 +1567,11 @@ public function testThat_actionLoginStatus_WorksAsExpected() {
'Unknown' => 'Unknown session status.',
];

if(!defined('SMVC_APP_AUTO_PREPEND_ACTION_TO_ACTION_METHOD_NAMES')){

define('SMVC_APP_AUTO_PREPEND_ACTION_TO_ACTION_METHOD_NAMES', true );
}

foreach ($test_params as $auth_status => $status_message_in_rendered_view) {

$auth->getSession()->setStatus($auth_status);
Expand All @@ -1575,11 +1580,6 @@ public function testThat_actionLoginStatus_WorksAsExpected() {
self::assertStringContainsString('<br>'.nl2br(sMVC_DumpAuthinfo($auth)), $action_result);
}

if(!defined('SMVC_APP_AUTO_PREPEND_ACTION_TO_ACTION_METHOD_NAMES')){

define('SMVC_APP_AUTO_PREPEND_ACTION_TO_ACTION_METHOD_NAMES', true );
}

////////////////////////////////////////////////////////////////////////
// Login & check that the page returned contains expected html elements
////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 18e53b6

Please sign in to comment.