Fixed some inspection issues.

This commit is contained in:
Jan Böhmer 2020-08-21 22:43:37 +02:00
parent 6caf605fe2
commit e01b06fb85
80 changed files with 173 additions and 218 deletions

View file

@ -70,7 +70,7 @@ class AmountFormatter
*
* @throws InvalidArgumentException thrown if $value is not numeric
*/
public function format($value, ?MeasurementUnit $unit = null, array $options = [])
public function format($value, ?MeasurementUnit $unit = null, array $options = []): string
{
if (!is_numeric($value)) {
throw new InvalidArgumentException('$value must be an numeric value!');
@ -106,7 +106,7 @@ class AmountFormatter
protected function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'show_prefix' => function (Options $options) {
'show_prefix' => static function (Options $options) {
if (null !== $options['measurement_unit']) {
/** @var MeasurementUnit $unit */
$unit = $options['measurement_unit'];
@ -116,7 +116,7 @@ class AmountFormatter
return false;
},
'is_integer' => function (Options $options) {
'is_integer' => static function (Options $options) {
if (null !== $options['measurement_unit']) {
/** @var MeasurementUnit $unit */
$unit = $options['measurement_unit'];
@ -126,7 +126,7 @@ class AmountFormatter
return true;
},
'unit' => function (Options $options) {
'unit' => static function (Options $options) {
if (null !== $options['measurement_unit']) {
/** @var MeasurementUnit $unit */
$unit = $options['measurement_unit'];
@ -144,7 +144,7 @@ class AmountFormatter
$resolver->setAllowedTypes('decimals', 'int');
$resolver->setNormalizer('decimals', function (Options $options, $value) {
$resolver->setNormalizer('decimals', static function (Options $options, $value) {
// If the unit is integer based, then dont show any decimals
if ($options['is_integer']) {
return 0;

View file

@ -48,7 +48,6 @@ use Doctrine\ORM\EntityManagerInterface;
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
use SplFileInfo;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\File\File;
/**
* This service provides functions to find attachments via an reverse search based on a file.

View file

@ -92,7 +92,7 @@ class FileTypeFilterTools
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
&& !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;
}
@ -176,7 +176,7 @@ class FileTypeFilterTools
$extensions = array_merge($extensions, static::AUDIO_EXTS);
} elseif ('video/*' === $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));
}
}

View file

@ -59,9 +59,10 @@ final class CustomEnvVarProcessor implements EnvVarProcessorInterface
return false;
}
}
return false;
}
public static function getProvidedTypes()
public static function getProvidedTypes(): array
{
return [
'validMailDSN' => 'bool',

View file

@ -51,13 +51,6 @@ use ReflectionException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\Serializer\Encoder\CsvEncoder;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
use Symfony\Component\Serializer\Encoder\YamlEncoder;
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\SerializerInterface;
/**
@ -166,7 +159,7 @@ class EntityExporter
$disposition = $response->headers->makeDisposition(
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
$filename,
$string = preg_replace('![^'.preg_quote('-').'a-z0-_9\s]+!', '', strtolower($filename))
$string = preg_replace('![^'.preg_quote('-','!').'a-z0-_9\s]+!', '', strtolower($filename))
);
// Set the content disposition
$response->headers->set('Content-Disposition', $disposition);

View file

@ -151,7 +151,7 @@ class EntityImporter
$tmp = $this->validator->validate($entity);
//When no validation error occured, persist entity to database (cascade must be set in entity)
if (empty($tmp)) {
if ($tmp === null) {
$this->em->persist($entity);
} else { //Log validation errors to global log.
$errors[$entity->getFullPath()] = $tmp;

View file

@ -58,7 +58,7 @@ class GitVersionInfo
*
* @return string|null The current git branch name. Null, if this is no Git installation
*/
public function getGitBranchName()
public function getGitBranchName(): ?string
{
if (is_file($this->project_dir.'/.git/HEAD')) {
$git = file($this->project_dir.'/.git/HEAD');
@ -83,7 +83,7 @@ class GitVersionInfo
*
* @return string|null The hash of the last commit, null If this is no Git installation
*/
public function getGitCommitHash(int $length = 7)
public function getGitCommitHash(int $length = 7): ?string
{
$filename = $this->project_dir.'/.git/refs/remotes/origin/'.$this->getGitBranchName();
if (is_file($filename)) {

View file

@ -78,7 +78,7 @@ final class LabelGenerator
*
* @return bool
*/
public function supports(LabelOptions $options, object $element)
public function supports(LabelOptions $options, object $element): bool
{
$supported_type = $options->getSupportedElement();
if (!isset(static::CLASS_SUPPORT_MAPPING[$supported_type])) {

View file

@ -68,7 +68,7 @@ final class LabelHTMLGenerator
$page = 1;
foreach ($elements as $element) {
if ('twig' === $options->getLinesMode() && isset($sandboxed_twig) && isset($current_user)) {
if (isset($sandboxed_twig, $current_user) && 'twig' === $options->getLinesMode()) {
try {
$lines = $sandboxed_twig->render(
'lines',
@ -103,7 +103,7 @@ final class LabelHTMLGenerator
]);
}
private function getPDFTitle(LabelOptions $options, object $element)
private function getPDFTitle(LabelOptions $options, object $element): string
{
if ($element instanceof NamedElementInterface) {
return $this->elementTypeNameGenerator->getTypeNameCombination($element, false);

View file

@ -44,7 +44,7 @@ final class PartLotProvider implements PlaceholderProviderInterface
{
if ($label_target instanceof PartLot) {
if ('[[LOT_ID]]' === $placeholder) {
return $label_target->getID() ?? 'unknown';
return (string) ($label_target->getID() ?? 'unknown');
}
if ('[[LOT_NAME]]' === $placeholder) {

View file

@ -147,13 +147,11 @@ class LogEntryExtraFormatter
);
}
if ($context instanceof LogWithEventUndoInterface) {
if ($context->isUndoEvent()) {
if ('undo' === $context->getUndoMode()) {
$array['log.undo_mode.undo'] = (string) $context->getUndoEventID();
} elseif ('revert' === $context->getUndoMode()) {
$array['log.undo_mode.revert'] = (string) $context->getUndoEventID();
}
if (($context instanceof LogWithEventUndoInterface) && $context->isUndoEvent()) {
if ('undo' === $context->getUndoMode()) {
$array['log.undo_mode.undo'] = (string) $context->getUndoEventID();
} elseif ('revert' === $context->getUndoMode()) {
$array['log.undo_mode.revert'] = (string) $context->getUndoEventID();
}
}
@ -192,7 +190,7 @@ class LogEntryExtraFormatter
$array['log.collection_deleted.deleted'] = sprintf(
'%s: %s (%s)',
$this->elementTypeNameGenerator->getLocalizedTypeLabel($context->getDeletedElementClass()),
$context->getOldName() ?? $context->getDeletedElementID(),
$context->getOldName() ?? (string) $context->getDeletedElementID(),
$context->getCollectionName()
);
}

View file

@ -152,11 +152,12 @@ class TimeTravel
foreach ($target_elements as $target_element) {
if (null !== $target_element && $element->getLastModified() >= $timestamp) {
//Remove the element from collection, if it did not existed at $timestamp
if (!$this->repo->getElementExistedAtTimestamp($target_element, $timestamp)) {
if ($target_elements instanceof Collection) {
if (!$this->repo->getElementExistedAtTimestamp(
$target_element,
$timestamp
) && $target_elements instanceof Collection) {
$target_elements->removeElement($target_element);
}
}
$this->revertEntityToTimestamp($target_element, $timestamp, $reverted_elements);
}
}
@ -183,11 +184,9 @@ class TimeTravel
foreach ($old_data as $field => $data) {
if ($metadata->hasField($field)) {
if ('big_decimal' === $metadata->getFieldMapping($field)['type']) {
//We need to convert the string to a BigDecimal first
if (!$data instanceof BigDecimal) {
$data = BigDecimal::of($data);
}
//We need to convert the string to a BigDecimal first
if (!$data instanceof BigDecimal && ('big_decimal' === $metadata->getFieldMapping($field)['type'])) {
$data = BigDecimal::of($data);
}
$this->setField($element, $field, $data);

View file

@ -67,7 +67,7 @@ class MoneyFormatter
*
* @return string
*/
public function format($value, ?Currency $currency = null, $decimals = 5, bool $show_all_digits = false)
public function format($value, ?Currency $currency = null, $decimals = 5, bool $show_all_digits = false): string
{
$iso_code = $this->base_currency;
if (null !== $currency && !empty($currency->getIsoCode())) {

View file

@ -85,7 +85,7 @@ class PricedetailHelper
} else {
// We have to sort the pricedetails manually
$array = $pricedetails->map(
function (Pricedetail $pricedetail) {
static function (Pricedetail $pricedetail) {
return $pricedetail->getMinDiscountQuantity();
}
)->toArray();

View file

@ -66,7 +66,7 @@ class TagFinder
*
* @return string[] an array containing the tags that match the given keyword
*/
public function searchTags(string $keyword, array $options = [])
public function searchTags(string $keyword, array $options = []): array
{
$results = [];
$keyword_regex = '/^'.preg_quote($keyword, '/').'/';

View file

@ -124,7 +124,7 @@ class TreeViewGenerator
}
//Translate text if text starts with $$
if ('$$' === substr($item->getText(), 0, 2)) {
if (strpos($item->getText(), '$$') === 0) {
$item->setText($this->translator->trans(substr($item->getText(), 2)));
}
}