Skip to content

Commit

Permalink
Update new services with prophecy and phpstan issues
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Mar 18, 2023
1 parent 9d407e0 commit 3aac8a0
Show file tree
Hide file tree
Showing 25 changed files with 87 additions and 48 deletions.
Expand Up @@ -31,7 +31,9 @@ public function map(
}

/**
* @param WorkflowInterface&DimensionContentInterface $object
* @template T of DimensionContentInterface
*
* @param WorkflowInterface&T $object
* @param mixed[] $data
*/
private function setWorkflowData(WorkflowInterface $object, array $data): void
Expand All @@ -41,7 +43,9 @@ private function setWorkflowData(WorkflowInterface $object, array $data): void
}

/**
* @param WorkflowInterface&DimensionContentInterface $object
* @template T of DimensionContentInterface
*
* @param WorkflowInterface&T $object
* @param mixed[] $data
*/
private function setInitialPlaceToDraftDimension(WorkflowInterface $object, array $data): void
Expand All @@ -61,7 +65,9 @@ private function setInitialPlaceToDraftDimension(WorkflowInterface $object, arra
}

/**
* @param WorkflowInterface&DimensionContentInterface $object
* @template T of DimensionContentInterface
*
* @param WorkflowInterface&T $object
* @param mixed[] $data
*/
private function setPublishedToLiveDimension(WorkflowInterface $object, array $data): void
Expand Down
Expand Up @@ -81,7 +81,7 @@ public function onUnpublish(TransitionEvent $transitionEvent): void
$unlocalizedLiveDimensionAttributes = \array_merge($liveDimensionAttributes, ['locale' => null]);

/** @var DimensionContentInterface $unlocalizedLiveDimensionContent */
$unlocalizedLiveDimensionContent = $dimensionContentCollection->getDimensionContent($unlocalizedLiveDimensionAttributes);
$unlocalizedLiveDimensionContent = $dimensionContentCollection->getDimensionContent($unlocalizedLiveDimensionAttributes); // @phpstan-ignore-line we can not define the generic of DimensionContentInterface here
$unlocalizedLiveDimensionContent->removeAvailableLocale($locale);
}

Expand Down
Expand Up @@ -71,6 +71,7 @@ public function create(
}

