Fixed some more psalm issues.

This commit is contained in:
Jan Böhmer 2020-03-29 23:36:53 +02:00
parent cb0aa7bc7a
commit a28e81065f
11 changed files with 25 additions and 18 deletions

View file

@ -33,6 +33,8 @@ services:
bind:
bool $demo_mode: '%demo_mode%'
bool $gpdr_compliance : '%gpdr_compliance%'
bool $kernel_debug: '%kernel.debug%'
string $kernel_cache_dir: '%kernel.cache_dir%'
# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name

View file

@ -254,6 +254,7 @@ abstract class AbstractStructuralDBElement extends AttachmentContainingDBElement
* Get all sub elements of this element.
*
* @return Collection<static>|iterable all subelements as an array of objects (sorted by their full path)
* @psalm-return Collection<int, static>
*/
public function getSubelements(): iterable
{
@ -262,6 +263,7 @@ abstract class AbstractStructuralDBElement extends AttachmentContainingDBElement
/**
* @return Collection<static>|iterable
* @psalm-return Collection<int, static>
*/
public function getChildren(): iterable
{

View file

@ -31,7 +31,7 @@ trait ParametersTrait
/**
* Mapping done in subclasses.
*
* @var Collection<AbstractParameter>
* @var Collection<int, AbstractParameter>
* @Assert\Valid()
*/
protected $parameters;
@ -39,9 +39,9 @@ trait ParametersTrait
/**
* Return all associated specifications.
*
* @return \Doctrine\Common\Collections\Collection
* @return Collection
*
* @psalm-return \Doctrine\Common\Collections\Collection<int, PartParameter>
* @psalm-return Collection<int, PartParameter>
*/
public function getParameters(): \Doctrine\Common\Collections\Collection
{

View file

@ -45,14 +45,15 @@ namespace App\EventSubscriber;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
final class SymfonyDebugToolbarSubscriber implements EventSubscriberInterface
{
private $kernel;
private $kernel_debug;
public function __construct(ContainerInterface $kernel)
public function __construct(bool $kernel_debug)
{
$this->kernel = $kernel;
$this->kernel_debug = $kernel_debug;
}
/**
@ -78,9 +79,9 @@ final class SymfonyDebugToolbarSubscriber implements EventSubscriberInterface
return ['kernel.response' => 'onKernelResponse'];
}
public function onKernelResponse(FilterResponseEvent $event): void
public function onKernelResponse(ResponseEvent $event): void
{
if (! $this->kernel->getParameter('kernel.debug')) {
if (! $this->kernel_debug) {
return;
}

View file

@ -43,6 +43,7 @@ declare(strict_types=1);
namespace App\Security\Voter;
use App\Entity\UserSystem\User;
use App\Repository\UserRepository;
use App\Services\PermissionResolver;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
@ -76,6 +77,7 @@ abstract class ExtendedVoter extends Voter
// if the user is anonymous, we use the anonymous user.
if (! $user instanceof User) {
/** @var UserRepository $repo */
$repo = $this->entityManager->getRepository(User::class);
$user = $repo->getAnonymousUser();
if (null === $user) {

View file

@ -130,7 +130,7 @@ class AttachmentURLGenerator
throw new InvalidArgumentException('Thumbnail creation only works for picture attachments!');
}
if ($attachment->isExternal()) {
if ($attachment->isExternal() && !empty($attachment->getURL())) {
return $attachment->getURL();
}

View file

@ -43,10 +43,10 @@ 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;
use Psr\Cache\InvalidArgumentException;
/**
* This service is used to find builtin attachment ressources.

View file

@ -174,7 +174,7 @@ class FileTypeFilterTools
$extensions = array_merge($extensions, static::IMAGE_EXTS);
} elseif ('audio/*' === $element) {
$extensions = array_merge($extensions, static::AUDIO_EXTS);
} elseif ('image/*' === $element) {
} elseif ('video/*' === $element) {
$extensions = array_merge($extensions, static::VIDEO_EXTS);
} elseif (preg_match('#^[-\w.]+\/[-\w.*]+#', $element)) {
$extensions = array_merge($extensions, $this->mimeTypes->getExtensions($element));

View file

@ -102,7 +102,7 @@ class ElementTypeNameGenerator
* Useful when the type should be shown to user.
* Throws an exception if the class is not supported.
*
* @param AbstractDBElement|string $entity The element or class for which the label should be generated
* @param object|string $entity The element or class for which the label should be generated
*
* @return string the localized label for the entity type
*

View file

@ -94,12 +94,12 @@ class EntityURLGenerator
* @param mixed $entity The element for which the page should be generated
* @param string $type The page type. Currently supported: 'info', 'edit', 'create', 'clone', 'list'/'list_parts'
*
* @return string the link to the desired page
* @return null|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
*/
public function getURL($entity, string $type)
public function getURL($entity, string $type): ?string
{
switch ($type) {
case 'info':

View file

@ -62,12 +62,12 @@ class PermissionResolver
/**
* PermissionResolver constructor.
*/
public function __construct(ContainerInterface $container)
public function __construct(bool $kernel_debug, string $kernel_cache_dir)
{
$cache_dir = $container->getParameter('kernel.cache_dir');
$cache_dir = $kernel_cache_dir;
//Here the cached structure will be saved.
$this->cache_file = $cache_dir.'/permissions.php.cache';
$this->is_debug = $container->getParameter('kernel.debug');
$this->is_debug = $kernel_debug;
$this->permission_structure = $this->generatePermissionStructure();
@ -127,7 +127,7 @@ class PermissionResolver
return $allowed;
}
/** @var HasPermissionsInterface $parent */
/** @var Group $parent */
$parent = $user->getGroup();
while (null !== $parent) { //The top group, has parent == null
//Check if our current element gives a info about disallow/allow