From 2ed92f8f357eb550a8c4a3b2e956ab0c8b54605e Mon Sep 17 00:00:00 2001 From: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> Date: Wed, 17 Jan 2024 17:11:45 +1300 Subject: [PATCH] ENH Add generic types (#584) --- src/AssetControlExtension.php | 4 +--- src/Dev/TestAssetStore.php | 5 ----- src/File.php | 13 +++++-------- src/Flysystem/FlysystemAssetStore.php | 14 -------------- src/Folder.php | 4 ++-- src/ImageManipulation.php | 2 -- src/Shortcodes/FileLinkTracking.php | 2 +- src/Shortcodes/FileShortcodeProvider.php | 4 ---- src/Shortcodes/ImageShortcodeProvider.php | 2 -- 9 files changed, 9 insertions(+), 41 deletions(-) diff --git a/src/AssetControlExtension.php b/src/AssetControlExtension.php index dafdb5ec..dc742dd7 100644 --- a/src/AssetControlExtension.php +++ b/src/AssetControlExtension.php @@ -24,11 +24,10 @@ * Assets which are no longer referenced will be flushed via explicit delete calls * to the underlying filesystem. * - * @property DataObject|Versioned $owner A {@see DataObject}, potentially decorated with {@see Versioned} extension. + * @extends DataExtension */ class AssetControlExtension extends DataExtension { - /** * When archiving versioned dataobjects, should assets be archived with them? * If false, assets will be deleted when the dataobject is archived. @@ -266,7 +265,6 @@ protected function findAssets(DataObject $record) */ protected function isVersioned() { - /** @var Versioned|DataObject $owner */ $owner = $this->owner; return class_exists(Versioned::class) && $owner->hasExtension(Versioned::class) diff --git a/src/Dev/TestAssetStore.php b/src/Dev/TestAssetStore.php index fdcd8d38..e985f16e 100644 --- a/src/Dev/TestAssetStore.php +++ b/src/Dev/TestAssetStore.php @@ -153,7 +153,6 @@ public static function getLocalPath(AssetContainer $asset, $forceProtected = fal /** @var TestAssetStore $assetStore */ $assetStore = Injector::inst()->get(AssetStore::class); $fileID = $assetStore->getFileID($asset->Filename, $asset->Hash, $asset->Variant); - /** @var Filesystem $filesystem */ $filesystem = $assetStore->getProtectedFilesystem(); if (!$forceProtected && !$filesystem->has($fileID)) { $filesystem = $assetStore->getPublicFilesystem(); @@ -165,7 +164,6 @@ public static function getLocalPath(AssetContainer $asset, $forceProtected = fal public function cleanFilename(string $filename) { - /** @var FileIDHelper $helper */ $helper = Injector::inst()->get(HashFileIDHelper::class); return $helper->cleanFilename($filename); } @@ -177,14 +175,12 @@ public function getFileID($filename, $hash, $variant = null) public function parseFileID(string $fileID) { - /** @var ParsedFileID $parsedFileID */ $parsedFileID = $this->getProtectedResolutionStrategy()->parseFileID($fileID); return $parsedFileID ? $parsedFileID->getTuple() : null; } public function getOriginalFilename(string $fileID) { - /** @var ParsedFileID $parsedFileID */ $parsedFiledID = $this->getPublicResolutionStrategy()->parseFileID($fileID); return $parsedFiledID ? $parsedFiledID->getFilename() : null; } @@ -201,7 +197,6 @@ function (ParsedFileID $parsedFileID, Filesystem $fs) { public function removeVariant(string $fileID) { - /** @var ParsedFileID $parsedFileID */ $parsedFiledID = $this->getPublicResolutionStrategy()->parseFileID($fileID); if ($parsedFiledID) { return $this->getPublicResolutionStrategy()->buildFileID($parsedFiledID->setVariant('')); diff --git a/src/File.php b/src/File.php index b1bc68f7..7f085d46 100644 --- a/src/File.php +++ b/src/File.php @@ -114,7 +114,7 @@ class File extends DataObject implements AssetContainer, Thumbnail, CMSPreviewab private static $singular_name = "File"; private static $plural_name = "Files"; - + /** * Control whether images in the admin will be resampled * @@ -315,7 +315,6 @@ public static function find($filename) // Split to folders and the actual filename, and traverse the structure. $parts = array_filter(preg_split("#[/\\\\]+#", $filename ?? '') ?? []); $parentID = 0; - /** @var File $item */ $item = null; foreach ($parts as $part) { $item = File::get()->filter([ @@ -754,7 +753,6 @@ protected function onAfterDelete() public function onAfterRevertToLive() { // Force query of draft object and update (as source record is bound to live stage) - /** @var File $draftRecord */ if (class_exists(Versioned::class) && $draftRecord = Versioned::get_by_stage(self::class, Versioned::DRAFT)->byID($this->ID) ) { @@ -847,7 +845,6 @@ public function collateDescendants($condition, &$collator) { if ($children = $this->Children()) { foreach ($children as $item) { - /** @var File $item */ if (!$condition || eval("return $condition;")) { $collator[] = $item; } @@ -895,7 +892,7 @@ public function getURL($grant = false) if (!$grant && $this->canView()) { $grant = true; } - + if ($this->File->exists()) { return $this->File->getURL($grant); } @@ -1151,9 +1148,9 @@ public function validate() * Caution: Changes to mapping doesn't apply to existing file records in the database. * Also doesn't hook into {@link Object::getCustomClass()}. * - * @param String File extension, without dot prefix. Use an asterisk ('*') + * @param string File extension, without dot prefix. Use an asterisk ('*') * to specify a generic fallback if no mapping is found for an extension. - * @return String Classname for a subclass of {@link File} + * @return string Classname for a subclass of {@link File} */ public static function get_class_for_file_extension($ext) { @@ -1294,7 +1291,7 @@ public function getTag() /** * Get the back-link tracking objects that link to this file via HTML fields * - * @retun ArrayList|DataObject[] + * @return ArrayList */ public function BackLinkTracking() { diff --git a/src/Flysystem/FlysystemAssetStore.php b/src/Flysystem/FlysystemAssetStore.php index 5dd8561e..cb5fbc13 100644 --- a/src/Flysystem/FlysystemAssetStore.php +++ b/src/Flysystem/FlysystemAssetStore.php @@ -261,7 +261,6 @@ protected function applyToFileOnFilesystem(callable $callable, ParsedFileID $par self::VISIBILITY_PROTECTED ]; - /** @var FileHashingService $hasher */ $hasher = Injector::inst()->get(FileHashingService::class); /** @var Filesystem $fs */ @@ -515,7 +514,6 @@ public function setFromStream($stream, $filename, $hash = null, $variant = null, return $result; } - /** @var FileHashingService $hasher */ $hasher = Injector::inst()->get(FileHashingService::class); // When saving original filename, generate hash @@ -587,7 +585,6 @@ function (ParsedFileID $parsedFileID, Filesystem $fs, FileResolutionStrategy $st $destParsedFileID->setVariant($originParsedFileID->getVariant()) ); - /** @var FileHashingService $hasher */ $hasher = Injector::inst()->get(FileHashingService::class); if ($origin !== $destination) { @@ -636,7 +633,6 @@ function (ParsedFileID $pfid, Filesystem $fs, FileResolutionStrategy $strategy) $fs->copy($fromFileID, $toFileID); // Set hash value for new file - /** @var FileHashingService $hasher */ $hasher = Injector::inst()->get(FileHashingService::class); if ($hash = $hasher->get($fromFileID, $fs)) { $hasher->set($toFileID, $fs, $hash); @@ -662,7 +658,6 @@ function (ParsedFileID $pfid, Filesystem $fs, FileResolutionStrategy $strategy) */ protected function deleteFromFileStore(ParsedFileID $parsedFileID, Filesystem $fs, FileResolutionStrategy $strategy) { - /** @var FileHashingService $hasher */ $hasher = Injector::inst()->get(FileHashingService::class); $deleted = false; @@ -730,7 +725,6 @@ public function swapPublish($filename, $hash) return; } - /** @var FileHashingService $hasher */ $hasher = Injector::inst()->get(FileHashingService::class); $parsedFileID = new ParsedFileID($filename, $hash); @@ -742,7 +736,6 @@ public function swapPublish($filename, $hash) // Look for files that might be overriden by publishing to destination store, those need to be stashed away - /** @var ParsedFileID $variantParsedFileID */ $swapFileIDStr = $toStrategy->buildFileID($parsedFileID); $swapFiles = []; if ($to->has($swapFileIDStr)) { @@ -768,7 +761,6 @@ public function swapPublish($filename, $hash) // Let's find all the variants on the origin store ... those need to be moved to the destination - /** @var ParsedFileID $variantParsedFileID */ foreach ($fromStrategy->findVariants($parsedFileID, $from) as $variantParsedFileID) { // Copy via stream $fromFileID = $variantParsedFileID->getFileID(); @@ -832,11 +824,9 @@ protected function moveBetweenFileStore( FileResolutionStrategy $toStrategy, $swap = false ) { - /** @var FileHashingService $hasher */ $hasher = Injector::inst()->get(FileHashingService::class); // Let's find all the variants on the origin store ... those need to be moved to the destination - /** @var ParsedFileID $variantParsedFileID */ foreach ($fromStrategy->findVariants($parsedFileID, $from) as $variantParsedFileID) { // Copy via stream $fromFileID = $variantParsedFileID->getFileID(); @@ -1063,7 +1053,6 @@ function ( if (empty($variant)) { // If deferring to the existing file, return the sha of the existing file, // unless we are writing a variant (which has the same hash value as its original file) - /** @var FileHashingService $hasher */ $hasher = Injector::inst()->get(FileHashingService::class); $hash = $hasher->computeFromFile($targetFileID, $fs); $parsedFileID = $parsedFileID->setHash($hash); @@ -1131,7 +1120,6 @@ function (ParsedFileID $parsedFileID, Filesystem $fs, FileResolutionStrategy $st if ($parsedFileID && $originalFileID = $parsedFileID->getFileID()) { if ($fs->has($originalFileID)) { - /** @var FileHashingService $hasher */ $hasher = Injector::inst()->get(FileHashingService::class); $actualHash = $hasher->computeFromFile($originalFileID, $fs); @@ -1455,8 +1443,6 @@ function (...$args) { private function normaliseToDefaultPath(ParsedFileID $pfid, Filesystem $fs, FileResolutionStrategy $strategy) { $ops = []; - - /** @var FileHashingService $hasher */ $hasher = Injector::inst()->get(FileHashingService::class); // Let's make sure we are using a valid file name diff --git a/src/Folder.php b/src/Folder.php index 29275da8..f5efc563 100644 --- a/src/Folder.php +++ b/src/Folder.php @@ -161,7 +161,7 @@ public function getSize() /** * Returns all children of this folder * - * @return DataList + * @return DataList */ public function myChildren() { @@ -191,7 +191,7 @@ public function hasChildFolders() /** * Get the children of this folder that are also folders. * - * @return DataList + * @return DataList */ public function ChildFolders() { diff --git a/src/ImageManipulation.php b/src/ImageManipulation.php index dd56c050..e7a74785 100644 --- a/src/ImageManipulation.php +++ b/src/ImageManipulation.php @@ -853,7 +853,6 @@ public function manipulateImage($variant, $callback) return $this->manipulate( $variant, function (AssetStore $store, $filename, $hash, $variant) use ($callback) { - /** @var Image_Backend $backend */ $backend = $this->getImageBackend(); // If backend isn't available @@ -884,7 +883,6 @@ function (AssetStore $store, $filename, $hash, $variant) use ($callback) { // Write from modified backend if ($result instanceof Image_Backend) { try { - /** @var Image_Backend $result */ $tuple = $result->writeToStore( $store, $filename, diff --git a/src/Shortcodes/FileLinkTracking.php b/src/Shortcodes/FileLinkTracking.php index 15bae1d0..92d3a8ca 100644 --- a/src/Shortcodes/FileLinkTracking.php +++ b/src/Shortcodes/FileLinkTracking.php @@ -23,8 +23,8 @@ * Note that since both SiteTree and File are versioned, LinkTracking and FileTracking will * only be enabled for the Stage record. * - * @property DataObject|FileLinkTracking $owner * @method SilverStripe\ORM\ManyManyThroughList FileTracking() + * @extends DataExtension */ class FileLinkTracking extends DataExtension { diff --git a/src/Shortcodes/FileShortcodeProvider.php b/src/Shortcodes/FileShortcodeProvider.php index 30326a71..4f4a4459 100644 --- a/src/Shortcodes/FileShortcodeProvider.php +++ b/src/Shortcodes/FileShortcodeProvider.php @@ -74,7 +74,6 @@ public static function get_shortcodes() */ public static function handle_shortcode($arguments, $content, $parser, $shortcode, $extra = []) { - /** @var CacheInterface $cache */ $cache = static::getCache(); $cacheKey = static::getCacheKey($arguments, $content); $cachedMarkup = static::getCachedMarkup($cache, $cacheKey, $arguments); @@ -87,7 +86,6 @@ public static function handle_shortcode($arguments, $content, $parser, $shortcod $record = static::find_shortcode_record($arguments, $errorCode); if ($errorCode) { $fileFound = false; - /** @var ErrorPage $record */ $record = static::find_error_record($errorCode); } if (!$record) { @@ -179,7 +177,6 @@ public static function find_shortcode_record($args, &$errorCode = null) } // Check if the file is found - /** @var File $file */ $file = DataObject::get_by_id(File::class, $args['id']); if (!$file) { $errorCode = 404; @@ -240,7 +237,6 @@ public static function getCacheKey($params, $content = null) */ public static function getCache() { - /** @var CacheInterface $cache */ return Injector::inst()->get(CacheInterface::class . '.FileShortcodeProvider'); } diff --git a/src/Shortcodes/ImageShortcodeProvider.php b/src/Shortcodes/ImageShortcodeProvider.php index b4b32f08..9b8cd419 100644 --- a/src/Shortcodes/ImageShortcodeProvider.php +++ b/src/Shortcodes/ImageShortcodeProvider.php @@ -56,7 +56,6 @@ public static function get_shortcodes() */ public static function handle_shortcode($args, $content, $parser, $shortcode, $extra = []) { - /** @var CacheInterface $cache */ $cache = static::getCache(); $cacheKey = static::getCacheKey($args, $content); $cachedMarkup = static::getCachedMarkup($cache, $cacheKey, $args); @@ -199,7 +198,6 @@ public static function regenerate_html_links($value) */ public static function getCache() { - /** @var CacheInterface $cache */ return Injector::inst()->get(CacheInterface::class . '.ImageShortcodeProvider'); }