Skip to content

Commit 89e7f22

Browse files
author
joweecaquicla
committed
magento/adobe-stock-integration#1727: Introduce internal class wrapping SplFileInfo - apply requested changes
1 parent 0b6ba91 commit 89e7f22

File tree

4 files changed

+36
-155
lines changed

4 files changed

+36
-155
lines changed

app/code/Magento/MediaGallerySynchronization/Model/CreateAssetFromFile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function execute(string $path): AssetInterface
110110
[
111111
'id' => null,
112112
'path' => $path,
113-
'title' => $metadata->getTitle() ?: $file->getBasename('.' . $file->getExtension()),
113+
'title' => $metadata->getTitle() ?: $file->getBasename(),
114114
'description' => $metadata->getDescription(),
115115
'createdAt' => $this->date->date($file->getCTime())->format(self::DATE_FORMAT),
116116
'updatedAt' => $this->date->date($file->getMTime())->format(self::DATE_FORMAT),

app/code/Magento/MediaGallerySynchronization/Model/Filesystem/FileInfo.php

Lines changed: 26 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
namespace Magento\MediaGallerySynchronization\Model\Filesystem;
99

1010
/**
11-
* Internal class wrapping \SplFileInfo
12-
*
13-
* @SuppressWarnings(PHPMD.TooManyFields)
11+
* Class for getting image file information.
1412
*/
15-
class FileInfo extends \SplFileInfo
13+
class FileInfo
1614
{
1715
/**
1816
* @var string
@@ -34,36 +32,11 @@ class FileInfo extends \SplFileInfo
3432
*/
3533
private $basename;
3634

37-
/**
38-
* @var string
39-
*/
40-
private $pathname;
41-
42-
/**
43-
* @var int
44-
*/
45-
private $inode;
46-
4735
/**
4836
* @var int
4937
*/
5038
private $size;
5139

52-
/**
53-
* @var int
54-
*/
55-
private $owner;
56-
57-
/**
58-
* @var int
59-
*/
60-
private $group;
61-
62-
/**
63-
* @var int
64-
*/
65-
private $aTime;
66-
6740
/**
6841
* @var int
6942
*/
@@ -74,178 +47,102 @@ class FileInfo extends \SplFileInfo
7447
*/
7548
private $cTime;
7649

77-
/**
78-
* @var string
79-
*/
80-
private $type;
81-
82-
/**
83-
* @var false|string
84-
*/
85-
private $realPath;
86-
8750
/**
8851
* FileInfo constructor.
89-
* @param string $file_name
52+
*
9053
* @param string $path
9154
* @param string $filename
9255
* @param string $extension
9356
* @param string $basename
94-
* @param string $pathname
95-
* @param int $inode
9657
* @param int $size
97-
* @param int $owner
98-
* @param int $group
99-
* @param int $aTime
10058
* @param int $mTime
10159
* @param int $cTime
102-
* @param string $type
103-
* @param false|string $realPath
104-
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
10560
*/
10661
public function __construct(
107-
string $file_name,
10862
string $path,
10963
string $filename,
11064
string $extension,
11165
string $basename,
112-
string $pathname,
113-
int $inode,
11466
int $size,
115-
int $owner,
116-
int $group,
117-
int $aTime,
11867
int $mTime,
119-
int $cTime,
120-
string $type,
121-
$realPath
68+
int $cTime
12269
) {
123-
parent::__construct($file_name);
12470
$this->path = $path;
12571
$this->filename = $filename;
12672
$this->extension = $extension;
12773
$this->basename = $basename;
128-
$this->pathname = $pathname;
129-
$this->inode = $inode;
13074
$this->size = $size;
131-
$this->owner = $owner;
132-
$this->group = $group;
133-
$this->aTime = $aTime;
13475
$this->mTime = $mTime;
13576
$this->cTime = $cTime;
136-
$this->type = $type;
137-
$this->realPath = $realPath;
13877
}
13978

14079
/**
141-
* @inheritDoc
80+
* Get path without filename.
81+
*
82+
* @return string
14283
*/
14384
public function getPath(): string
14485
{
14586
return $this->path;
14687
}
14788

14889
/**
149-
* @inheritDoc
90+
* Get filename.
91+
*
92+
* @return string
15093
*/
15194
public function getFilename(): string
15295
{
15396
return $this->filename;
15497
}
15598

15699
/**
157-
* @inheritDoc
100+
* Get file extension.
101+
*
102+
* @return string
158103
*/
159104
public function getExtension(): string
160105
{
161106
return $this->extension;
162107
}
163108

164109
/**
165-
* @inheritDoc
110+
* Get file basename.
111+
*
112+
* @return string
166113
*/
167-
public function getBasename($suffix = null): string
114+
public function getBasename(): string
168115
{
169116
return $this->basename;
170117
}
171118

172119
/**
173-
* @inheritDoc
174-
*/
175-
public function getPathname(): string
176-
{
177-
return $this->pathname;
178-
}
179-
180-
/**
181-
* @inheritDoc
182-
*/
183-
public function getInode(): int
184-
{
185-
return $this->inode;
186-
}
187-
188-
/**
189-
* @inheritDoc
120+
* Get file size.
121+
*
122+
* @return int
190123
*/
191124
public function getSize(): int
192125
{
193126
return $this->size;
194127
}
195128

196129
/**
197-
* @inheritDoc
198-
*/
199-
public function getOwner(): int
200-
{
201-
return $this->owner;
202-
}
203-
204-
/**
205-
* @inheritDoc
206-
*/
207-
public function getGroup(): int
208-
{
209-
return $this->group;
210-
}
211-
212-
/**
213-
* @inheritDoc
214-
*/
215-
public function getATime(): int
216-
{
217-
return $this->aTime;
218-
}
219-
220-
/**
221-
* @inheritDoc
130+
* Get last modified time.
131+
*
132+
* @return int
222133
*/
223134
public function getMTime(): int
224135
{
225136
return $this->mTime;
226137
}
227138

228139
/**
229-
* @inheritDoc
140+
* Get inode change time.
141+
*
142+
* @return int
230143
*/
231144
public function getCTime(): int
232145
{
233146
return $this->cTime;
234147
}
235-
236-
/**
237-
* @inheritDoc
238-
*/
239-
public function getType(): string
240-
{
241-
return $this->type;
242-
}
243-
244-
/**
245-
* @inheritDoc
246-
*/
247-
public function getRealPath()
248-
{
249-
return $this->realPath;
250-
}
251148
}

app/code/Magento/MediaGallerySynchronization/Model/Filesystem/GetFileInfo.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,13 @@ public function execute(string $path): FileInfo
4040
$splFileInfo = new \SplFileInfo($path);
4141

4242
return $this->fileInfoFactory->create([
43-
'file_name' => $path,
4443
'path' => $splFileInfo->getPath(),
4544
'filename' => $splFileInfo->getFilename(),
4645
'extension' => $splFileInfo->getExtension(),
4746
'basename' => $splFileInfo->getBasename('.' . $splFileInfo->getExtension()),
48-
'pathname' => $splFileInfo->getPathname(),
49-
'perms' => $splFileInfo->getPerms(),
50-
'inode' => $splFileInfo->getInode(),
5147
'size' => $splFileInfo->getSize(),
52-
'owner' => $splFileInfo->getOwner(),
53-
'group' => $splFileInfo->getGroup(),
54-
'aTime' => $splFileInfo->getATime(),
5548
'mTime' => $splFileInfo->getMTime(),
56-
'cTime' => $splFileInfo->getCTime(),
57-
'type' => $splFileInfo->getType(),
58-
'realPath' => $splFileInfo->getRealPath()
49+
'cTime' => $splFileInfo->getCTime()
5950
]);
6051
}
6152
}

