mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-10 10:24:31 +02:00
Fixed some more phpstan issues
This commit is contained in:
parent
2f46fbfc7a
commit
e8771ea118
77 changed files with 192 additions and 109 deletions
|
@ -220,7 +220,7 @@ class AttachmentSubmitHandler
|
|||
|
||||
|
||||
//Check if the extension is blacklisted and replace the file extension with txt if needed
|
||||
if(in_array($ext, self::BLACKLISTED_EXTENSIONS)) {
|
||||
if(in_array($ext, self::BLACKLISTED_EXTENSIONS, true)) {
|
||||
$new_path = $this->generateAttachmentPath($attachment, $attachment->isSecure())
|
||||
.DIRECTORY_SEPARATOR.$this->generateAttachmentFilename($attachment, 'txt');
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ class FileTypeFilterTools
|
|||
$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
|
||||
&& !in_array($element, static::ALLOWED_MIME_PLACEHOLDERS, true)) { //image/* is allowed
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -173,6 +173,6 @@ class FileTypeFilterTools
|
|||
{
|
||||
$extension = strtolower($extension);
|
||||
|
||||
return $filter === '' || in_array($extension, $this->resolveFileExtensions($filter), false);
|
||||
return $filter === '' || in_array($extension, $this->resolveFileExtensions($filter), true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ class ElementTypeNameGenerator
|
|||
*
|
||||
* @throws EntityNotSupportedException when the passed entity is not supported
|
||||
*/
|
||||
public function getLocalizedTypeLabel($entity): string
|
||||
public function getLocalizedTypeLabel(object|string $entity): string
|
||||
{
|
||||
$class = is_string($entity) ? $entity : $entity::class;
|
||||
|
||||
|
@ -105,8 +105,8 @@ class ElementTypeNameGenerator
|
|||
}
|
||||
|
||||
//Otherwise iterate over array and check for inheritance (needed when the proxy element from doctrine are passed)
|
||||
foreach ($this->mapping as $class => $translation) {
|
||||
if (is_a($entity, $class, true)) {
|
||||
foreach ($this->mapping as $class_to_check => $translation) {
|
||||
if (is_a($entity, $class_to_check, true)) {
|
||||
return $translation;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -172,7 +172,7 @@ class EntityURLGenerator
|
|||
return $entity->getURL();
|
||||
}
|
||||
|
||||
return $this->attachmentURLGenerator->getDownloadURL($entity) ?? '';
|
||||
return $this->attachmentURLGenerator->getDownloadURL($entity);
|
||||
}
|
||||
|
||||
//Otherwise throw an error
|
||||
|
|
|
@ -99,7 +99,6 @@ final class BarcodeGenerator
|
|||
BarcodeType::CODE39 => 'C39',
|
||||
BarcodeType::CODE93 => 'C93',
|
||||
BarcodeType::CODE128 => 'C128A',
|
||||
default => throw new InvalidArgumentException('Unknown label type!'),
|
||||
};
|
||||
|
||||
if ($type === null) {
|
||||
|
|
|
@ -62,7 +62,6 @@ final class LabelExampleElementsGenerator
|
|||
LabelSupportedElement::PART => $this->getExamplePart(),
|
||||
LabelSupportedElement::PART_LOT => $this->getExamplePartLot(),
|
||||
LabelSupportedElement::STORELOCATION => $this->getStorelocation(),
|
||||
default => throw new InvalidArgumentException('Unknown $type.'),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ class LogTargetHelper
|
|||
if (!$target instanceof AbstractDBElement) {
|
||||
if ($context->hasTarget()) {
|
||||
return $this->elementTypeNameGenerator->formatElementDeletedHTML($context->getTargetClass(),
|
||||
$context->getTargetId());
|
||||
$context->getTargetID());
|
||||
}
|
||||
//If no target is set, we can't do anything
|
||||
return '';
|
||||
|
|
|
@ -64,7 +64,7 @@ class ProjectBuildHelper
|
|||
public function getMaximumBuildableCount(Project $project): int
|
||||
{
|
||||
$maximum_buildable_count = PHP_INT_MAX;
|
||||
foreach ($project->getBOMEntries() as $bom_entry) {
|
||||
foreach ($project->getBomEntries() as $bom_entry) {
|
||||
//Skip BOM entries without a part (as we can not determine that)
|
||||
if (!$bom_entry->isPartBomEntry()) {
|
||||
continue;
|
||||
|
|
|
@ -172,19 +172,13 @@ class PermissionPresetsHelper
|
|||
return $perm_holder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @phpstan-api
|
||||
*/
|
||||
private function AllForbid(HasPermissionsInterface $perm_holder): HasPermissionsInterface
|
||||
private function allForbid(HasPermissionsInterface $perm_holder): HasPermissionsInterface
|
||||
{
|
||||
$this->permissionResolver->setAllPermissions($perm_holder, PermissionData::DISALLOW);
|
||||
return $perm_holder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @phpstan-api
|
||||
*/
|
||||
private function AllAllow(HasPermissionsInterface $perm_holder): HasPermissionsInterface
|
||||
private function allAllow(HasPermissionsInterface $perm_holder): HasPermissionsInterface
|
||||
{
|
||||
$this->permissionResolver->setAllPermissions($perm_holder, PermissionData::ALLOW);
|
||||
return $perm_holder;
|
||||
|
|
|
@ -65,8 +65,6 @@ class PermissionSchemaUpdater
|
|||
$reflectionClass = new \ReflectionClass(self::class);
|
||||
try {
|
||||
$method = $reflectionClass->getMethod('upgradeSchemaToVersion'.($n + 1));
|
||||
//Set the method accessible, so we can call it (needed for PHP < 8.1)
|
||||
$method->setAccessible(true);
|
||||
$method->invoke($this, $holder);
|
||||
} catch (\ReflectionException $e) {
|
||||
throw new \RuntimeException('Could not find update method for schema version '.($n + 1), $e->getCode(), $e);
|
||||
|
@ -114,7 +112,7 @@ class PermissionSchemaUpdater
|
|||
return $updated;
|
||||
}
|
||||
|
||||
private function upgradeSchemaToVersion1(HasPermissionsInterface $holder): void
|
||||
private function upgradeSchemaToVersion1(HasPermissionsInterface $holder): void //@phpstan-ignore-line This is called via reflection
|
||||
{
|
||||
//Use the part edit permission to set the preset value for the new part stock permission
|
||||
if (
|
||||
|
@ -131,7 +129,7 @@ class PermissionSchemaUpdater
|
|||
}
|
||||
}
|
||||
|
||||
private function upgradeSchemaToVersion2(HasPermissionsInterface $holder): void
|
||||
private function upgradeSchemaToVersion2(HasPermissionsInterface $holder): void //@phpstan-ignore-line This is called via reflection
|
||||
{
|
||||
//If the projects permissions are not defined yet, rename devices permission to projects (just copy its data over)
|
||||
if (!$holder->getPermissions()->isAnyOperationOfPermissionSet('projects')) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue