Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dead code and improve method machCode(). #181

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 7 additions & 27 deletions UrlManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -548,44 +548,24 @@ protected function matchCode($code)
$language = $code;
$country = null;
}

if (in_array($language . '-*', $this->languages)) {
if ($hasDash) {
// TODO: Make wildcards work with script codes
// like `sr-Latn`
return [$language, strtoupper($country)];
} else {
return [$language, null];
}
} elseif ($hasDash && in_array($language, $this->languages)) {
return [$language, null];
} else {
return [null, null];
}
} else {
$result = $this->languages[$key];
return $hasDash ? explode('-', $result, 2) : [$result, null];
if ($hasDash && in_array($language, $this->languages)) {
return [$language, null];
}
return [null, null];
}

$language = $code;
$country = null;
$parts = explode('-', $code);
if (count($parts) === 2) {
$language = $parts[0];
$country = strtoupper($parts[1]);
}
$result = $this->languages[$key];

if (in_array($code, $this->languages)) {
return [$language, $country];
} elseif (
$country && in_array("$language-$country", $this->languages) ||
in_array("$language-*", $this->languages)
) {
return [$language, $country];
} elseif (in_array($language, $this->languages)) {
return [$language, null];
} else {
return [null, null];
}
return $hasDash ? explode('-', $result, 2) : [$result, null];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, before I dig deeper into this: The code here has seen a couple of iterations so I think there was good reason why it was written that way. At a quick glance your change seems to oversimplify things.

I'd prefer not to touch it as the library has worked reliably for years ("If it ain't broken - don't fix it").

}

/**
Expand Down