app/code/Magento/MediaGallerySynchronization/Test/Integration/Model/Filesystem/GetFileInfoTest.php

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,14 @@ public function testExecute(
4040
$path = $this->getImageFilePath($file);
4141

4242
$fileInfo = $this->getFileInfo->execute($path);
43-
$this->assertNotEmpty($fileInfo->getPath());
44-
$this->assertNotEmpty($fileInfo->getFilename());
45-
$this->assertNotEmpty($fileInfo->getExtension());
46-
$this->assertNotEmpty($fileInfo->getBasename());
47-
$this->assertNotEmpty($fileInfo->getPathname());
48-
$this->assertNotEmpty($fileInfo->getPerms());
49-
$this->assertNotEmpty($fileInfo->getInode());
50-
$this->assertNotEmpty($fileInfo->getSize());
51-
$this->assertNotEmpty($fileInfo->getOwner());
52-
$this->assertNotEmpty($fileInfo->getGroup());
53-
$this->assertNotEmpty($fileInfo->getATime());
54-
$this->assertNotEmpty($fileInfo->getMTime());
55-
$this->assertNotEmpty($fileInfo->getCTime());
56-
$this->assertNotEmpty($fileInfo->getType());
57-
$this->assertNotEmpty($fileInfo->getRealPath());
43+
$expectedResult = new \SplFileInfo($path);
44+
$this->assertEquals($expectedResult->getPath(), $fileInfo->getPath());
45+
$this->assertEquals($expectedResult->getFilename(), $fileInfo->getFilename());
46+
$this->assertEquals($expectedResult->getExtension(), $fileInfo->getExtension());
47+
$this->assertEquals($expectedResult->getBasename('.' . $expectedResult->getExtension()), $fileInfo->getBasename());
48+
$this->assertEquals($expectedResult->getSize(), $fileInfo->getSize());
49+
$this->assertEquals($expectedResult->getMTime(), $fileInfo->getMTime());
50+
$this->assertEquals($expectedResult->getCTime(), $fileInfo->getCTime());
5851
}
5952

6053
/**

0 commit comments

Comments
 (0)