Fixed code style.

This commit is contained in:
Jan Böhmer 2020-08-21 21:36:22 +02:00
parent 2853e471c4
commit d0b1024d80
212 changed files with 495 additions and 1005 deletions

View file

@ -72,7 +72,7 @@ class AttachmentManager
*/
public function attachmentToFile(Attachment $attachment): ?SplFileInfo
{
if ($attachment->isExternal() || ! $this->isFileExisting($attachment)) {
if ($attachment->isExternal() || !$this->isFileExisting($attachment)) {
return null;
}
@ -150,7 +150,7 @@ class AttachmentManager
return null;
}
if (! $this->isFileExisting($attachment)) {
if (!$this->isFileExisting($attachment)) {
return null;
}

View file

@ -203,7 +203,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;
}

View file

@ -58,7 +58,6 @@ use App\Entity\Attachments\StorelocationAttachment;
use App\Entity\Attachments\SupplierAttachment;
use App\Entity\Attachments\UserAttachment;
use App\Exceptions\AttachmentDownloadException;
use Symfony\Component\Form\FormInterface;
use const DIRECTORY_SEPARATOR;
use function get_class;
use InvalidArgumentException;
@ -82,7 +81,6 @@ class AttachmentSubmitHandler
protected $mimeTypes;
protected $filterTools;
public function __construct(AttachmentPathResolver $pathResolver, bool $allow_attachments_downloads,
HttpClientInterface $httpClient, MimeTypesInterface $mimeTypes,
FileTypeFilterTools $filterTools)
@ -114,9 +112,6 @@ class AttachmentSubmitHandler
/**
* Check if the extension of the uploaded file is allowed for the given attachment type.
* Returns true, if the file is allowed, false if not.
* @param AttachmentType $attachment_type
* @param UploadedFile $uploadedFile
* @return bool
*/
public function isValidFileExtension(AttachmentType $attachment_type, UploadedFile $uploadedFile): bool
{
@ -174,7 +169,7 @@ class AttachmentSubmitHandler
}
//Ensure the given attachment class is known to mapping
if (! isset($this->folder_mapping[get_class($attachment)])) {
if (!isset($this->folder_mapping[get_class($attachment)])) {
throw new InvalidArgumentException('The given attachment class is not known! The passed class was: '.get_class($attachment));
}
//Ensure the attachment has an assigned element
@ -260,13 +255,13 @@ class AttachmentSubmitHandler
//Determine the old filepath
$old_path = $this->pathResolver->placeholderToRealPath($attachment->getPath());
if (! file_exists($old_path)) {
if (!file_exists($old_path)) {
return $attachment;
}
$filename = basename($old_path);
//If the basename is not one of the new unique on, we have to save the old filename
if (! preg_match('#\w+-\w{13}\.#', $filename)) {
if (!preg_match('#\w+-\w{13}\.#', $filename)) {
//Save filename to attachment field
$attachment->setFilename($attachment->getFilename());
}
@ -298,7 +293,7 @@ class AttachmentSubmitHandler
protected function downloadURL(Attachment $attachment, array $options): Attachment
{
//Check if we are allowed to download files
if (! $this->allow_attachments_downloads) {
if (!$this->allow_attachments_downloads) {
throw new RuntimeException('Download of attachments is not allowed!');
}
@ -348,7 +343,7 @@ class AttachmentSubmitHandler
//Check if we have a extension given
$pathinfo = pathinfo($filename);
if (! empty($pathinfo['extension'])) {
if (!empty($pathinfo['extension'])) {
$new_ext = $pathinfo['extension'];
} else { //Otherwise we have to guess the extension for the new file, based on its content
$new_ext = $this->mimeTypes->getExtensions($this->mimeTypes->guessMimeType($tmp_path))[0] ?? 'tmp';

View file

@ -106,13 +106,12 @@ class AttachmentURLGenerator
/**
* Converts a placeholder path to a path to a image path.
*
* @param string $placeholder_path the placeholder path that should be converted
*
* @return string|null
* @param string $placeholder_path the placeholder path that should be converted
*/
public function placeholderPathToAssetPath(string $placeholder_path): ?string
{
$absolute_path = $this->pathResolver->placeholderToRealPath($placeholder_path);
return $this->absolutePathToAssetPath($absolute_path);
}
@ -142,11 +141,11 @@ class AttachmentURLGenerator
*/
public function getThumbnailURL(Attachment $attachment, string $filter_name = 'thumbnail_sm'): string
{
if (! $attachment->isPicture()) {
if (!$attachment->isPicture()) {
throw new InvalidArgumentException('Thumbnail creation only works for picture attachments!');
}
if ($attachment->isExternal() && ! empty($attachment->getURL())) {
if ($attachment->isExternal() && !empty($attachment->getURL())) {
return $attachment->getURL();
}
@ -165,7 +164,7 @@ class AttachmentURLGenerator
//because the footprints images are small and highly optimized already.
if (('thumbnail_md' === $filter_name && $attachment->isBuiltIn())
//GD can not work with SVG, so serve it directly...
|| $attachment->getExtension() === 'svg') {
|| 'svg' === $attachment->getExtension()) {
return $this->assets->getUrl($asset_path);
}

View file

@ -91,9 +91,9 @@ class FileTypeFilterTools
//Check for each element if it is valid:
foreach ($elements as $element) {
$element = trim($element);
if (! preg_match('#^\.\w+$#', $element) // .ext is allowed
&& ! preg_match('#^[-\w.]+\/[-\w.]+#', $element) //Explicit MIME type is allowed
&& ! in_array($element, static::ALLOWED_MIME_PLACEHOLDERS, false)) { //image/* is allowed
if (!preg_match('#^\.\w+$#', $element) // .ext is allowed
&& !preg_match('#^[-\w.]+\/[-\w.]+#', $element) //Explicit MIME type is allowed
&& !in_array($element, static::ALLOWED_MIME_PLACEHOLDERS, false)) { //image/* is allowed
return false;
}
}
@ -139,7 +139,7 @@ class FileTypeFilterTools
$element = 'video/*';
} elseif ('audio' === $element || 'audio/' === $element) {
$element = 'audio/*';
} elseif (! preg_match('#^[-\w.]+\/[-\w.*]+#', $element) && 0 !== strpos($element, '.')) {
} elseif (!preg_match('#^[-\w.]+\/[-\w.*]+#', $element) && 0 !== strpos($element, '.')) {
//Convert jpg to .jpg
$element = '.'.$element;
}