diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b757f7..a270a05 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,3 +8,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## 0.1.0 Under development - feat: added a framework-agnostic Vite facade with explicit development and production configuration. +- docs: add class-level PHPDoc for the framework-neutral Vite APIs. diff --git a/src/Asset/AssetCollection.php b/src/Asset/AssetCollection.php index 34a5119..abde8a2 100644 --- a/src/Asset/AssetCollection.php +++ b/src/Asset/AssetCollection.php @@ -21,12 +21,15 @@ final readonly class AssetCollection implements Countable, IteratorAggregate { /** - * @var list + * @var list Accepted assets in insertion order, with per-type duplicates removed. */ private array $assets; /** - * @param iterable $assets + * @param iterable $assets Assets to collect. + * + * @throws ConfigurationException if a value does not implement {@see AssetInterface}, or implements it without + * being one of the four supported asset types. */ public function __construct(iterable $assets = []) { @@ -52,25 +55,45 @@ public function __construct(iterable $assets = []) } /** - * @return list + * Returns every collected asset in insertion order, regardless of type. + * + * @return list The collected assets. */ public function all(): array { return $this->assets; } - public function append(AssetInterface ...$assets): self + /** + * Returns a new collection with the supplied assets added after the current ones. + * + * The receiver is left untouched; deduplication is re-applied across the combined sequence. + * + * @param AssetInterface ...$assets Assets to add at the end. + * + * @throws ConfigurationException if an asset is not one of the four supported types. + * + * @return AssetCollection A new collection holding both sequences. + */ + public function append(AssetInterface ...$assets): AssetCollection { return new self([...$this->assets, ...$assets]); } + /** + * Counts the collected assets after deduplication. + * + * @return int<0, max> Number of assets in the collection. + */ public function count(): int { return count($this->assets); } /** - * @return Traversable + * Iterates over the collected assets in insertion order. + * + * @return Traversable Iterator over the collected assets. */ public function getIterator(): Traversable { @@ -78,7 +101,9 @@ public function getIterator(): Traversable } /** - * @return list + * Filters the collection down to its inline modules. + * + * @return list Inline modules in insertion order. */ public function inlineModules(): array { @@ -94,7 +119,9 @@ public function inlineModules(): array } /** - * @return list + * Filters the collection down to its module-preload hints. + * + * @return list Module preloads in insertion order. */ public function modulePreloads(): array { @@ -110,7 +137,9 @@ public function modulePreloads(): array } /** - * @return list + * Filters the collection down to its module scripts. + * + * @return list Module scripts in insertion order. */ public function moduleScripts(): array { @@ -125,13 +154,26 @@ public function moduleScripts(): array return $assets; } - public function prepend(AssetInterface ...$assets): self + /** + * Returns a new collection with the supplied assets added before the current ones. + * + * The receiver is left untouched; deduplication is re-applied across the combined sequence. + * + * @param AssetInterface ...$assets Assets to add at the beginning. + * + * @throws ConfigurationException if an asset is not one of the four supported types. + * + * @return AssetCollection A new collection holding both sequences. + */ + public function prepend(AssetInterface ...$assets): AssetCollection { return new self([...$assets, ...$this->assets]); } /** - * @return list + * Filters the collection down to its stylesheets. + * + * @return list Stylesheets in insertion order. */ public function stylesheets(): array { @@ -147,7 +189,14 @@ public function stylesheets(): array } /** - * @return InlineModule|ModulePreload|ModuleScript|Stylesheet + * Narrows an arbitrary value to one of the four supported asset types. + * + * @param mixed $asset Value taken from the incoming iterable. + * + * @throws ConfigurationException if the value does not implement {@see AssetInterface}, or implements it without + * being a supported type. + * + * @return InlineModule|ModulePreload|ModuleScript|Stylesheet The narrowed asset. */ private function requireAsset(mixed $asset): AssetInterface { diff --git a/src/Asset/InlineModule.php b/src/Asset/InlineModule.php index 2baab0c..5c8437d 100644 --- a/src/Asset/InlineModule.php +++ b/src/Asset/InlineModule.php @@ -8,8 +8,16 @@ use function trim; +/** + * Represents validated inline JavaScript module source. + */ final readonly class InlineModule implements AssetInterface { + /** + * @param string $source JavaScript module source rendered inside a `