CI: Fix Psalm checks

NoValue
UndefinedVariable
MissingTemplateParam
TooFewArguments
pull/6027/head
Angel Fernando Quiroz Campos 8 months ago
parent 985b98a971
commit 22eb233899
No known key found for this signature in database
GPG Key ID: B284841AE3E562CD
  1. 2
      src/CoreBundle/Decorator/OAuth2ProviderFactoryDecorator.php
  2. 2
      src/CoreBundle/Entity/User.php
  3. 26
      src/CoreBundle/Form/DataTransformer/ResourceToIdentifierTransformer.php
  4. 7
      src/CoreBundle/Repository/ResourceRepository.php
  5. 3
      src/CoreBundle/Security/Authorization/Voter/MessageRelUserVoter.php
  6. 4
      src/CoreBundle/ServiceHelper/ThemeHelper.php
  7. 7
      src/CoreBundle/Settings/CourseSettingsSchema.php
  8. 12
      src/CoreBundle/State/SocialPostStateProvider.php
  9. 8
      tests/CourseBundle/Repository/CDocumentRepositoryTest.php

@ -55,7 +55,7 @@ readonly class OAuth2ProviderFactoryDecorator
Facebook::class => $this->authenticationConfigHelper->getProviderOptions('facebook', $customConfig),
Keycloak::class => $this->authenticationConfigHelper->getProviderOptions('keycloak', $customConfig),
Azure::class => $this->authenticationConfigHelper->getProviderOptions('azure', $customConfig),
default => throw new \InvalidArgumentException("Unsupported provider class: $class"),
default => throw new InvalidArgumentException("Unsupported provider class: $class"),
};
$options = $customOptions + $options;

@ -2412,6 +2412,6 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso
public function isCourseTutor(?Course $course = null, ?Session $session = null): bool
{
return $session?->hasCoachInCourseList($user) || $course?->getSubscriptionByUser($user)?->isTutor();
return $session?->hasCoachInCourseList($this) || $course?->getSubscriptionByUser($this)?->isTutor();
}
}

