12
12
use Magento \Framework \App \Filesystem \DirectoryList ;
13
13
use Magento \Framework \Encryption \Encryptor ;
14
14
use Magento \Framework \Encryption \EncryptorInterface ;
15
- use Magento \Framework \Exception \FileSystemException ;
16
15
use Magento \Framework \Filesystem ;
17
16
use Magento \Framework \Filesystem \Directory \WriteInterface ;
18
17
use Magento \Framework \View \ConfigInterface ;
19
18
20
19
/**
21
20
* Delete image from cache
22
- *
23
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
24
21
*/
25
22
class RemoveDeletedImagesFromCache
26
23
{
@@ -61,7 +58,6 @@ class RemoveDeletedImagesFromCache
61
58
* @param Filesystem $filesystem
62
59
* @param ParamsBuilder $imageParamsBuilder
63
60
* @param ConvertImageMiscParamsToReadableFormat $convertImageMiscParamsToReadableFormat
64
- * @throws FileSystemException
65
61
*/
66
62
public function __construct (
67
63
ConfigInterface $ presentationConfig ,
@@ -83,38 +79,40 @@ public function __construct(
83
79
* Remove deleted images from cache.
84
80
*
85
81
* @param array $files
86
- * @throws FileSystemException
82
+ *
83
+ * @return void
87
84
*/
88
- public function removeDeletedImagesFromCache (array $ files )
85
+ public function removeDeletedImagesFromCache (array $ files ): void
89
86
{
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
+ );
97
96
98
- foreach ($ images as $ imageData ) {
99
- $ imageMiscParams = $ this ->imageParamsBuilder ->build ($ imageData );
97
+ foreach ($ images as $ imageData ) {
98
+ $ imageMiscParams = $ this ->imageParamsBuilder ->build ($ imageData );
100
99
101
- if (isset ($ imageMiscParams ['image_type ' ])) {
102
- unset($ imageMiscParams ['image_type ' ]);
103
- }
100
+ if (isset ($ imageMiscParams ['image_type ' ])) {
101
+ unset($ imageMiscParams ['image_type ' ]);
102
+ }
104
103
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
+ );
110
109
111
- $ catalogPath = $ this ->mediaConfig ->getBaseMediaPath ();
110
+ $ catalogPath = $ this ->mediaConfig ->getBaseMediaPath ();
112
111
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
+ );
118
116
}
119
117
}
120
118
}
0 commit comments