Skip to content

Commit

Permalink
Merge 4.x into 5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
SonataCI committed Nov 29, 2021
2 parents 4617b60 + cd3f029 commit 918144d
Show file tree
Hide file tree
Showing 19 changed files with 61 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/qa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
php-version: '8.0'
coverage: none
tools: composer:v2
extensions: mongodb-1.9.0, gd
extensions: mongodb, gd

- name: Install Composer dependencies (highest)
uses: ramsey/composer-install@v1
Expand All @@ -53,7 +53,7 @@ jobs:
php-version: '8.0'
coverage: none
tools: composer:v2
extensions: mongodb-1.9.0, gd
extensions: mongodb, gd

- name: Install Composer dependencies (highest)
uses: ramsey/composer-install@v1
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
php-version: ${{ matrix.php-version }}
coverage: pcov
tools: composer:v2
extensions: mongodb-1.9.0, gd
extensions: mongodb, gd

- name: Add PHPUnit matcher
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
Expand All @@ -92,7 +92,7 @@ jobs:

- name: Remove dev dependencies not compatible with Symfony 6
if: matrix.symfony-require == '6.0.*'
run: composer remove psalm/plugin-symfony symfony/maker-bundle symfony/panther --dev --no-update --no-interaction
run: composer remove psalm/plugin-symfony --dev --no-update --no-interaction

- name: Install Composer dependencies (${{ matrix.dependencies }})
uses: ramsey/composer-install@v1
Expand Down
4 changes: 2 additions & 2 deletions UPGRADE-3.x.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
UPGRADE 3.x
===========

UPGRADE FROM 3.x to 3.x
=======================
UPGRADE FROM 3.36 to 3.37
=========================

### ReST API

Expand Down
4 changes: 2 additions & 2 deletions src/Admin/GalleryAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;