@ -7,9 +7,10 @@ namespace Chamilo\CoreBundle\Form\DataTransformer;
use Doctrine\Persistence\ObjectRepository;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\PropertyAccess\PropertyAccess;
/**
* @template-implements DataTransformerInterface<object, int|string>
* @implements DataTransformerInterface<object, int|string|null>
*/
final class ResourceToIdentifierTransformer implements DataTransformerInterface
{
@ -25,34 +26,27 @@ final class ResourceToIdentifierTransformer implements DataTransformerInterface
public function transform($value): mixed
{
if (null === $value) {
if (empty($value)) {
return null;
}
if (\is_object($value) && method_exists($value, 'getId')) {
return $value;
}
if (is_numeric($value)) {
return $this->repository->find($value);
}
\assert(get_class($value) === $this->repository->getClassName());
return $value;
return PropertyAccess::createPropertyAccessor()->getValue($value, $this->identifier);
}
public function reverseTransform($value): mixed
{
if (null === $value || '' === $value) {
if (empty($value)) {
return null;
}
if (\is_object($value) && method_exists($value, 'getId')) {
return $value;
}
$resource = $this->repository->findOneBy([
$this->identifier => $value,
]);
$resource = $this->repository->find($value);
if (null === $resource) {
throw new TransformationFailedException(\sprintf('Object "%s" with identifier "%s" does not exist.', $this->repository->getClassName(), $value));
throw new TransformationFailedException(\sprintf('Object "%s" with identifier "%s"="%s" does not exist.', $this->repository->getClassName(), $this->identifier, $value));
}
return $resource;

@ -585,8 +585,11 @@ abstract class ResourceRepository extends ServiceEntityRepository
}
}
public function toggleVisibilityPublishedDraft(AbstractResource $resource, ?Course $course, ?Session $session): void
{
public function toggleVisibilityPublishedDraft(
AbstractResource $resource,
?Course $course = null,
?Session $session = null
): void {
$firstLink = $resource->getFirstResourceLink();
if (ResourceLink::VISIBILITY_PUBLISHED === $firstLink->getVisibility()) {

@ -13,6 +13,9 @@ use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @extends Voter<'DELETE'|'VIEW'|'EDIT', MessageRelUser>
*/
class MessageRelUserVoter extends Voter
{
public const DELETE = 'DELETE';

@ -10,7 +10,6 @@ use Chamilo\CoreBundle\Settings\SettingsManager;
use Chamilo\CourseBundle\Settings\SettingsCourseManager;
use League\Flysystem\FilesystemException;
use League\Flysystem\FilesystemOperator;
use League\Flysystem\UnableToReadFile;
use League\MimeTypeDetection\ExtensionMimeTypeDetector;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
@ -78,7 +77,6 @@ final class ThemeHelper
/**
* @throws FilesystemException
* @throws UnableToCheckExistence
*/
public function getFileLocation(string $path): ?string
{
@ -140,7 +138,7 @@ final class ThemeHelper
return $contents;
}
} catch (FilesystemException|UnableToReadFile) {
} catch (FilesystemException) {
return '';
}

@ -9,6 +9,7 @@ namespace Chamilo\CoreBundle\Settings;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Form\DataTransformer\ResourceToIdentifierTransformer;
use Chamilo\CoreBundle\Form\Type\YesNoType;
use Chamilo\CoreBundle\Repository\Node\CourseRepository;
use Chamilo\CoreBundle\Tool\AbstractTool;
use Chamilo\CoreBundle\Tool\ToolChain;
use Chamilo\CoreBundle\Transformer\ArrayToIdentifierTransformer;
@ -24,6 +25,10 @@ class CourseSettingsSchema extends AbstractSettingsSchema
{
protected ToolChain $toolChain;
public function __construct(
private readonly CourseRepository $courseRepository,
) {}
public function getProcessedToolChain(): array
{
$tools = [];
@ -132,7 +137,7 @@ class CourseSettingsSchema extends AbstractSettingsSchema
)
->setTransformer(
'course_creation_use_template',
new ResourceToIdentifierTransformer($this->getRepository(), 'id')
new ResourceToIdentifierTransformer($this->courseRepository, 'id')
)
;

@ -9,18 +9,22 @@ namespace Chamilo\CoreBundle\State;
use ApiPlatform\Metadata\CollectionOperationInterface;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProviderInterface;
use Chamilo\CoreBundle\Entity\SocialPost;
use Chamilo\CoreBundle\Settings\SettingsManager;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
class SocialPostStateProvider implements ProviderInterface
/**
* @template-implements ProviderInterface<SocialPost>
*/
readonly class SocialPostStateProvider implements ProviderInterface
{
public function __construct(
#[Autowire(service: 'api_platform.doctrine.orm.state.item_provider')]
private readonly ProviderInterface $itemProvider,
private ProviderInterface $itemProvider,
#[Autowire(service: 'api_platform.doctrine.orm.state.collection_provider')]
private readonly ProviderInterface $collectionProvider,
private readonly SettingsManager $settingsManager,
private ProviderInterface $collectionProvider,
private SettingsManager $settingsManager,
) {}
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null

@ -983,7 +983,11 @@ class CDocumentRepositoryTest extends AbstractApiTest
public function testSetVisibility(): void
{
$course = $this->createCourse('Test');
/** @var CDocumentRepository $documentRepo */
$documentRepo = self::getContainer()->get(CDocumentRepository::class);
/** @var ResourceLinkRepository $linksRepo */
$linksRepo = self::getContainer()->get(ResourceLinkRepository::class);
$admin = $this->getUser('admin');
@ -1020,12 +1024,12 @@ class CDocumentRepositoryTest extends AbstractApiTest
$this->assertSame(ResourceLink::VISIBILITY_DRAFT, $link->getVisibility());
$this->assertSame('Draft', $link->getVisibilityName());
$documentRepo->toggleVisibilityPublishedDraft($document);
$documentRepo->toggleVisibilityPublishedDraft($document, $course);
$link = $document->getFirstResourceLink();
$this->assertSame(ResourceLink::VISIBILITY_PUBLISHED, $link->getVisibility());
$this->assertSame('Published', $link->getVisibilityName());
$documentRepo->toggleVisibilityPublishedDraft($document);
$documentRepo->toggleVisibilityPublishedDraft($document, $course);
$link = $document->getFirstResourceLink();
$this->assertSame(ResourceLink::VISIBILITY_DRAFT, $link->getVisibility());

Loading…
Cancel
Save