Issue #3262358 by mfb, smustgrave, joachim: Fix type hints in FileInterface to align with reality
parent
c48da9e7a7
commit
1c96bea27e
|
@ -113,7 +113,8 @@ class File extends ContentEntityBase implements FileInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSize() {
|
||||
return $this->get('filesize')->value;
|
||||
$filesize = $this->get('filesize')->value;
|
||||
return isset($filesize) ? (int) $filesize : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -127,7 +128,8 @@ class File extends ContentEntityBase implements FileInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCreatedTime() {
|
||||
return $this->get('created')->value;
|
||||
$created = $this->get('created')->value;
|
||||
return isset($created) ? (int) $created : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -28,25 +28,27 @@ interface FileInterface extends ContentEntityInterface, EntityChangedInterface,
|
|||
* This may differ from the basename of the URI if the file is renamed to
|
||||
* avoid overwriting an existing file.
|
||||
*
|
||||
* @return string
|
||||
* Name of the file.
|
||||
* @return string|null
|
||||
* Name of the file, or NULL if unknown.
|
||||
*/
|
||||
public function getFilename();
|
||||
|
||||
/**
|
||||
* Sets the name of the file.
|
||||
*
|
||||
* @param string $filename
|
||||
* The file name that corresponds to this file. May differ from the basename
|
||||
* of the URI and changing the filename does not change the URI.
|
||||
* @param string|null $filename
|
||||
* The file name that corresponds to this file, or NULL if unknown. May
|
||||
* differ from the basename of the URI and changing the filename does not
|
||||
* change the URI.
|
||||
*/
|
||||
public function setFilename($filename);
|
||||
|
||||
/**
|
||||
* Returns the URI of the file.
|
||||
*
|
||||
* @return string
|
||||
* The URI of the file, e.g. public://directory/file.jpg.
|
||||
* @return string|null
|
||||
* The URI of the file, e.g. public://directory/file.jpg, or NULL if it has
|
||||
* not yet been set.
|
||||
*/
|
||||
public function getFileUri();
|
||||
|
||||
|
@ -75,32 +77,34 @@ interface FileInterface extends ContentEntityInterface, EntityChangedInterface,
|
|||
/**
|
||||
* Returns the MIME type of the file.
|
||||
*
|
||||
* @return string
|
||||
* The MIME type of the file, e.g. image/jpeg or text/xml.
|
||||
* @return string|null
|
||||
* The MIME type of the file, e.g. image/jpeg or text/xml, or NULL if it
|
||||
* could not be determined.
|
||||
*/
|
||||
public function getMimeType();
|
||||
|
||||
/**
|
||||
* Sets the MIME type of the file.
|
||||
*
|
||||
* @param string $mime
|
||||
* The MIME type of the file, e.g. image/jpeg or text/xml.
|
||||
* @param string|null $mime
|
||||
* The MIME type of the file, e.g. image/jpeg or text/xml, or NULL if it
|
||||
* could not be determined.
|
||||
*/
|
||||
public function setMimeType($mime);
|
||||
|
||||
/**
|
||||
* Returns the size of the file.
|
||||
*
|
||||
* @return string
|
||||
* The size of the file in bytes.
|
||||
* @return int|null
|
||||
* The size of the file in bytes, or NULL if it could not be determined.
|
||||
*/
|
||||
public function getSize();
|
||||
|
||||
/**
|
||||
* Sets the size of the file.
|
||||
*
|
||||
* @param int $size
|
||||
* The size of the file in bytes.
|
||||
* @param int|null $size
|
||||
* The size of the file in bytes, or NULL if it could not be determined.
|
||||
*/
|
||||
public function setSize($size);
|
||||
|
||||
|
@ -133,8 +137,8 @@ interface FileInterface extends ContentEntityInterface, EntityChangedInterface,
|
|||
/**
|
||||
* Returns the file entity creation timestamp.
|
||||
*
|
||||
* @return int
|
||||
* Creation timestamp of the file entity.
|
||||
* @return int|null
|
||||
* Creation timestamp of the file entity, or NULL if unknown.
|
||||
*/
|
||||
public function getCreatedTime();
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ class MigrateFileTest extends MigrateDrupal7TestBase {
|
|||
* Tests that all expected files are migrated.
|
||||
*/
|
||||
public function testFileMigration() {
|
||||
$this->assertEntity(1, 'cube.jpeg', 'public://cube.jpeg', 'image/jpeg', '3620', '1421727515', '1421727515', '1');
|
||||
$this->assertEntity(1, 'cube.jpeg', 'public://cube.jpeg', 'image/jpeg', 3620, 1421727515, '1421727515', '1');
|
||||
// Ensure temporary file was not migrated.
|
||||
$this->assertNull(File::load(4));
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ class MigratePrivateFileTest extends MigrateDrupal7TestBase {
|
|||
* Tests that all expected files are migrated.
|
||||
*/
|
||||
public function testFileMigration() {
|
||||
$this->assertEntity(3, 'Babylon5.txt', 'private://Babylon5.txt', 'text/plain', '3', '1486104045', '1486104045', '1');
|
||||
$this->assertEntity(3, 'Babylon5.txt', 'private://Babylon5.txt', 'text/plain', 3, 1486104045, '1486104045', '1');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ class MigrateUserPictureD6FileTest extends MigrateDrupal6TestBase {
|
|||
$this->assertSame('image-test.jpg', $file->getFilename());
|
||||
$this->assertSame('public://image-test.jpg', $file->getFileUri());
|
||||
$this->assertSame('2', $file->getOwnerId());
|
||||
$this->assertSame('1901', $file->getSize());
|
||||
$this->assertSame(1901, $file->getSize());
|
||||
$this->assertSame('image/jpeg', $file->getMimeType());
|
||||
|
||||
$file = array_shift($files);
|
||||
|
|
Loading…
Reference in New Issue