diff --git a/src/Shortcodes/ImageShortcodeProvider.php b/src/Shortcodes/ImageShortcodeProvider.php index 91492129..ccdbe1c8 100644 --- a/src/Shortcodes/ImageShortcodeProvider.php +++ b/src/Shortcodes/ImageShortcodeProvider.php @@ -47,11 +47,11 @@ public static function get_shortcodes() * Replace"[image id=n]" shortcode with an image reference. * Permission checks will be enforced by the file routing itself. * - * @param array $args Arguments passed to the parser - * @param string $content Raw shortcode - * @param ShortcodeParser $parser Parser - * @param string $shortcode Name of shortcode used to register this handler - * @param array $extra Extra arguments + * @param array $args Arguments passed to the parser + * @param string $content Raw shortcode + * @param ShortcodeParser $parser Parser + * @param string $shortcode Name of shortcode used to register this handler + * @param array $extra Extra arguments * @return string Result of the handled shortcode */ public static function handle_shortcode($args, $content, $parser, $shortcode, $extra = []) @@ -138,14 +138,11 @@ public static function handle_shortcode($args, $content, $parser, $shortcode, $e // cache it for future reference if ($fileFound) { - $cache->set( - $cacheKey, - [ + $cache->set($cacheKey, [ 'markup' => $markup, 'filename' => $record instanceof File ? $record->getFilename() : null, 'hash' => $record instanceof File ? $record->getHash() : null, - ] - ); + ]); } return $markup; @@ -176,11 +173,11 @@ public static function createImageTag(array $attributes) : string /** * Regenerates "[image id=n]" shortcode with new src attribute prior to being edited within the CMS. * - * @param array $args Arguments passed to the parser - * @param string $content Raw shortcode - * @param ShortcodeParser $parser Parser - * @param string $shortcode Name of shortcode used to register this handler - * @param array $extra Extra arguments + * @param array $args Arguments passed to the parser + * @param string $content Raw shortcode + * @param ShortcodeParser $parser Parser + * @param string $shortcode Name of shortcode used to register this handler + * @param array $extra Extra arguments * @return string Result of the handled shortcode */ public static function regenerate_shortcode($args, $content, $parser, $shortcode, $extra = []) diff --git a/tests/php/ImageManipulationTest.php b/tests/php/ImageManipulationTest.php index 541c2c50..5994b19c 100644 --- a/tests/php/ImageManipulationTest.php +++ b/tests/php/ImageManipulationTest.php @@ -38,9 +38,7 @@ protected function setUp(): void TestAssetStore::activate('ImageTest'); // Copy test images for each of the fixture references - /** - * @var File $image -*/ + /** @var File $image */ $files = File::get()->exclude('ClassName', Folder::class); foreach ($files as $image) { $sourcePath = __DIR__ . '/ImageTest/' . $image->Name; @@ -49,14 +47,11 @@ protected function setUp(): void } // Set default config - InterventionBackend::config()->set( - 'error_cache_ttl', - [ + InterventionBackend::config()->set('error_cache_ttl', [ InterventionBackend::FAILED_INVALID => 0, InterventionBackend::FAILED_MISSING => '5,10', InterventionBackend::FAILED_UNKNOWN => 300, - ] - ); + ]); } protected function tearDown(): void @@ -67,9 +62,7 @@ protected function tearDown(): void public function testAttribute() { - /** - * @var Image $origin -*/ + /** @var Image $origin */ $origin = $this->objFromFixture(Image::class, 'imageWithTitle'); $this->assertEmpty( @@ -77,9 +70,7 @@ public function testAttribute() 'Undefined attributes are falsy' ); - /** - * @var DBFile $image -*/ + /** @var DBFile $image */ $image = $origin->setAttribute('foo', 'bar'); $this->assertEquals( 'bar', @@ -121,9 +112,7 @@ public function testAttribute() public function testInitAttributes() { - /** - * @var Image $origin -*/ + /** @var Image $origin */ $origin = $this->objFromFixture(Image::class, 'imageWithTitle'); $origin->initAttributes(['foo' => 'bar']); @@ -133,9 +122,7 @@ public function testInitAttributes() 'Attributes hawve been set' ); - /** - * @var DBFile $dbfile -*/ + /** @var DBFile $dbfile */ $dbfile = $origin->setAttribute('hello', 'bonjour'); $dbfile->initAttributes(['bar' => 'foo']); $this->assertEquals( @@ -151,9 +138,7 @@ public function testInitAttributes() public function testGetAttributesForImage() { - /** - * @var Image $origin -*/ + /** @var Image $origin */ $image = $this->objFromFixture(Image::class, 'imageWithTitle'); $this->assertEquals( @@ -220,37 +205,33 @@ public function testGetAttributesForImage() public function testGetAttributesWhenLazyLoadIsDisabled() { - Config::withConfig( - function () { - Config::modify()->set(Image::class, 'lazy_loading_enabled', false); - /** - * @var Image $origin - */ - $image = $this->objFromFixture(Image::class, 'imageWithTitle'); - - $this->assertEquals( - [ - 'width' => $image->getWidth(), - 'height' => $image->getHeight(), - 'alt' => $image->getTitle(), - 'src' => $image->getURL(), - ], - $image->getAttributes(), - 'No loading attribute when lazy loading is disabled globally' - ); + Config::withConfig(function () { + Config::modify()->set(Image::class, 'lazy_loading_enabled', false); + /** @var Image $origin */ + $image = $this->objFromFixture(Image::class, 'imageWithTitle'); + + $this->assertEquals( + [ + 'width' => $image->getWidth(), + 'height' => $image->getHeight(), + 'alt' => $image->getTitle(), + 'src' => $image->getURL(), + ], + $image->getAttributes(), + 'No loading attribute when lazy loading is disabled globally' + ); - $this->assertEquals( - [ + $this->assertEquals( + [ 'width' => $image->getWidth(), 'height' => $image->getHeight(), 'alt' => $image->getTitle(), 'src' => $image->getURL(), - ], - $image->LazyLoad(true)->getAttributes(), - 'No loading attribute when lazy loading is disabled globally even if requested' - ); - } - ); + ], + $image->LazyLoad(true)->getAttributes(), + 'No loading attribute when lazy loading is disabled globally even if requested' + ); + }); } public function testGetAttributesForPlainFile() @@ -276,15 +257,13 @@ public function testIsLazyLoaded() 'Disabling LazyLoad turns off lazy load' ); - Config::withConfig( - function () use ($image) { - Config::modify()->set(Image::class, 'lazy_loading_enabled', false); - $this->assertFalse( - $image->IsLazyLoaded(), - 'Disabling LazyLoad globally turns off lazy load' - ); - } - ); + Config::withConfig(function () use ($image) { + Config::modify()->set(Image::class, 'lazy_loading_enabled', false); + $this->assertFalse( + $image->IsLazyLoaded(), + 'Disabling LazyLoad globally turns off lazy load' + ); + }); $file = File::create(); $file->setFromString('boom', 'boom.txt'); @@ -296,9 +275,7 @@ function () use ($image) { public function testAttributesHTML() { - /** - * @var Image $origin -*/ + /** @var Image $origin*/ $image = $this->objFromFixture(Image::class, 'imageWithTitle'); $this->assertEquals( 'width="300" height="300" alt="This is a image Title" src="/assets/ImageTest/folder/test-image.png" loading="lazy"', @@ -325,15 +302,13 @@ public function lazyLoadProvider() } /** - * @param $val - * @param $expected + * @param $val + * @param $expected * @dataProvider lazyLoadProvider */ public function testLazyLoad($val, bool $expected) { - /** - * @var Image $origin -*/ + /** @var Image $origin */ $image = $this->objFromFixture(Image::class, 'imageWithTitle'); $newImg = $image->LazyLoad($val); @@ -362,14 +337,12 @@ public function lazyLoadBadProvider() } /** - * @param $val + * @param $val * @dataProvider lazyLoadBadProvider */ public function testBadLazyLoad($val) { - /** - * @var Image $origin -*/ + /** @var Image $origin */ $image = $this->objFromFixture(Image::class, 'imageWithTitle'); $newImg = $image->LazyLoad($val); @@ -397,9 +370,7 @@ public function testLazyLoadIsAccessibleInExtensions() { Image::add_extension(LazyLoadAccessorExtension::class); - /** - * @var Image $origin -*/ + /** @var Image $origin */ $image = $this->objFromFixture(Image::class, 'imageWithTitle'); $this->assertTrue( @@ -474,9 +445,7 @@ public function renderProvider() */ public function testRender(string $template, string $expected) { - /** - * @var Image $origin -*/ + /** @var Image $origin */ $image = $this->objFromFixture(Image::class, 'imageWithTitle'); $this->assertEquals( @@ -501,9 +470,7 @@ public function testThumbnailURL() 'Thumbnail URL is correct' ); - /** - * @var AssetStore assetStore -*/ + /** @var AssetStore assetStore */ $assetStore = Injector::inst()->get(AssetStore::class); $this->assertFalse( $assetStore->isGranted($fileUrl), @@ -620,9 +587,7 @@ public function testConvert(string $originalFileFixtureClass, string $originalFi { // Make sure we have a known set of converters for testing FileConverterManager::config()->set('converters', [TestTxtToImageConverter::class]); - /** - * @var File $file -*/ + /** @var File $file */ $file = $this->objFromFixture($originalFileFixtureClass, $originalFileFixture); // Set up mock logger so we can check the exception gets logged