Code improvements (#1649)

* use global namespace for faster lookups
* phpstan level 5
This commit is contained in:
Kevin Papst
2020-04-19 14:37:14 +02:00
committed by GitHub
parent 7b25e9acaf
commit 0f3fa8fdbe
183 changed files with 604 additions and 574 deletions

View File

@@ -129,7 +129,7 @@ class AvatarService
$filePath = $this->getImagePath($profile);
if ($regenerate || !file_exists($filePath)) {
if (!is_writable(dirname($filePath))) {
if (!is_writable(\dirname($filePath))) {
return false;
}
$avatar = new Avatar(self::AVATAR_CONFIG);
@@ -154,6 +154,6 @@ class AvatarService
public function hasDependencies(): bool
{
return extension_loaded('gd') && function_exists('imagettfbbox');
return \extension_loaded('gd') && \function_exists('imagettfbbox');
}
}

View File

@@ -122,14 +122,14 @@ class Duration
protected function parseColonFormat(string $duration): int
{
$parts = explode(':', $duration);
if (count($parts) < 2 || count($parts) > 3) {
if (\count($parts) < 2 || \count($parts) > 3) {
throw new \InvalidArgumentException(
sprintf('Invalid colon format given in "%s"', $duration)
);
}
foreach ($parts as $part) {
if (strlen($part) === 0) {
if (\strlen($part) === 0) {
throw new \InvalidArgumentException(
sprintf('Colon format cannot parse "%s"', $duration)
);
@@ -143,7 +143,7 @@ class Duration
$seconds = 0;
if (3 == count($parts)) {
if (3 == \count($parts)) {
$seconds += (int) array_pop($parts);
}

View File

@@ -37,15 +37,15 @@ class MPdfConverter implements HtmlToPdfConverter
// some OS do not follow the PHP default settings
if ((int) ini_get('pcre.backtrack_limit') < 1000000) {
@ini_set('pcre.backtrack_limit', 1000000);
@ini_set('pcre.backtrack_limit', '1000000');
}
// reduce the size of content parts that are passed to MPDF, to prevent
// https://mpdf.github.io/troubleshooting/known-issues.html#blank-pages-or-some-sections-missing
$parts = explode('<pagebreak>', $html);
for ($i = 0; $i < count($parts); $i++) {
for ($i = 0; $i < \count($parts); $i++) {
$mpdf->WriteHTML($parts[$i]);
if ($i < count($parts) - 1) {
if ($i < \count($parts) - 1) {
$mpdf->WriteHTML('<pagebreak>');
}
}

View File

@@ -31,6 +31,6 @@ class MenuItemModel extends BaseMenuItemModel
public function isChildRoute(string $route): bool
{
return in_array($route, $this->childRoutes);
return \in_array($route, $this->childRoutes);
}
}

View File

@@ -52,7 +52,7 @@ class ParsedownExtension extends \Parsedown
$url = $matches[0][0];
$Inline = [
'extent' => strlen($matches[0][0]),
'extent' => \strlen($matches[0][0]),
'position' => $matches[0][1],
'element' => [
'name' => 'a',

View File

@@ -38,7 +38,7 @@ final class SearchTerm
foreach ($terms as $term) {
$tmp = explode(':', $term);
if (count($tmp) === 2) {
if (\count($tmp) === 2) {
$fields[$tmp[0]] = $tmp[1];
} else {
$finalTerm[] = $term;
@@ -51,7 +51,7 @@ final class SearchTerm
public function hasSearchField(string $name): bool
{
return array_key_exists($name, $this->fields);
return \array_key_exists($name, $this->fields);
}
public function getSearchField(string $name): ?string