Skip to content

Commit

Permalink
[TASK] Introduce CollectableInterface for collection items
Browse files Browse the repository at this point in the history
  • Loading branch information
brotkrueml committed Nov 20, 2022
1 parent 08c917d commit 044879e
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 7 deletions.
5 changes: 3 additions & 2 deletions Classes/Collection/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Brotkrueml\FeedGenerator\Contract\AttachmentInterface;
use Brotkrueml\FeedGenerator\Contract\AuthorInterface;
use Brotkrueml\FeedGenerator\Contract\CategoryInterface;
use Brotkrueml\FeedGenerator\Contract\CollectableInterface;
use Brotkrueml\FeedGenerator\Contract\ExtensionElementInterface;
use Brotkrueml\FeedGenerator\Contract\ItemInterface;
use Traversable;
Expand All @@ -33,7 +34,7 @@ final class Collection implements \IteratorAggregate
* @param T $items
* @return self<T>
*/
public function add(AttachmentInterface|AuthorInterface|CategoryInterface|ExtensionElementInterface|ItemInterface ...$items): self
public function add(CollectableInterface ...$items): self
{
if ($items === []) {
return $this;
Expand All @@ -54,7 +55,7 @@ public function add(AttachmentInterface|AuthorInterface|CategoryInterface|Extens
/**
* @return T
*/
public function get(int $index): AttachmentInterface|AuthorInterface|CategoryInterface|ExtensionElementInterface|ItemInterface
public function get(int $index): CollectableInterface
{
return $this->items[$index] ?? throw IndexNotFoundException::forIndex($index);
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/Contract/AttachmentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* Interface for an attachment (enclosure). Used in RSS and JSON feeds.
*/

interface AttachmentInterface
interface AttachmentInterface extends CollectableInterface
{
/**
* Get the URL.
Expand Down
2 changes: 1 addition & 1 deletion Classes/Contract/AuthorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* Interface for an author.
*/
interface AuthorInterface
interface AuthorInterface extends CollectableInterface
{
/**
* Get the name.
Expand Down
2 changes: 1 addition & 1 deletion Classes/Contract/CategoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* Interface for a category. Used in Atom and RSS feeds.
*/
interface CategoryInterface
interface CategoryInterface extends CollectableInterface
{
/**
* Get the term. The term identifies the category.
Expand Down
29 changes: 29 additions & 0 deletions Classes/Contract/CollectableInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

/*
* This file is part of the "feed_generator" extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/

namespace Brotkrueml\FeedGenerator\Contract;

use JiriPudil\SealedClasses\Sealed;

/**
* Marker interface used for interfaces/classes which can be added to a Collection
* @internal
*/
#[Sealed(permits: [
AttachmentInterface::class,
AuthorInterface::class,
ExtensionElementInterface::class,
CategoryInterface::class,
ItemInterface::class,
])]
interface CollectableInterface
{
}
2 changes: 1 addition & 1 deletion Classes/Contract/ExtensionElementInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
* A marker interface for extension elements
* @api
*/
interface ExtensionElementInterface
interface ExtensionElementInterface extends CollectableInterface
{
}
2 changes: 1 addition & 1 deletion Classes/Contract/ItemInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* @api
*/
interface ItemInterface
interface ItemInterface extends CollectableInterface
{
/**
* Get a unique identifier associated with this item. These are optional so long as a link is added; i.e. if no
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"brotkrueml/coding-standards": "~3.0.0",
"brotkrueml/t3docs-codesnippets-standalone": "dev-main@dev",
"ergebnis/composer-normalize": "~2.28.0",
"jiripudil/phpstan-sealed-classes": "^1.0",
"php-coveralls/php-coveralls": "^2.5",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "1.9.2",
Expand Down

0 comments on commit 044879e

Please sign in to comment.