/**
* @phpstan-extends AbstractAdmin<\Sonata\MediaBundle\Model\GalleryInterface>
* @phpstan-extends AbstractAdmin<\Sonata\MediaBundle\Model\GalleryInterface<\Sonata\MediaBundle\Model\GalleryItemInterface>>
*/
final class GalleryAdmin extends AbstractAdmin
{
Expand All @@ -31,7 +31,7 @@ final class GalleryAdmin extends AbstractAdmin
private Pool $pool;

/**
* @phpstan-param class-string<\Sonata\MediaBundle\Model\GalleryInterface> $class
* @phpstan-param class-string<\Sonata\MediaBundle\Model\GalleryInterface<\Sonata\MediaBundle\Model\GalleryItemInterface>> $class
*/
public function __construct(string $code, string $class, string $baseControllerName, Pool $pool)
{
Expand Down
7 changes: 5 additions & 2 deletions src/Block/GalleryBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Sonata\Form\Type\ImmutableArrayType;
use Sonata\Form\Validator\ErrorElement;
use Sonata\MediaBundle\Model\GalleryInterface;
use Sonata\MediaBundle\Model\GalleryItemInterface;
use Sonata\MediaBundle\Model\GalleryManagerInterface;
use Sonata\MediaBundle\Model\MediaInterface;
use Sonata\MediaBundle\Provider\Pool;
Expand All @@ -45,14 +46,14 @@ final class GalleryBlockService extends AbstractBlockService implements Editable
private Pool $pool;

/**
* @var AdminInterface<GalleryInterface>|null
* @var AdminInterface<GalleryInterface<GalleryItemInterface>>|null
*/
private ?AdminInterface $galleryAdmin;

private GalleryManagerInterface $galleryManager;

/**
* @param AdminInterface<GalleryInterface>|null $galleryAdmin
* @param AdminInterface<GalleryInterface<GalleryItemInterface>>|null $galleryAdmin
*/
public function __construct(
Environment $twig,
Expand Down Expand Up @@ -218,6 +219,8 @@ private function getGalleryBuilder(FormMapper $form): FormBuilderInterface
/**
* @return array<string, MediaInterface|string|null>
*
* @phpstan-param GalleryInterface<GalleryItemInterface> $gallery
*
* @phpstan-return array{
* title: string|null,
* caption: string|null,
Expand Down
4 changes: 4 additions & 0 deletions src/Document/BaseGallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@

use Sonata\MediaBundle\Model\Gallery;

/**
* @phpstan-template T of \Sonata\MediaBundle\Model\GalleryItemInterface
* @phpstan-extends Gallery<T>
*/
abstract class BaseGallery extends Gallery
{
public function prePersist(): void
Expand Down
4 changes: 4 additions & 0 deletions src/Entity/BaseGallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@

use Sonata\MediaBundle\Model\Gallery;

/**
* @phpstan-template T of \Sonata\MediaBundle\Model\GalleryItemInterface
* @phpstan-extends Gallery<T>
*/
abstract class BaseGallery extends Gallery
{
public function prePersist(): void
Expand Down
6 changes: 6 additions & 0 deletions src/Model/Gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
use Doctrine\Common\Collections\Collection;
use Sonata\MediaBundle\Provider\MediaProviderInterface;

/**
* @phpstan-template T of GalleryItemInterface
* @phpstan-implements GalleryInterface<T>
*/
abstract class Gallery implements GalleryInterface
{
protected ?string $context = null;
Expand All @@ -33,6 +37,8 @@ abstract class Gallery implements GalleryInterface

/**
* @var Collection<int, GalleryItemInterface>
*
* @phpstan-var Collection<int, T>
*/
protected Collection $galleryItems;

Expand Down
13 changes: 13 additions & 0 deletions src/Model/GalleryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

use Doctrine\Common\Collections\Collection;

/**
* @phpstan-template T of GalleryItemInterface
*/
interface GalleryInterface
{
public function __toString(): string;
Expand Down Expand Up @@ -50,16 +53,26 @@ public function getDefaultFormat(): string;

/**
* @param iterable<int, GalleryItemInterface> $galleryItems
*
* @phpstan-param iterable<int, T> $galleryItems
*/
public function setGalleryItems(iterable $galleryItems): void;

/**
* @return Collection<int, GalleryItemInterface>
*
* @phpstan-return Collection<int, T>
*/
public function getGalleryItems(): Collection;

/**
* @phpstan-param T $galleryItem
*/
public function addGalleryItem(GalleryItemInterface $galleryItem): void;

/**
* @phpstan-param T $galleryItem
*/
public function removeGalleryItem(GalleryItemInterface $galleryItem): void;

/**
Expand Down
3 changes: 3 additions & 0 deletions src/Model/GalleryItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ abstract class GalleryItem implements GalleryItemInterface
{
protected ?MediaInterface $media = null;

/**
* @phpstan-var ?GalleryInterface<GalleryItemInterface>
*/
protected ?GalleryInterface $gallery = null;

protected int $position = 0;
Expand Down
6 changes: 6 additions & 0 deletions src/Model/GalleryItemInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@ public function setEnabled(bool $enabled): void;

public function getEnabled(): bool;

/**
* @phpstan-param ?GalleryInterface<GalleryItemInterface> $gallery
*/
public function setGallery(?GalleryInterface $gallery = null): void;

/**
* @phpstan-return ?GalleryInterface<GalleryItemInterface>
*/
public function getGallery(): ?GalleryInterface;

public function setMedia(?MediaInterface $media = null): void;
Expand Down
2 changes: 1 addition & 1 deletion src/Model/GalleryManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Sonata\Doctrine\Model\ManagerInterface;

/**
* @phpstan-extends ManagerInterface<\Sonata\MediaBundle\Model\GalleryInterface>
* @phpstan-extends ManagerInterface<\Sonata\MediaBundle\Model\GalleryInterface<\Sonata\MediaBundle\Model\GalleryItemInterface>>
*/
interface GalleryManagerInterface extends ManagerInterface
{
Expand Down
3 changes: 1 addition & 2 deletions src/Provider/FileProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,7 @@ protected function doTransform(MediaInterface $media): void
}

// this is the name used to store the file
if (
null === $media->getProviderReference() ||
if (null === $media->getProviderReference() ||
MediaInterface::MISSING_BINARY_REFERENCE === $media->getProviderReference()
) {
$media->setProviderReference($this->generateReferenceName($media));
Expand Down
1 change: 0 additions & 1 deletion src/Thumbnail/FormatThumbnail.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ public function delete(MediaProviderInterface $provider, MediaInterface $media,

foreach ($formats as $format) {
$path = $provider->generatePrivateUrl($media, $format);

if ($provider->getFilesystem()->has($path)) {
$provider->getFilesystem()->delete($path);
}
Expand Down
2 changes: 2 additions & 0 deletions tests/App/Entity/Gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
/**
* @ORM\Entity
* @ORM\Table(name="media__gallery")
*
* @phpstan-extends BaseGallery<\Sonata\MediaBundle\Model\GalleryItemInterface>
*/
class Gallery extends BaseGallery
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Block/GalleryBlockServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected function setUp(): void
{
parent::setUp();

/** @var AdminInterface<GalleryInterface>&Stub $galleryAdmin */
/** @var AdminInterface<GalleryInterface<\Sonata\MediaBundle\Model\GalleryItemInterface>>&Stub $galleryAdmin */
$galleryAdmin = $this->createStub(AdminInterface::class);

$this->blockService = new GalleryBlockService(
Expand Down
2 changes: 1 addition & 1 deletion tests/Controller/GalleryAdminControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class GalleryAdminControllerTest extends TestCase
private Container $container;

/**
* @var MockObject&AdminInterface<GalleryInterface>
* @var MockObject&AdminInterface<GalleryInterface<\Sonata\MediaBundle\Model\GalleryItemInterface>>
*/
private MockObject $admin;

Expand Down
3 changes: 3 additions & 0 deletions tests/Controller/MediaAdminControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ private function configureCRUDController(): void
$this->admin->method('getCode')->willReturn('admin_code');
}

/**
* @phpstan-param class-string $class
*/
private function configureCreateAction(string $class): void
{
$object = $this->createStub(Media::class);
Expand Down
3 changes: 3 additions & 0 deletions tests/Provider/BaseProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
*/
class BaseProviderTest extends AbstractProviderTest
{
/**
* @return TestProvider
*/
public function getProvider(): MediaProviderInterface
{
$adapter = $this->createMock(Adapter::class);
Expand Down

0 comments on commit 918144d

Please sign in to comment.