forked from CIT/Vmeda.Online
		
	MOBILE-4081 chore: PHP Code smell fixes
This commit is contained in:
		
							parent
							
								
									44cbee9683
								
							
						
					
					
						commit
						4d6962043c
					
				| @ -283,7 +283,7 @@ class behat_app extends behat_app_helper { | ||||
| 
 | ||||
|         // Wait until the main page appears.
 | ||||
|         $this->spin( | ||||
|                 function($context, $args) { | ||||
|                 function($context) { | ||||
|                     $initialpage = $context->getSession()->getPage()->find('xpath', '//page-core-mainmenu') ?? | ||||
|                         $context->getSession()->getPage()->find('xpath', '//page-core-login-change-password') ?? | ||||
|                         $context->getSession()->getPage()->find('xpath', '//page-core-user-complete-profile'); | ||||
| @ -780,7 +780,7 @@ class behat_app extends behat_app_helper { | ||||
|             if (!is_null($urlpattern)) { | ||||
|                 $this->getSession()->switchToWindow($windowNames[1]); | ||||
|                 $windowurl = $this->getSession()->getCurrentUrl(); | ||||
|                 $windowhaspattern = !!preg_match("/$urlpattern/", $windowurl); | ||||
|                 $windowhaspattern = (bool)preg_match("/$urlpattern/", $windowurl); | ||||
|                 $this->getSession()->switchToWindow($windowNames[0]); | ||||
| 
 | ||||
|                 if ($not === $windowhaspattern) { | ||||
| @ -885,6 +885,8 @@ class behat_app extends behat_app_helper { | ||||
|             case 'offline': | ||||
|                 $this->runtime_js("network.setForceConnectionMode('none');"); | ||||
|                 break; | ||||
|             default: | ||||
|                 break; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -412,12 +412,9 @@ class behat_app_helper extends behat_base { | ||||
|         preg_match_all("/\\$\\{([^:}]+):([^}]+)\\}/", $text, $matches); | ||||
| 
 | ||||
|         foreach ($matches[0] as $index => $match) { | ||||
|             switch ($matches[2][$index]) { | ||||
|                 case 'cmid': | ||||
|                     $coursemodule = $DB->get_record('course_modules', ['idnumber' => $matches[1][$index]]); | ||||
|                     $text = str_replace($match, $coursemodule->id, $text); | ||||
| 
 | ||||
|                     break; | ||||
|             if ($matches[2][$index] == 'cmid') { | ||||
|                 $coursemodule = $DB->get_record('course_modules', ['idnumber' => $matches[1][$index]]); | ||||
|                 $text = str_replace($match, $coursemodule->id, $text); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
| @ -550,7 +547,7 @@ class behat_app_helper extends behat_base { | ||||
|         if (!empty($successXPath)) { | ||||
|             // Wait until the page appears.
 | ||||
|             $this->spin( | ||||
|                 function($context, $args) use ($successXPath) { | ||||
|                 function($context) use ($successXPath) { | ||||
|                     $found = $context->getSession()->getPage()->find('xpath', $successXPath); | ||||
|                     if ($found) { | ||||
|                         return true; | ||||
| @ -597,7 +594,6 @@ class behat_app_helper extends behat_base { | ||||
|         $cmfrom = $cmtable->get_from_sql(); | ||||
| 
 | ||||
|         $acttable = new \core\dml\table($activity, 'a', 'a'); | ||||
|         $actselect = $acttable->get_field_select(); | ||||
|         $actfrom = $acttable->get_from_sql(); | ||||
| 
 | ||||
|         $sql = <<<EOF | ||||
| @ -662,7 +658,7 @@ EOF; | ||||
|         // Set up relevant tags for each version.
 | ||||
|         $usedtags = array_keys($usedtags); | ||||
|         foreach ($usedtags as $usedtag) { | ||||
|             if (!preg_match('~^lms_(from|upto)([0-9]+(?:\.[0-9]+)*)$~', $usedtag, $matches)) { | ||||
|             if (!preg_match('~^lms_(from|upto)(\d+(?:\.\d+)*)$~', $usedtag, $matches)) { | ||||
|                 // No match, ignore.
 | ||||
|                 continue; | ||||
|             } | ||||
|  | ||||
| @ -78,10 +78,8 @@ class behat_performance extends behat_base { | ||||
|         $spaceindex = strpos($text, ' '); | ||||
|         $value = floatval(substr($text, 0, $spaceindex)); | ||||
| 
 | ||||
|         switch (substr($text, $spaceindex + 1)) { | ||||
|             case 'seconds': | ||||
|                 $value *= 1000; | ||||
|                 break; | ||||
|         if (substr($text, $spaceindex + 1) == 'seconds') { | ||||
|             $value *= 1000; | ||||
|         } | ||||
| 
 | ||||
|         return $value; | ||||
| @ -108,6 +106,8 @@ class behat_performance extends behat_base { | ||||
|                 return function ($a, $b) { | ||||
|                     return $a === $b; | ||||
|                 }; | ||||
|             default: | ||||
|                 break; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -247,13 +247,13 @@ class performance_measure implements behat_app_listener { | ||||
|      * Analyse long tasks. | ||||
|      */ | ||||
|     private function analyseLongTasks(): void { | ||||
|         $blocking = 0; | ||||
|         $blockingDuration = 0; | ||||
| 
 | ||||
|         foreach ($this->longTasks as $longTask) { | ||||
|             $blocking += $longTask['duration'] - 50; | ||||
|             $blockingDuration += $longTask['duration'] - 50; | ||||
|         } | ||||
| 
 | ||||
|         $this->blocking = $blocking; | ||||
|         $this->blocking = $blockingDuration; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
| @ -269,15 +269,15 @@ class performance_measure implements behat_app_listener { | ||||
|     private function analysePerformanceLogs(): void { | ||||
|         global $CFG; | ||||
| 
 | ||||
|         $scripting = 0; | ||||
|         $styling = 0; | ||||
|         $networking = 0; | ||||
|         $scriptingDuration = 0; | ||||
|         $stylingDuration = 0; | ||||
|         $networkingCount = 0; | ||||
|         $logs = $this->getPerformanceLogs(); | ||||
| 
 | ||||
|         foreach ($logs as $log) { | ||||
|             // TODO this should filter by end time as well, but it seems like the timestamps are not
 | ||||
|             // working as expected.
 | ||||
|             if (($log['timestamp'] < $this->start)) { | ||||
|             if ($log['timestamp'] < $this->start) { | ||||
|                 continue; | ||||
|             } | ||||
| 
 | ||||
| @ -285,27 +285,27 @@ class performance_measure implements behat_app_listener { | ||||
|             $messagename = $message->params->name ?? ''; | ||||
| 
 | ||||
|             if (in_array($messagename, ['FunctionCall', 'GCEvent', 'MajorGC', 'MinorGC', 'EvaluateScript'])) { | ||||
|                 $scripting += $message->params->dur; | ||||
|                 $scriptingDuration += $message->params->dur; | ||||
| 
 | ||||
|                 continue; | ||||
|             } | ||||
| 
 | ||||
|             if (in_array($messagename, ['UpdateLayoutTree', 'RecalculateStyles', 'ParseAuthorStyleSheet'])) { | ||||
|                 $styling += $message->params->dur; | ||||
|                 $stylingDuration += $message->params->dur; | ||||
| 
 | ||||
|                 continue; | ||||
|             } | ||||
| 
 | ||||
|             if (in_array($messagename, ['XHRLoad']) && !str_starts_with($message->params->args->data->url, $CFG->behat_ionic_wwwroot)) { | ||||
|                 $networking++; | ||||
|                 $networkingCount++; | ||||
| 
 | ||||
|                 continue; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         $this->scripting = round($scripting / 1000); | ||||
|         $this->styling = round($styling / 1000); | ||||
|         $this->networking = $networking; | ||||
|         $this->scripting = round($scriptingDuration / 1000); | ||||
|         $this->styling = round($stylingDuration / 1000); | ||||
|         $this->networking = $networkingCount; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | ||||
| @ -42,7 +42,7 @@ $versions = array('master', '310', '39', '38', '37', '36', '35', '34', '33', '32 | ||||
| 
 | ||||
| $moodlespath = $argv[1]; | ||||
| $wsname = $argv[2]; | ||||
| $useparams = !!(isset($argv[3]) && $argv[3]); | ||||
| $useparams = (bool)(isset($argv[3]) && $argv[3]); | ||||
| $pathseparator = '/'; | ||||
| 
 | ||||
| // Get the path to the script.
 | ||||
|  | ||||
| @ -39,7 +39,7 @@ if (!defined('SERIALIZED')) { | ||||
| 
 | ||||
| $moodlepath = $argv[1]; | ||||
| $wsname = $argv[2]; | ||||
| $useparams = !!(isset($argv[3]) && $argv[3]); | ||||
| $useparams = (bool)(isset($argv[3]) && $argv[3]); | ||||
| 
 | ||||
| define('CLI_SCRIPT', true); | ||||
| 
 | ||||
|  | ||||
| @ -302,7 +302,7 @@ function build_lang($lang) { | ||||
|                 $text = str_replace(['{{{', '}}}'], ['{{', '}}'], $text); | ||||
|             } else { | ||||
|                 // @TODO: Remove that line when core.cannotconnect and core.login.invalidmoodleversion are completelly changed to use $a
 | ||||
|                 if (($appkey == 'core.cannotconnect' || $appkey == 'core.login.invalidmoodleversion') && strpos($text, '2.4') != false) { | ||||
|                 if (($appkey == 'core.cannotconnect' || $appkey == 'core.login.invalidmoodleversion') && strpos($text, '2.4')) { | ||||
|                     $text = str_replace('2.4', '{{$a}}', $text); | ||||
|                 } | ||||
|                 $local++; | ||||
| @ -471,13 +471,10 @@ function override_component_lang_files($translations) { | ||||
|         } | ||||
|         switch($type) { | ||||
|             case 'core': | ||||
|                 switch($component) { | ||||
|                     case 'moodle': | ||||
|                         $path .= 'core/lang.json'; | ||||
|                         break; | ||||
|                     default: | ||||
|                         $path .= 'core/features/'.str_replace('_', '/', $component).'/lang.json'; | ||||
|                         break; | ||||
|                 if ($component == 'moodle') { | ||||
|                     $path .= 'core/lang.json'; | ||||
|                 } else { | ||||
|                     $path .= 'core/features/'.str_replace('_', '/', $component).'/lang.json'; | ||||
|                 } | ||||
|                 break; | ||||
|             case 'addon': | ||||
|  | ||||
| @ -70,7 +70,7 @@ function fix_comment($desc) { | ||||
|     if (count($lines) > 1) { | ||||
|         $desc = array_shift($lines)."\n"; | ||||
| 
 | ||||
|         foreach ($lines as $i => $line) { | ||||
|         foreach ($lines as $line) { | ||||
|             $spaces = strlen($line) - strlen(ltrim($line)); | ||||
|             $desc .= str_repeat(' ', $spaces - 3) . '// '. ltrim($line)."\n"; | ||||
|         } | ||||
| @ -138,9 +138,7 @@ function convert_to_ts($key, $value, $boolisnumber = false, $indentation = '', $ | ||||
|             $type = 'number'; | ||||
|         } | ||||
| 
 | ||||
|         $result = convert_key_type($key, $type, $value->required, $indentation); | ||||
| 
 | ||||
|         return $result; | ||||
|         return convert_key_type($key, $type, $value->required, $indentation); | ||||
| 
 | ||||
|     } else if ($value instanceof external_single_structure) { | ||||
|         // It's an object.
 | ||||
| @ -278,7 +276,7 @@ function remove_default_closures($value) { | ||||
| 
 | ||||
|     } else if ($value instanceof external_single_structure) { | ||||
| 
 | ||||
|         foreach ($value->keys as $key => $subvalue) { | ||||
|         foreach ($value->keys as $subvalue) { | ||||
|             remove_default_closures($subvalue); | ||||
|         } | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user