Skip to content

Commit

Permalink
replaced static methods with public ones (#3715)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasLudvik authored Jan 29, 2025
2 parents 5c5ad7c + f091a9c commit 40c1cd1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 33 deletions.
34 changes: 11 additions & 23 deletions src/Model/LuigisBoxArticleFeedItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@

namespace Shopsys\ArticleFeed\LuigisBoxBundle\Model;

use Shopsys\FrameworkBundle\Component\Image\ImageUrlWithSizeHelper;
use Shopsys\FrameworkBundle\Model\Feed\FeedItemInterface;

class LuigisBoxArticleFeedItem implements FeedItemInterface
{
public const UNIQUE_BLOG_ARTICLE_IDENTIFIER_PREFIX = 'blog_article';
public const UNIQUE_ARTICLE_IDENTIFIER_PREFIX = 'article';
protected const SMALL_IMAGE_SIZE = 100;
protected const MEDIUM_IMAGE_SIZE = 200;
protected const LARGE_IMAGE_SIZE = 600;
public const string UNIQUE_BLOG_ARTICLE_IDENTIFIER_PREFIX = 'blog_article';
public const string UNIQUE_ARTICLE_IDENTIFIER_PREFIX = 'article';

/**
* @param int $id
Expand All @@ -22,7 +18,9 @@ class LuigisBoxArticleFeedItem implements FeedItemInterface
* @param string $link
* @param string|null $description
* @param string|null $perex
* @param string|null $imageUrl
* @param string|null $imageUrlS
* @param string|null $imageUrlM
* @param string|null $imageUrlL
*/
public function __construct(
protected readonly int $id,
Expand All @@ -31,7 +29,9 @@ public function __construct(
protected readonly string $link,
protected readonly ?string $description,
protected readonly ?string $perex,
protected readonly ?string $imageUrl = null,
protected readonly ?string $imageUrlS = null,
protected readonly ?string $imageUrlM = null,
protected readonly ?string $imageUrlL = null,
) {
}

Expand Down Expand Up @@ -88,34 +88,22 @@ public function getAnnotation(): ?string
*/
public function getImageLinkS(): ?string
{
if ($this->imageUrl === null) {
return null;
}

return ImageUrlWithSizeHelper::limitSizeInImageUrl($this->imageUrl, static::SMALL_IMAGE_SIZE, static::SMALL_IMAGE_SIZE);
return $this->imageUrlS;
}

/**
* @return string|null
*/
public function getImageLinkM(): ?string
{
if ($this->imageUrl === null) {
return null;
}

return ImageUrlWithSizeHelper::limitSizeInImageUrl($this->imageUrl, static::MEDIUM_IMAGE_SIZE, static::MEDIUM_IMAGE_SIZE);
return $this->imageUrlM;
}

/**
* @return string|null
*/
public function getImageLinkL(): ?string
{
if ($this->imageUrl === null) {
return null;
}

return ImageUrlWithSizeHelper::limitSizeInImageUrl($this->imageUrl, static::LARGE_IMAGE_SIZE, static::LARGE_IMAGE_SIZE);
return $this->imageUrlL;
}
}
25 changes: 21 additions & 4 deletions src/Model/LuigisBoxArticleFeedItemFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,41 @@

namespace Shopsys\ArticleFeed\LuigisBoxBundle\Model;

use Shopsys\FrameworkBundle\Component\String\TransformString;
use Shopsys\FrameworkBundle\Component\Image\ImageUrlWithSizeHelper;
use Shopsys\FrameworkBundle\Component\String\TransformStringHelper;

class LuigisBoxArticleFeedItemFactory
{
protected const int SMALL_IMAGE_SIZE = 100;
protected const int MEDIUM_IMAGE_SIZE = 200;
protected const int LARGE_IMAGE_SIZE = 600;

/**
* @param \Shopsys\FrameworkBundle\Component\Image\ImageUrlWithSizeHelper $imageUrlWithSizeHelper
*/
public function __construct(
protected readonly ImageUrlWithSizeHelper $imageUrlWithSizeHelper,
) {
}

/**
* @param array $articleData
* @return \Shopsys\ArticleFeed\LuigisBoxBundle\Model\LuigisBoxArticleFeedItem
*/
public function create(array $articleData): LuigisBoxArticleFeedItem
{
$imageUrl = $articleData['imageUrl'] ?? null;

return new LuigisBoxArticleFeedItem(
$articleData['id'],
$articleData['index'],
$articleData['name'],
$articleData['url'],
TransformString::convertHtmlToPlainText($articleData['text']),
TransformString::convertHtmlToPlainText($articleData['perex'] ?? null),
$articleData['imageUrl'] ?? null,
TransformStringHelper::convertHtmlToPlainText($articleData['text']),
TransformStringHelper::convertHtmlToPlainText($articleData['perex'] ?? null),
$imageUrl !== null ? $this->imageUrlWithSizeHelper->limitSizeInImageUrl($imageUrl, static::SMALL_IMAGE_SIZE, static::SMALL_IMAGE_SIZE) : null,
$imageUrl !== null ? $this->imageUrlWithSizeHelper->limitSizeInImageUrl($imageUrl, static::MEDIUM_IMAGE_SIZE, static::MEDIUM_IMAGE_SIZE) : null,
$imageUrl !== null ? $this->imageUrlWithSizeHelper->limitSizeInImageUrl($imageUrl, static::LARGE_IMAGE_SIZE, static::LARGE_IMAGE_SIZE) : null,
);
}
}
13 changes: 7 additions & 6 deletions tests/Unit/LuigisBoxArticleFeedItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
use Shopsys\FrameworkBundle\Component\Domain\Config\DomainConfig;
use Shopsys\FrameworkBundle\Component\Domain\Domain;
use Shopsys\FrameworkBundle\Component\Image\ImageFacade;
use Shopsys\FrameworkBundle\Component\Image\ImageUrlWithSizeHelper;
use Shopsys\FrameworkBundle\Model\Article\Article;

class LuigisBoxArticleFeedItemTest extends TestCase
{
private const ARTICLE_NAME = 'Test article';
private const ARTICLE_URL = 'https://www.example.com/test-article';
private const ARTICLE_TEXT = 'Test article text';
private const ARTICLE_IMAGE_URL = 'https://www.example.com/test-article.jpg';
private const string ARTICLE_NAME = 'Test article';
private const string ARTICLE_URL = 'https://www.example.com/test-article';
private const string ARTICLE_TEXT = 'Test article text';
private const string ARTICLE_IMAGE_URL = 'https://www.example.com/test-article.jpg';

private LuigisBoxArticleFeedItemFactory $luigisBoxArticleFeedItemFactory;

Expand All @@ -30,7 +31,7 @@ class LuigisBoxArticleFeedItemTest extends TestCase

protected function setUp(): void
{
$this->luigisBoxArticleFeedItemFactory = new LuigisBoxArticleFeedItemFactory();
$this->luigisBoxArticleFeedItemFactory = new LuigisBoxArticleFeedItemFactory(new ImageUrlWithSizeHelper());
$this->imageFacadeMock = $this->createMock(ImageFacade::class);

$this->defaultDomain = $this->createDomainConfigMock(
Expand Down Expand Up @@ -68,7 +69,7 @@ private function createDomainConfigMock(int $id, string $url, string $locale): D
#[DataProvider('articleFeedItemCreationDataProvider')]
public function testArticleFeedItemCreation(array $articleData): void
{
$luigisBoxArticleFeedItemFactory = new LuigisBoxArticleFeedItemFactory();
$luigisBoxArticleFeedItemFactory = new LuigisBoxArticleFeedItemFactory(new ImageUrlWithSizeHelper());
$luigisBoxArticleFeedItem = $luigisBoxArticleFeedItemFactory->create($articleData);

$this->assertSame($articleData['index'] . '-' . $articleData['id'], $luigisBoxArticleFeedItem->getIdentity());
Expand Down

0 comments on commit 40c1cd1

Please sign in to comment.