Applied code style rules to src/

This commit is contained in:
Jan Böhmer 2020-01-05 15:46:58 +01:00
parent 700c049d26
commit f861de791f
186 changed files with 1462 additions and 1059 deletions

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -114,23 +117,6 @@ class AttachmentPathResolver
return $tmp;
}
/**
* Create an array usable for preg_replace out of an array of placeholders or pathes.
* Slashes and other chars become escaped.
* For example: '%TEST%' becomes '/^%TEST%/'.
*/
protected function arrayToRegexArray(array $array): array
{
$ret = [];
foreach ($array as $item) {
$item = str_replace(['\\'], ['/'], $item);
$ret[] = '/'.preg_quote($item, '/').'/';
}
return $ret;
}
/**
* Converts an relative placeholder filepath (with %MEDIA% or older %BASE%) to an absolute filepath on disk.
* The directory separator is always /. Relative pathes are not realy possible (.. is striped).
@ -163,9 +149,7 @@ class AttachmentPathResolver
}
//Normalize path and remove .. (to prevent directory traversal attack)
$placeholder_path = str_replace(['\\'], ['/'], $placeholder_path);
return $placeholder_path;
return str_replace(['\\'], ['/'], $placeholder_path);
}
/**
@ -199,7 +183,7 @@ class AttachmentPathResolver
}
//If the new string does not begin with a placeholder, it is invalid
if (!preg_match('/^%\w+%/', $real_path)) {
if (! preg_match('/^%\w+%/', $real_path)) {
return null;
}
@ -246,4 +230,21 @@ class AttachmentPathResolver
{
return $this->models_path;
}
/**
* Create an array usable for preg_replace out of an array of placeholders or pathes.
* Slashes and other chars become escaped.
* For example: '%TEST%' becomes '/^%TEST%/'.
*/
protected function arrayToRegexArray(array $array): array
{
$ret = [];
foreach ($array as $item) {
$item = str_replace(['\\'], ['/'], $item);
$ret[] = '/'.preg_quote($item, '/').'/';
}
return $ret;
}
}