Skip to content

Commit

Permalink
**Zesk Kernel**: Code cleanup and linting
Browse files Browse the repository at this point in the history
  • Loading branch information
razzed committed Jul 20, 2020
1 parent f7ebd27 commit 1fe4536
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
4 changes: 2 additions & 2 deletions classes/Configure/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,8 @@ public function command_symlink($symlink, $file) {
/**
* Map a string using the current variable map
*
* @param string $string
* @return string
* @param string|array $string
* @return string|array
*/
public function map($string) {
return map($string, $this->variable_map, true);
Expand Down
4 changes: 2 additions & 2 deletions classes/Controller/Control.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public function action_control($control, $name, $input) {

$result = array(
"content" => $this->widget_factory($control)
->request($this->request)->response($this->response)
->names($name, null, $input)
->json(true)
->request($this->request)->response($this->response)
->json()
->execute(),
);
$result += $this->response->to_json();
Expand Down
19 changes: 11 additions & 8 deletions classes/Locale/Validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,13 @@ public function check_translation_token_count($source, $translation) {
$translation_matches = $this->extract_tokens($translation);
$errors = array();
$n = count($source_matches) - count($translation_matches);
$locale = $this->application->locale;
if ($n > 0) {
$errors[] = __("Missing {n_tokens} in translation", array(
$errors[] = $locale->__("Missing {n_tokens} in translation", array(
"n_tokens" => $this->locale->plural_word("token", $n),
));
} elseif ($n < 0) {
$errors[] = __("You have an additional {n_tokens} in your translation", array(
$errors[] = $locale->__("You have an additional {n_tokens} in your translation", array(
"n_tokens" => $this->locale->plural_word("token", -$n),
));
}
Expand All @@ -133,15 +134,16 @@ public function check_translation_token_names($source, $translation) {
$translation_matches = $this->extract_tokens($translation);
$errors = array();
if ($translation_matches !== $source_matches) {
$locale = $this->application->locale;
$missing = array_diff($source_matches, $translation_matches);
if (count($missing) > 0) {
$errors[] = __("Target phrase is missing the following variables: {missing}", array(
$errors[] = $locale->__("Target phrase is missing the following variables: {missing}", array(
"missing" => implode(", ", $missing),
));
}
$extras = array_diff($translation_matches, $source_matches);
if (count($extras) > 0) {
$errors[] = __("Target phrase has extra variables it shouldn't have: {extras}", array(
$errors[] = $locale->__("Target phrase has extra variables it shouldn't have: {extras}", array(
"extras" => implode(", ", $extras),
));
}
Expand All @@ -162,27 +164,28 @@ public function check_translation_braces($source, $translation) {
$translation_matches = $this->extract_braces($translation);
$stack = 0;
$errors = array();
$locale = $this->application->locale;
foreach ($source_matches as $index => $bracket) {
if ($bracket === ']' && $stack === 0) {
$errors[] = __("Unexpected close brace &quot;]&quot; found before open brace; are the braces balanced?");
$errors[] = $locale->__("Unexpected close brace &quot;]&quot; found before open brace; are the braces balanced?");
return $errors;
}
$stack += ($bracket === ']') ? 1 : -1;
if (!array_key_exists($index, $translation_matches)) {
$errors[] = __("Translation is missing a pair of braces.");
$errors[] = $locale->__("Translation is missing a pair of braces.");
return $errors;
}
$translation_bracket = $translation_matches[$index];
if ($translation_bracket !== $bracket) {
$errors[] = __("The {nth} brace in the translation ({translation_bracket}) does not match the source string bracket ({bracket})", array(
$errors[] = $locale->__("The {nth} brace in the translation ({translation_bracket}) does not match the source string bracket ({bracket})", array(
"nth" => $this->locale->ordinal($index + 1),
"debug" => JSON::encode($source_matches) . " " . JSON::encode($translation_matches),
) + compact("translation_bracket", "bracket"));
return $errors;
}
}
if (count($translation_matches) > count($source_matches)) {
$errors[] = __("The translation has an extra {num_braces} than the source phrase.", array(
$errors[] = $locale->__("The translation has an extra {num_braces} than the source phrase.", array(
"n" => $n = count($translation_matches) - count($source_matches),
"num_braces" => $this->locale->plural_word("brace", $n),
));
Expand Down
2 changes: 1 addition & 1 deletion classes/Response/HTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ public function jquery_ready() {
* 'attributes' => array('type' => 'text/javascript', 'src' => '),
* </code>
*
* @return string
* @return array
*/
private function script_tags($cache_scripts = null) {
// Sort them by weight if they're not sorted
Expand Down
4 changes: 2 additions & 2 deletions classes/Route/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ private function _determine_class_action() {
} catch (Exception_Class_NotFound $e) {
}
if (!$reflectionClass) {
throw new Exception_Class_NotFound($class_name, __("Controller {controller} not found", array(
throw new Exception_Class_NotFound($class_name, map("Controller {controller} not found", array(
'controller' => $class_name,
)));
}
Expand Down Expand Up @@ -243,7 +243,7 @@ protected function get_route_map($action, $object = null, $options = null) {
$url = map($this->clean_pattern, $map);
if (!$this->match($url)) {
throw new Exception_Invalid("{method} {pattern} does not match {url} - route {original_pattern} is corrupt", [
"method" => $method,
"method" => __METHOD__,
"url" => $url,
] + $this->variables());
}
Expand Down

0 comments on commit 1fe4536

Please sign in to comment.