$localizedDimensionContent = null;
/** @var string|null $locale */
$locale = $dimensionAttributes['locale'] ?? null;
if ($locale) {
$localizedDimensionContent = $dimensionContentCollection->getDimensionContent($dimensionAttributes);
Expand Down
Expand Up @@ -76,7 +76,9 @@ public function __construct(
* TODO it should be possible to add custom filters for all contents here example when the
* excerpt tab and entity get extended with an additional field.
*
* @param class-string<DimensionContentInterface> $dimensionContentClassName
* @template T of DimensionContentInterface
*
* @param class-string<T> $dimensionContentClassName
* @param array{
* locale?: string|null,
* stage?: string|null,
Expand Down Expand Up @@ -238,7 +240,9 @@ private function addJoinFilter(
* TODO it should be possible to add custom select for all contents here example when the
* excerpt tab and entity get extended with additional relation.
*
* @param class-string<DimensionContentInterface> $dimensionContentClassName
* @template T of DimensionContentInterface
*
* @param class-string<T> $dimensionContentClassName
* @param mixed[] $dimensionAttributes
* @param array{
* content_admin?: bool,
Expand Down
2 changes: 1 addition & 1 deletion Content/Infrastructure/Doctrine/MetadataLoader.php
Expand Up @@ -127,7 +127,7 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $event): void
* @param ClassMetadataInfo<object> $metadata
* @param class-string $class
*/
private function addManyToOne(// @phpstan-ignore-line ignore unused method
private function addManyToOne(
LoadClassMetadataEventArgs $event,
ClassMetadataInfo $metadata,
string $name,
Expand Down
2 changes: 1 addition & 1 deletion Content/Infrastructure/Doctrine/RouteRemover.php
Expand Up @@ -82,7 +82,7 @@ public function preRemove(LifecycleEventArgs $event): void
return;
}

foreach ($this->routeRepository->findAllByEntity($entityClass, $object->getId()) as $route) {
foreach ($this->routeRepository->findAllByEntity($entityClass, (string) $object->getId()) as $route) {
$event->getEntityManager()->remove($route);
}
}
Expand Down
Expand Up @@ -297,6 +297,7 @@ private function createSettingsFormView(
string $dimensionContentClass
): ViewBuilderInterface {
$forms = [];
/** @var array{instanceOf: class-string} $tag */
foreach ($this->settingsForms as $key => $tag) {
if (\is_subclass_of($dimensionContentClass, $tag['instanceOf'])) {
$forms[] = $key;
Expand Down
8 changes: 7 additions & 1 deletion Content/Infrastructure/Sulu/Link/ContentLinkProvider.php
Expand Up @@ -24,6 +24,9 @@
use Sulu\Bundle\MarkupBundle\Markup\Link\LinkProviderInterface;
use Sulu\Component\Content\Metadata\Factory\StructureMetadataFactoryInterface;

/**
* @template T of ContentRichEntityInterface
*/
abstract class ContentLinkProvider implements LinkProviderInterface
{
use FindContentRichEntitiesTrait;
Expand All @@ -46,10 +49,13 @@ abstract class ContentLinkProvider implements LinkProviderInterface
protected $entityManager;

/**
* @var string
* @var class-string<T>
*/
protected $contentRichEntityClass;

/**
* @param class-string<T> $contentRichEntityClass
*/
public function __construct(
ContentManagerInterface $contentManager,
StructureMetadataFactoryInterface $structureMetadataFactory,
Expand Down
Expand Up @@ -17,12 +17,17 @@
use Sulu\Bundle\ContentBundle\Content\Application\ContentWorkflow\ContentWorkflowInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface;

/**
* @template T of ContentRichEntityInterface
*
* @internal
*/
trait FindContentRichEntitiesTrait
{
/**
* @param string[]|int[] $ids
*
* @return ContentRichEntityInterface[]
* @return T[]
*/
protected function findEntitiesByIds(array $ids): array
{
Expand Down Expand Up @@ -56,6 +61,9 @@ function(ContentRichEntityInterface $a, ContentRichEntityInterface $b) use ($idP

abstract protected function getEntityIdField(): string;

/**
* @return class-string<T>
*/
abstract protected function getContentRichEntityClass(): string;

abstract protected function getEntityManager(): EntityManagerInterface;
Expand Down
Expand Up @@ -17,6 +17,9 @@
use Sulu\Bundle\ContentBundle\Content\Domain\Model\TemplateInterface;
use Sulu\Component\Content\Metadata\Factory\StructureMetadataFactoryInterface;

/**
* @internal
*/
trait ResolveContentDimensionUrlTrait
{
/**
Expand Down
3 changes: 3 additions & 0 deletions Content/Infrastructure/Sulu/Traits/ResolveContentTrait.php
Expand Up @@ -18,6 +18,9 @@
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface;

/**
* @internal
*/
trait ResolveContentTrait
{
protected function resolveContent(ContentRichEntityInterface $contentRichEntity, string $locale, bool $showDrafts = false): ?DimensionContentInterface
Expand Down
4 changes: 2 additions & 2 deletions Tests/Application/ExampleTestBundle/Entity/Example.php
Expand Up @@ -31,12 +31,12 @@ class Example implements ContentRichEntityInterface
public const TEMPLATE_TYPE = 'example';

/**
* @var int|string
* @var int
*/
public $id;

/**
* @return int|string
* @return int
*/
public function getId()
{
Expand Down
Expand Up @@ -101,11 +101,11 @@ public static function setUpBeforeClass(): void

static::getEntityManager()->flush();

static::$exampleIds[] = $example1->getId();
static::$exampleIds[] = $example2->getId();
static::$exampleIds[] = $example3->getId();
static::$exampleIds[] = $example4->getId();
static::$exampleIds[] = $example5->getId();
self::$exampleIds[] = $example1->getId();
self::$exampleIds[] = $example2->getId();
self::$exampleIds[] = $example3->getId();
self::$exampleIds[] = $example4->getId();
self::$exampleIds[] = $example5->getId();
}

protected function setUp(): void
Expand All @@ -124,13 +124,13 @@ public function testEmpty(): void

public function testPreloadDE(): void
{
$links = $this->exampleLinkProvider->preload(static::$exampleIds, 'de');
$links = $this->exampleLinkProvider->preload(self::$exampleIds, 'de');
$this->assertArraySnapshot('links_de.json', $this->mapLinks($links));
}

public function testPreloadEN(): void
{
$links = $this->exampleLinkProvider->preload(static::$exampleIds, 'en');
$links = $this->exampleLinkProvider->preload(self::$exampleIds, 'en');
$this->assertArraySnapshot('links_en.json', $this->mapLinks($links));
}

Expand Down
Expand Up @@ -15,6 +15,7 @@

use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Sulu\Bundle\ContactBundle\Entity\Contact;
use Sulu\Bundle\ContentBundle\Content\Application\ContentDataMapper\DataMapper\AuthorDataMapper;
Expand All @@ -25,8 +26,10 @@

class AuthorDataMapperTest extends TestCase
{
use ProphecyTrait;

/**
* @var ObjectProphecy|ContactFactoryInterface
* @var ObjectProphecy<ContactFactoryInterface>
*/
private $contactFactory;

Expand Down
Expand Up @@ -14,6 +14,7 @@
namespace Sulu\Bundle\ContentBundle\Tests\Unit\Content\Application\ContentDataMapper\DataMapper;

use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Sulu\Bundle\ContentBundle\Content\Application\ContentDataMapper\DataMapper\WebspaceDataMapper;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface;
Expand All @@ -25,8 +26,10 @@

class WebspaceDataMapperTest extends TestCase
{
use ProphecyTrait;

/**
* @var ObjectProphecy|WebspaceManagerInterface
* @var ObjectProphecy<WebspaceManagerInterface>
*/
private $webspaceManager;

Expand Down
Expand Up @@ -15,6 +15,7 @@

use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Sulu\Bundle\ContactBundle\Entity\ContactInterface;
use Sulu\Bundle\ContentBundle\Content\Application\ContentMerger\Merger\AuthorMerger;
use Sulu\Bundle\ContentBundle\Content\Application\ContentMerger\Merger\MergerInterface;
Expand All @@ -23,6 +24,8 @@

class AuthorMergerTest extends TestCase
{
use ProphecyTrait;

protected function getAuthorMergerInstance(): MergerInterface
{
return new AuthorMerger();
Expand Down
Expand Up @@ -15,13 +15,16 @@

use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Sulu\Bundle\ContentBundle\Content\Application\ContentMerger\Merger\MergerInterface;
use Sulu\Bundle\ContentBundle\Content\Application\ContentMerger\Merger\WebspaceMerger;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\WebspaceInterface;

class WebspaceMergerTest extends TestCase
{
use ProphecyTrait;

protected function getWebspaceMergerInstance(): MergerInterface
{
return new WebspaceMerger();
Expand Down
Expand Up @@ -14,12 +14,15 @@
namespace Sulu\Bundle\ContentBundle\Tests\Unit\Content\Application\ContentNormalizer\Normalizer;

use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Sulu\Bundle\ContactBundle\Entity\ContactInterface;
use Sulu\Bundle\ContentBundle\Content\Application\ContentNormalizer\Normalizer\AuthorNormalizer;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\AuthorInterface;

class AuthorNormalizerTest extends TestCase
{
use ProphecyTrait;

protected function createAuthorNormalizerInstance(): AuthorNormalizer
{
return new AuthorNormalizer();
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/Content/Domain/Model/AuthorTraitTest.php
Expand Up @@ -14,12 +14,15 @@
namespace Sulu\Bundle\ContentBundle\Tests\Unit\Content\Domain\Model;

use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Sulu\Bundle\ContactBundle\Entity\ContactInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\AuthorInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\AuthorTrait;

class AuthorTraitTest extends TestCase
{
use ProphecyTrait;

protected function getAuthorInstance(): AuthorInterface
{
return new class() implements AuthorInterface {
Expand Down
Expand Up @@ -18,6 +18,7 @@
use Doctrine\ORM\Events;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Sulu\Bundle\ContentBundle\Content\Application\ContentMetadataInspector\ContentMetadataInspectorInterface;
use Sulu\Bundle\ContentBundle\Content\Infrastructure\Doctrine\RouteRemover;
Expand All @@ -28,18 +29,20 @@

class RouteRemoverTest extends TestCase
{
use ProphecyTrait;

public static function getResourceKey(): string
{
return 'test';
}

/**
* @var ContentMetadataInspectorInterface|ObjectProphecy
* @var ObjectProphecy<ContentMetadataInspectorInterface>
*/
private $contentMetadataInspector;

/**
* @var RouteRepositoryInterface|ObjectProphecy
* @var ObjectProphecy<RouteRepositoryInterface>
*/
private $routeRepository;

Expand Down
Expand Up @@ -15,6 +15,7 @@

use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Sulu\Bundle\AdminBundle\Metadata\FormMetadata\FormMetadata;
use Sulu\Bundle\AdminBundle\Metadata\FormMetadata\ItemMetadata;
Expand All @@ -25,8 +26,10 @@

class SettingsFormMetadataVisitorTest extends TestCase
{
use ProphecyTrait;

/**
* @var ObjectProphecy|XmlFormMetadataLoader
* @var ObjectProphecy<XmlFormMetadataLoader>
*/
private $xmlFormMetadataLoader;

Expand Down
Expand Up @@ -14,6 +14,7 @@
namespace Sulu\Bundle\ContentBundle\Tests\Unit\Content\Infrastructure\Sulu\Page\Select;

use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Page\Select\WebspaceSelect;
use Sulu\Component\Webspace\Manager\WebspaceCollection;
Expand All @@ -22,8 +23,10 @@

class WebspaceSelectTest extends TestCase
{
use ProphecyTrait;

/**
* @var ObjectProphecy|WebspaceManagerInterface
* @var ObjectProphecy<WebspaceManagerInterface>
*/
private $webspaceManager;

Expand Down

0 comments on commit 3aac8a0

Please sign in to comment.