Applied symplify rules to codebase.

This commit is contained in:
Jan Böhmer 2020-01-05 22:49:00 +01:00
parent 2f20d90041
commit 388e847b17
136 changed files with 1370 additions and 789 deletions

View file

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace App\Services;
use App\Entity\Parts\MeasurementUnit;
use InvalidArgumentException;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
@ -48,12 +49,12 @@ class AmountFormatter
*
* @return string The formatted string
*
* @throws \InvalidArgumentException thrown if $value is not numeric
* @throws InvalidArgumentException thrown if $value is not numeric
*/
public function format($value, ?MeasurementUnit $unit = null, array $options = [])
{
if (! is_numeric($value)) {
throw new \InvalidArgumentException('$value must be an numeric value!');
throw new InvalidArgumentException('$value must be an numeric value!');
}
$value = (float) $value;
@ -117,7 +118,9 @@ class AmountFormatter
return '';
},
'decimals' => 2,
'error_mapping' => ['.' => 'value'],
'error_mapping' => [
'.' => 'value',
],
]);
$resolver->setAllowedTypes('decimals', 'int');

View file

@ -25,6 +25,8 @@ declare(strict_types=1);
namespace App\Services\Attachments;
use App\Entity\Attachments\Attachment;
use SplFileInfo;
use function strlen;
/**
* This service contains basic commonly used functions to work with attachments.
@ -47,16 +49,16 @@ class AttachmentManager
*
* @param Attachment $attachment The attachment for which the file should be generated
*
* @return \SplFileInfo|null The fileinfo for the attachment file. Null, if the attachment is external or has
* invalid file.
* @return SplFileInfo|null The fileinfo for the attachment file. Null, if the attachment is external or has
* invalid file.
*/
public function attachmentToFile(Attachment $attachment): ?\SplFileInfo
public function attachmentToFile(Attachment $attachment): ?SplFileInfo
{
if ($attachment->isExternal() || ! $this->isFileExisting($attachment)) {
return null;
}
return new \SplFileInfo($this->toAbsoluteFilePath($attachment));
return new SplFileInfo($this->toAbsoluteFilePath($attachment));
}
/**
@ -107,7 +109,7 @@ class AttachmentManager
$absolute_path = $this->toAbsoluteFilePath($attachment);
if ($absolute_path === null) {
if (null === $absolute_path) {
return false;
}
@ -155,7 +157,7 @@ class AttachmentManager
//Taken from: https://www.php.net/manual/de/function.filesize.php#106569 and slightly modified
$sz = 'BKMGTP';
$factor = (int) floor((\strlen($bytes) - 1) / 3);
$factor = (int) floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / 1024 ** $factor).@$sz[$factor];
}

View file

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace App\Services\Attachments;
use const DIRECTORY_SEPARATOR;
use Symfony\Component\Filesystem\Filesystem;
/**
@ -106,7 +107,7 @@ class AttachmentPathResolver
}
//Otherwise prepend the project path
$tmp = realpath($this->project_dir.\DIRECTORY_SEPARATOR.$param_path);
$tmp = realpath($this->project_dir.DIRECTORY_SEPARATOR.$param_path);
//If path does not exist then disable the placeholder
if (false === $tmp) {
@ -139,7 +140,7 @@ class AttachmentPathResolver
}
//If we have now have a placeholder left, the string is invalid:
if (preg_match('/%\w+%/', $placeholder_path)) {
if (preg_match('#%\w+%#', $placeholder_path)) {
return null;
}
@ -183,7 +184,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

@ -25,8 +25,10 @@ declare(strict_types=1);
namespace App\Services\Attachments;
use App\Entity\Attachments\Attachment;
use function count;
use Doctrine\ORM\EntityManagerInterface;
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
use SplFileInfo;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\File\File;
@ -52,11 +54,11 @@ class AttachmentReverseSearch
/**
* Find all attachments that use the given file.
*
* @param \SplFileInfo $file The file for which is searched
* @param SplFileInfo $file The file for which is searched
*
* @return Attachment[] an list of attachments that use the given file
*/
public function findAttachmentsByFile(\SplFileInfo $file): array
public function findAttachmentsByFile(SplFileInfo $file): array
{
//Path with %MEDIA%
$relative_path_new = $this->pathResolver->realPathToPlaceholder($file->getPathname());
@ -65,21 +67,23 @@ class AttachmentReverseSearch
$repo = $this->em->getRepository(Attachment::class);
return $repo->findBy(['path' => [$relative_path_new, $relative_path_old]]);
return $repo->findBy([
'path' => [$relative_path_new, $relative_path_old],
]);
}
/**
* Deletes the given file if it is not used by more than $threshold attachments.
*
* @param \SplFileInfo $file The file that should be removed
* @param int $threshold the threshold used, to determine if a file should be deleted or not
* @param SplFileInfo $file The file that should be removed
* @param int $threshold the threshold used, to determine if a file should be deleted or not
*
* @return bool True, if the file was delete. False if not.
*/
public function deleteIfNotUsed(\SplFileInfo $file, int $threshold = 1): bool
public function deleteIfNotUsed(SplFileInfo $file, int $threshold = 1): bool
{
/* When the file is used more then $threshold times, don't delete it */
if (\count($this->findAttachmentsByFile($file)) > $threshold) {
if (count($this->findAttachmentsByFile($file)) > $threshold) {
return false;
}

View file

@ -39,6 +39,10 @@ use App\Entity\Attachments\StorelocationAttachment;
use App\Entity\Attachments\SupplierAttachment;
use App\Entity\Attachments\UserAttachment;
use App\Exceptions\AttachmentDownloadException;
use const DIRECTORY_SEPARATOR;
use function get_class;
use InvalidArgumentException;
use RuntimeException;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Mime\MimeTypesInterface;
@ -66,12 +70,20 @@ class AttachmentSubmitHandler
$this->mimeTypes = $mimeTypes;
//The mapping used to determine which folder will be used for an attachment type
$this->folder_mapping = [PartAttachment::class => 'part', AttachmentTypeAttachment::class => 'attachment_type',
CategoryAttachment::class => 'category', CurrencyAttachment::class => 'currency',
DeviceAttachment::class => 'device', FootprintAttachment::class => 'footprint',
GroupAttachment::class => 'group', ManufacturerAttachment::class => 'manufacturer',
MeasurementUnitAttachment::class => 'measurement_unit', StorelocationAttachment::class => 'storelocation',
SupplierAttachment::class => 'supplier', UserAttachment::class => 'user', ];
$this->folder_mapping = [
PartAttachment::class => 'part',
AttachmentTypeAttachment::class => 'attachment_type',
CategoryAttachment::class => 'category',
CurrencyAttachment::class => 'currency',
DeviceAttachment::class => 'device',
FootprintAttachment::class => 'footprint',
GroupAttachment::class => 'group',
ManufacturerAttachment::class => 'manufacturer',
MeasurementUnitAttachment::class => 'measurement_unit',
StorelocationAttachment::class => 'storelocation',
SupplierAttachment::class => 'supplier',
UserAttachment::class => 'user',
];
}
/**
@ -117,18 +129,18 @@ class AttachmentSubmitHandler
}
//Ensure the given attachment class is known to mapping
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));
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
if (null === $attachment->getElement()) {
throw new \InvalidArgumentException('The given attachment is not assigned to an element! An element is needed to generate a path!');
throw new InvalidArgumentException('The given attachment is not assigned to an element! An element is needed to generate a path!');
}
//Build path
return
$base_path.\DIRECTORY_SEPARATOR //Base path
.$this->folder_mapping[\get_class($attachment)].\DIRECTORY_SEPARATOR.$attachment->getElement()->getID();
$base_path.DIRECTORY_SEPARATOR //Base path
.$this->folder_mapping[get_class($attachment)].DIRECTORY_SEPARATOR.$attachment->getElement()->getID();
}
/**
@ -209,14 +221,14 @@ class AttachmentSubmitHandler
$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());
}
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$new_path = $this->generateAttachmentPath($attachment, $secure_location)
.\DIRECTORY_SEPARATOR.$this->generateAttachmentFilename($attachment, $ext);
.DIRECTORY_SEPARATOR.$this->generateAttachmentFilename($attachment, $ext);
//Move file to new directory
$fs = new Filesystem();
@ -240,14 +252,14 @@ class AttachmentSubmitHandler
{
//Check if we are allowed to download files
if (! $this->allow_attachments_downloads) {
throw new \RuntimeException('Download of attachments is not allowed!');
throw new RuntimeException('Download of attachments is not allowed!');
}
$url = $attachment->getURL();
$fs = new Filesystem();
$attachment_folder = $this->generateAttachmentPath($attachment, $options['secure_attachment']);
$tmp_path = $attachment_folder.\DIRECTORY_SEPARATOR.$this->generateAttachmentFilename($attachment, 'tmp');
$tmp_path = $attachment_folder.DIRECTORY_SEPARATOR.$this->generateAttachmentFilename($attachment, 'tmp');
try {
$response = $this->httpClient->request('GET', $url, [
@ -296,14 +308,14 @@ class AttachmentSubmitHandler
}
//Rename the file to its new name and save path to attachment entity
$new_path = $attachment_folder.\DIRECTORY_SEPARATOR.$this->generateAttachmentFilename($attachment, $new_ext);
$new_path = $attachment_folder.DIRECTORY_SEPARATOR.$this->generateAttachmentFilename($attachment, $new_ext);
$fs->rename($tmp_path, $new_path);
//Make our file path relative to %BASE%
$new_path = $this->pathResolver->realPathToPlaceholder($new_path);
//Save the path to the attachment
$attachment->setPath($new_path);
} catch (TransportExceptionInterface $exception) {
} catch (TransportExceptionInterface $transportExceptionInterface) {
throw new AttachmentDownloadException('Transport error!');
}

View file

@ -25,7 +25,10 @@ declare(strict_types=1);
namespace App\Services\Attachments;
use App\Entity\Attachments\Attachment;
use InvalidArgumentException;
use Liip\ImagineBundle\Service\FilterService;
use RuntimeException;
use function strlen;
use Symfony\Component\Asset\Packages;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
@ -76,7 +79,7 @@ class AttachmentURLGenerator
}
//Return the part relative after public path.
return substr($absolute_path, \strlen($public_path) + 1);
return substr($absolute_path, strlen($public_path) + 1);
}
/**
@ -86,7 +89,7 @@ class AttachmentURLGenerator
{
$absolute_path = $this->attachmentHelper->toAbsoluteFilePath($attachment);
if (null === $absolute_path) {
throw new \RuntimeException('The given attachment is external or has no valid file, so no URL can get generated for it!
throw new RuntimeException('The given attachment is external or has no valid file, so no URL can get generated for it!
Use Attachment::getURL() to get the external URL!');
}
@ -106,7 +109,7 @@ class AttachmentURLGenerator
public function getThumbnailURL(Attachment $attachment, string $filter_name = 'thumbnail_sm'): string
{
if (! $attachment->isPicture()) {
throw new \InvalidArgumentException('Thumbnail creation only works for picture attachments!');
throw new InvalidArgumentException('Thumbnail creation only works for picture attachments!');
}
if ($attachment->isExternal()) {
@ -115,7 +118,7 @@ class AttachmentURLGenerator
$absolute_path = $this->attachmentHelper->toAbsoluteFilePath($attachment);
if (null === $absolute_path) {
throw new \RuntimeException('The given attachment is external or has no valid file, so no URL can get generated for it!');
throw new RuntimeException('The given attachment is external or has no valid file, so no URL can get generated for it!');
}
$asset_path = $this->absolutePathToAssetPath($absolute_path);

View file

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace App\Services\Attachments;
use App\Entity\Attachments\Attachment;
use Psr\Cache\InvalidArgumentException;
use Symfony\Component\Finder\Finder;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Contracts\Cache\CacheInterface;
@ -77,7 +78,7 @@ class BuiltinAttachmentsFinder
return $results;
});
} catch (\Psr\Cache\InvalidArgumentException $ex) {
} catch (InvalidArgumentException $invalidArgumentException) {
return [];
}
}

View file

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace App\Services\Attachments;
use App\Entity\Attachments\Attachment;
use function in_array;
use Symfony\Component\Mime\MimeTypesInterface;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\ItemInterface;
@ -72,9 +73,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;
}
}
@ -120,7 +121,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;
}
@ -157,7 +158,7 @@ class FileTypeFilterTools
$extensions = array_merge($extensions, static::AUDIO_EXTS);
} elseif ('image/*' === $element) {
$extensions = array_merge($extensions, static::VIDEO_EXTS);
} elseif (preg_match('/^[-\w.]+\/[-\w.*]+/', $element)) {
} elseif (preg_match('#^[-\w.]+\/[-\w.*]+#', $element)) {
$extensions = array_merge($extensions, $this->mimeTypes->getExtensions($element));
}
}
@ -178,6 +179,6 @@ class FileTypeFilterTools
{
$extension = strtolower($extension);
return empty($filter) || \in_array($extension, $this->resolveFileExtensions($filter), false);
return empty($filter) || in_array($extension, $this->resolveFileExtensions($filter), false);
}
}

View file

@ -24,19 +24,20 @@ declare(strict_types=1);
namespace App\Services;
use Closure;
use Symfony\Component\DependencyInjection\EnvVarProcessorInterface;
use Symfony\Component\DependencyInjection\Exception\EnvNotFoundException;
class CustomEnvVarProcessor implements EnvVarProcessorInterface
final class CustomEnvVarProcessor implements EnvVarProcessorInterface
{
public function getEnv($prefix, $name, \Closure $getEnv)
public function getEnv($prefix, $name, Closure $getEnv)
{
if ('validMailDSN' === $prefix) {
try {
$env = $getEnv($name);
return ! empty($env) && 'null://null' !== $env;
} catch (EnvNotFoundException $exception) {
} catch (EnvNotFoundException $envNotFoundException) {
return false;
}
}

View file

@ -42,6 +42,7 @@ use App\Entity\PriceInformations\Pricedetail;
use App\Entity\UserSystem\Group;
use App\Entity\UserSystem\User;
use App\Exceptions\EntityNotSupportedException;
use function get_class;
use Proxies\__CG__\App\Entity\Parts\Supplier;
use Symfony\Contracts\Translation\TranslatorInterface;
@ -90,8 +91,8 @@ class ElementTypeNameGenerator
public function getLocalizedTypeLabel(DBElement $entity): string
{
//Check if we have an direct array entry for our entity class, then we can use it
if (isset($this->mapping[\get_class($entity)])) {
return $this->mapping[\get_class($entity)];
if (isset($this->mapping[get_class($entity)])) {
return $this->mapping[get_class($entity)];
}
//Otherwise iterate over array and check for inheritance (needed when the proxy element from doctrine are passed)
@ -102,7 +103,7 @@ class ElementTypeNameGenerator
}
//When nothing was found throw an exception
throw new EntityNotSupportedException(sprintf('No localized label for the element with type %s was found!', \get_class($entity)));
throw new EntityNotSupportedException(sprintf('No localized label for the element with type %s was found!', get_class($entity)));
}
/**

View file

@ -25,6 +25,11 @@ declare(strict_types=1);
namespace App\Services;
use App\Entity\Base\NamedDBElement;
use function in_array;
use InvalidArgumentException;
use function is_array;
use ReflectionClass;
use ReflectionException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
@ -49,21 +54,21 @@ class EntityExporter
*
* @return Response the generated response containing the exported data
*
* @throws \ReflectionException
* @throws ReflectionException
*/
public function exportEntityFromRequest($entity, Request $request): Response
{
$format = $request->get('format') ?? 'json';
//Check if we have one of the supported formats
if (! \in_array($format, ['json', 'csv', 'yaml', 'xml'], true)) {
throw new \InvalidArgumentException('Given format is not supported!');
if (! in_array($format, ['json', 'csv', 'yaml', 'xml'], true)) {
throw new InvalidArgumentException('Given format is not supported!');
}
//Check export verbosity level
$level = $request->get('level') ?? 'extended';
if (! \in_array($level, ['simple', 'extended', 'full'], true)) {
throw new \InvalidArgumentException('Given level is not supported!');
if (! in_array($level, ['simple', 'extended', 'full'], true)) {
throw new InvalidArgumentException('Given level is not supported!');
}
//Check for include children option
@ -91,7 +96,7 @@ class EntityExporter
}
//Ensure that we always serialize an array. This makes it easier to import the data again.
if (\is_array($entity)) {
if (is_array($entity)) {
$entity_array = $entity;
} else {
$entity_array = [$entity];
@ -111,16 +116,16 @@ class EntityExporter
if (! $request->get('view')) {
if ($entity instanceof NamedDBElement) {
$entity_name = $entity->getName();
} elseif (\is_array($entity)) {
} elseif (is_array($entity)) {
if (empty($entity)) {
throw new \InvalidArgumentException('$entity must not be empty!');
throw new InvalidArgumentException('$entity must not be empty!');
}
//Use the class name of the first element for the filename
$reflection = new \ReflectionClass($entity[0]);
$reflection = new ReflectionClass($entity[0]);
$entity_name = $reflection->getShortName();
} else {
throw new \InvalidArgumentException('$entity type is not supported!');
throw new InvalidArgumentException('$entity type is not supported!');
}
$filename = 'export_'.$entity_name.'_'.$level.'.'.$format;

View file

@ -25,7 +25,10 @@ declare(strict_types=1);
namespace App\Services;
use App\Entity\Base\StructuralDBElement;
use function count;
use Doctrine\ORM\EntityManagerInterface;
use InvalidArgumentException;
use function is_array;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Serializer\SerializerInterface;
@ -61,10 +64,10 @@ class EntityImporter
$names = explode("\n", $lines);
if (! is_a($class_name, StructuralDBElement::class, true)) {
throw new \InvalidArgumentException('$class_name must be a StructuralDBElement type!');
throw new InvalidArgumentException('$class_name must be a StructuralDBElement type!');
}
if (null !== $parent && ! is_a($parent, $class_name)) {
throw new \InvalidArgumentException('$parent must have the same type as specified in $class_name!');
throw new InvalidArgumentException('$parent must have the same type as specified in $class_name!');
}
$errors = [];
@ -85,10 +88,13 @@ class EntityImporter
//Validate entity
$tmp = $this->validator->validate($entity);
//If no error occured, write entry to DB:
if (0 === \count($tmp)) {
if (0 === count($tmp)) {
$valid_entities[] = $entity;
} else { //Otherwise log error
$errors[] = ['entity' => $entity, 'violations' => $tmp];
$errors[] = [
'entity' => $entity,
'violations' => $tmp,
];
}
}
@ -127,7 +133,7 @@ class EntityImporter
$tmp = $this->validator->validate($entity);
//When no validation error occured, persist entity to database (cascade must be set in entity)
if (0 === \count($errors)) {
if (0 === count($errors)) {
$this->em->persist($entity);
} else { //Log validation errors to global log.
$errors[$entity->getFullPath()] = $tmp;
@ -171,10 +177,13 @@ class EntityImporter
//The [] behind class_name denotes that we expect an array.
$entities = $this->serializer->deserialize($content, $class_name.'[]', $options['format'],
['groups' => $groups, 'csv_delimiter' => $options['csv_separator']]);
[
'groups' => $groups,
'csv_delimiter' => $options['csv_separator'],
]);
//Ensure we have an array of entitity elements.
if (! \is_array($entities)) {
if (! is_array($entities)) {
$entities = [$entities];
}

View file

@ -40,6 +40,9 @@ use App\Entity\UserSystem\Group;
use App\Entity\UserSystem\User;
use App\Exceptions\EntityNotSupportedException;
use App\Services\Attachments\AttachmentURLGenerator;
use function array_key_exists;
use function get_class;
use InvalidArgumentException;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
/**
@ -49,11 +52,11 @@ use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
*/
class EntityURLGenerator
{
protected $attachmentURLGenerator;
/**
* @var UrlGeneratorInterface
*/
protected $urlGenerator;
protected $attachmentURLGenerator;
public function __construct(UrlGeneratorInterface $urlGenerator, AttachmentURLGenerator $attachmentURLGenerator)
{
@ -72,7 +75,7 @@ class EntityURLGenerator
* @return string the link to the desired page
*
* @throws EntityNotSupportedException thrown if the entity is not supported for the given type
* @throws \InvalidArgumentException thrown if the givent type is not existing
* @throws InvalidArgumentException thrown if the givent type is not existing
*/
public function getURL($entity, string $type)
{
@ -96,7 +99,7 @@ class EntityURLGenerator
return $this->viewURL($entity);
}
throw new \InvalidArgumentException('Method is not supported!');
throw new InvalidArgumentException('Method is not supported!');
}
public function viewURL($entity): string
@ -124,7 +127,7 @@ class EntityURLGenerator
}
//Otherwise throw an error
throw new EntityNotSupportedException(sprintf('The given entity is not supported yet! Passed class type: %s', \get_class($entity)));
throw new EntityNotSupportedException(sprintf('The given entity is not supported yet! Passed class type: %s', get_class($entity)));
}
/**
@ -290,10 +293,10 @@ class EntityURLGenerator
*/
protected function mapToController(array $map, $entity): string
{
$class = \get_class($entity);
$class = get_class($entity);
//Check if we have an direct mapping for the given class
if (! \array_key_exists($class, $map)) {
if (! array_key_exists($class, $map)) {
//Check if we need to check inheritance by looping through our map
foreach ($map as $key => $value) {
if (is_a($entity, $key)) {
@ -301,7 +304,7 @@ class EntityURLGenerator
}
}
throw new EntityNotSupportedException(sprintf('The given entity is not supported yet! Passed class type: %s', \get_class($entity)));
throw new EntityNotSupportedException(sprintf('The given entity is not supported yet! Passed class type: %s', get_class($entity)));
}
return $map[$class];

View file

@ -25,6 +25,8 @@ declare(strict_types=1);
namespace App\Services;
use App\Entity\Attachments\Attachment;
use function in_array;
use InvalidArgumentException;
class FAIconGenerator
{
@ -53,12 +55,12 @@ class FAIconGenerator
public function fileExtensionToFAType(string $extension): string
{
if ('' === $extension) {
throw new \InvalidArgumentException('You must specify an extension!');
throw new InvalidArgumentException('You must specify an extension!');
}
//Normalize file extension
$extension = strtolower($extension);
foreach (self::EXT_MAPPING as $fa => $exts) {
if (\in_array($extension, $exts, true)) {
if (in_array($extension, $exts, true)) {
return $fa;
}
}

View file

@ -26,6 +26,7 @@ namespace App\Services;
use App\Entity\PriceInformations\Currency;
use Locale;
use NumberFormatter;
class MoneyFormatter
{
@ -55,7 +56,7 @@ class MoneyFormatter
$iso_code = $currency->getIsoCode();
}
$number_formatter = new \NumberFormatter($this->locale, \NumberFormatter::CURRENCY);
$number_formatter = new NumberFormatter($this->locale, NumberFormatter::CURRENCY);
if ($show_all_digits) {
$number_formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $decimals);
} else {

View file

@ -32,7 +32,7 @@ use Symfony\Component\Translation\MessageCatalogue;
* The purpose of this class is to extract label attributes out of our permissions.yaml structure,
* so they can be translated.
*/
class PermissionExtractor implements ExtractorInterface
final class PermissionExtractor implements ExtractorInterface
{
protected $permission_structure;
protected $finished = false;