mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-10 10:24:31 +02:00
Fixed some PHPStan level 5 issues
This commit is contained in:
parent
74051c5649
commit
19530a9102
35 changed files with 95 additions and 63 deletions
|
@ -26,6 +26,7 @@ use App\Entity\Attachments\AttachmentContainingDBElement;
|
|||
use App\Entity\Attachments\Attachment;
|
||||
use App\Entity\Attachments\AttachmentType;
|
||||
use App\Entity\Base\AbstractDBElement;
|
||||
use App\Entity\Base\AbstractNamedDBElement;
|
||||
use App\Entity\Contracts\NamedElementInterface;
|
||||
use App\Entity\ProjectSystem\Project;
|
||||
use App\Entity\LabelSystem\LabelProfile;
|
||||
|
@ -180,7 +181,7 @@ class ElementTypeNameGenerator
|
|||
$on = $entity->getProject();
|
||||
}
|
||||
|
||||
if (isset($on) && is_object($on)) {
|
||||
if (isset($on) && $on instanceof NamedElementInterface) {
|
||||
try {
|
||||
$tmp .= sprintf(
|
||||
' (<a href="%s">%s</a>)',
|
||||
|
|
|
@ -132,6 +132,14 @@ final class LabelExampleElementsGenerator
|
|||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T of AbstractStructuralDBElement
|
||||
* @param string $class
|
||||
* @phpstan-param class-string<T> $class
|
||||
* @return AbstractStructuralDBElement
|
||||
* @phpstan-return T
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
private function getStructuralData(string $class): AbstractStructuralDBElement
|
||||
{
|
||||
if (!is_a($class, AbstractStructuralDBElement::class, true)) {
|
||||
|
|
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
|||
*/
|
||||
namespace App\Services\LabelSystem\PlaceholderProviders;
|
||||
|
||||
use App\Entity\LabelSystem\BarcodeType;
|
||||
use App\Entity\LabelSystem\LabelOptions;
|
||||
use App\Services\LabelSystem\BarcodeGenerator;
|
||||
use App\Services\LabelSystem\Barcodes\BarcodeContentGenerator;
|
||||
|
@ -52,19 +53,19 @@ final class BarcodeProvider implements PlaceholderProviderInterface
|
|||
|
||||
if ('[[BARCODE_QR]]' === $placeholder) {
|
||||
$label_options = new LabelOptions();
|
||||
$label_options->setBarcodeType('qr');
|
||||
$label_options->setBarcodeType(BarcodeType::QR);
|
||||
return $this->barcodeGenerator->generateHTMLBarcode($label_options, $label_target);
|
||||
}
|
||||
|
||||
if ('[[BARCODE_C39]]' === $placeholder) {
|
||||
$label_options = new LabelOptions();
|
||||
$label_options->setBarcodeType('code39');
|
||||
$label_options->setBarcodeType(BarcodeType::CODE39);
|
||||
return $this->barcodeGenerator->generateHTMLBarcode($label_options, $label_target);
|
||||
}
|
||||
|
||||
if ('[[BARCODE_C128]]' === $placeholder) {
|
||||
$label_options = new LabelOptions();
|
||||
$label_options->setBarcodeType('code128');
|
||||
$label_options->setBarcodeType(BarcodeType::CODE128);
|
||||
return $this->barcodeGenerator->generateHTMLBarcode($label_options, $label_target);
|
||||
}
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ class TimeTravel
|
|||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function revertEntityToTimestamp(AbstractDBElement $element, DateTime $timestamp, array $reverted_elements = []): void
|
||||
public function revertEntityToTimestamp(AbstractDBElement $element, \DateTimeInterface $timestamp, array $reverted_elements = []): void
|
||||
{
|
||||
if (!$element instanceof TimeStampableInterface) {
|
||||
throw new InvalidArgumentException('$element must have a Timestamp!');
|
||||
|
@ -228,7 +228,7 @@ class TimeTravel
|
|||
$this->setField($element, 'lastModified', $logEntry->getTimestamp());
|
||||
}
|
||||
|
||||
protected function getField(AbstractDBElement $element, string $field)
|
||||
protected function getField(AbstractDBElement $element, string $field): mixed
|
||||
{
|
||||
$reflection = new ReflectionClass($element::class);
|
||||
$property = $reflection->getProperty($field);
|
||||
|
@ -237,7 +237,7 @@ class TimeTravel
|
|||
return $property->getValue($element);
|
||||
}
|
||||
|
||||
protected function setField(AbstractDBElement $element, string $field, \DateTime|int|null $new_value): void
|
||||
protected function setField(AbstractDBElement $element, string $field, mixed $new_value): void
|
||||
{
|
||||
$reflection = new ReflectionClass($element::class);
|
||||
$property = $reflection->getProperty($field);
|
||||
|
|
|
@ -112,7 +112,7 @@ class PermissionManager
|
|||
|
||||
/** @var Group $parent */
|
||||
$parent = $user->getGroup();
|
||||
while ($parent instanceof AbstractStructuralDBElement) { //The top group, has parent == null
|
||||
while ($parent instanceof Group) { //The top group, has parent == null
|
||||
//Check if our current element gives an info about disallow/allow
|
||||
$allowed = $this->dontInherit($parent, $permission, $operation);
|
||||
if (null !== $allowed) {
|
||||
|
|
|
@ -172,12 +172,18 @@ class PermissionPresetsHelper
|
|||
return $perm_holder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @phpstan-api
|
||||
*/
|
||||
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
|
||||
{
|
||||
$this->permissionResolver->setAllPermissions($perm_holder, PermissionData::ALLOW);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue