1212use Magento \Framework \App \Filesystem \DirectoryList ;
1313use Magento \Framework \Encryption \Encryptor ;
1414use Magento \Framework \Encryption \EncryptorInterface ;
15- use Magento \Framework \Exception \FileSystemException ;
1615use Magento \Framework \Filesystem ;
1716use Magento \Framework \Filesystem \Directory \WriteInterface ;
1817use Magento \Framework \View \ConfigInterface ;
1918
2019/**
2120 * Delete image from cache
22- *
23- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2421 */
2522class RemoveDeletedImagesFromCache
2623{
@@ -61,7 +58,6 @@ class RemoveDeletedImagesFromCache
6158 * @param Filesystem $filesystem
6259 * @param ParamsBuilder $imageParamsBuilder
6360 * @param ConvertImageMiscParamsToReadableFormat $convertImageMiscParamsToReadableFormat
64- * @throws FileSystemException
6561 */
6662 public function __construct (
6763 ConfigInterface $ presentationConfig ,
@@ -83,38 +79,40 @@ public function __construct(
8379 * Remove deleted images from cache.
8480 *
8581 * @param array $files
86- * @throws FileSystemException
82+ *
83+ * @return void
8784 */
88- public function removeDeletedImagesFromCache (array $ files )
85+ public function removeDeletedImagesFromCache (array $ files ): void
8986 {
90- if (count ($ files ) > 0 ) {
91- $ images = $ this ->presentationConfig
92- ->getViewConfig (['area ' => \Magento \Framework \App \Area::AREA_FRONTEND ])
93- ->getMediaEntities (
94- 'Magento_Catalog ' ,
95- Image::MEDIA_TYPE_CONFIG_NODE
96- );
87+ if (count ($ files ) === 0 ) {
88+ return ;
89+ }
90+ $ images = $ this ->presentationConfig
91+ ->getViewConfig (['area ' => \Magento \Framework \App \Area::AREA_FRONTEND ])
92+ ->getMediaEntities (
93+ 'Magento_Catalog ' ,
94+ Image::MEDIA_TYPE_CONFIG_NODE
95+ );
9796
98- foreach ($ images as $ imageData ) {
99- $ imageMiscParams = $ this ->imageParamsBuilder ->build ($ imageData );
97+ foreach ($ images as $ imageData ) {
98+ $ imageMiscParams = $ this ->imageParamsBuilder ->build ($ imageData );
10099
101- if (isset ($ imageMiscParams ['image_type ' ])) {
102- unset($ imageMiscParams ['image_type ' ]);
103- }
100+ if (isset ($ imageMiscParams ['image_type ' ])) {
101+ unset($ imageMiscParams ['image_type ' ]);
102+ }
104103
105- $ cacheId = $ this ->encryptor ->hash (
106- implode ('_ ' , $ this ->convertImageMiscParamsToReadableFormat
107- ->convertImageMiscParamsToReadableFormat ($ imageMiscParams )),
108- Encryptor::HASH_VERSION_MD5
109- );
104+ $ cacheId = $ this ->encryptor ->hash (
105+ implode ('_ ' , $ this ->convertImageMiscParamsToReadableFormat
106+ ->convertImageMiscParamsToReadableFormat ($ imageMiscParams )),
107+ Encryptor::HASH_VERSION_MD5
108+ );
110109
111- $ catalogPath = $ this ->mediaConfig ->getBaseMediaPath ();
110+ $ catalogPath = $ this ->mediaConfig ->getBaseMediaPath ();
112111
113- foreach ($ files as $ filePath ) {
114- $ this ->mediaDirectory ->delete (
115- $ catalogPath . '/cache/ ' . $ cacheId . '/ ' . $ filePath
116- );
117- }
112+ foreach ($ files as $ filePath ) {
113+ $ this ->mediaDirectory ->delete (
114+ $ catalogPath . '/cache/ ' . $ cacheId . '/ ' . $ filePath
115+ );
118116 }
119117 }
120118 }
0 commit comments