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}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getSize() {
|
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}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getCreatedTime() {
|
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
|
* This may differ from the basename of the URI if the file is renamed to
|
||||||
* avoid overwriting an existing file.
|
* avoid overwriting an existing file.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string|null
|
||||||
* Name of the file.
|
* Name of the file, or NULL if unknown.
|
||||||
*/
|
*/
|
||||||
public function getFilename();
|
public function getFilename();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the name of the file.
|
* Sets the name of the file.
|
||||||
*
|
*
|
||||||
* @param string $filename
|
* @param string|null $filename
|
||||||
* The file name that corresponds to this file. May differ from the basename
|
* The file name that corresponds to this file, or NULL if unknown. May
|
||||||
* of the URI and changing the filename does not change the URI.
|
* differ from the basename of the URI and changing the filename does not
|
||||||
|
* change the URI.
|
||||||
*/
|
*/
|
||||||
public function setFilename($filename);
|
public function setFilename($filename);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the URI of the file.
|
* Returns the URI of the file.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string|null
|
||||||
* The URI of the file, e.g. public://directory/file.jpg.
|
* The URI of the file, e.g. public://directory/file.jpg, or NULL if it has
|
||||||
|
* not yet been set.
|
||||||
*/
|
*/
|
||||||
public function getFileUri();
|
public function getFileUri();
|
||||||
|
|
||||||
|
@ -75,32 +77,34 @@ interface FileInterface extends ContentEntityInterface, EntityChangedInterface,
|
||||||
/**
|
/**
|
||||||
* Returns the MIME type of the file.
|
* Returns the MIME type of the file.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string|null
|
||||||
* The MIME type of the file, e.g. image/jpeg or text/xml.
|
* The MIME type of the file, e.g. image/jpeg or text/xml, or NULL if it
|
||||||
|
* could not be determined.
|
||||||
*/
|
*/
|
||||||
public function getMimeType();
|
public function getMimeType();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the MIME type of the file.
|
* Sets the MIME type of the file.
|
||||||
*
|
*
|
||||||
* @param string $mime
|
* @param string|null $mime
|
||||||
* The MIME type of the file, e.g. image/jpeg or text/xml.
|
* 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);
|
public function setMimeType($mime);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the size of the file.
|
* Returns the size of the file.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return int|null
|
||||||
* The size of the file in bytes.
|
* The size of the file in bytes, or NULL if it could not be determined.
|
||||||
*/
|
*/
|
||||||
public function getSize();
|
public function getSize();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the size of the file.
|
* Sets the size of the file.
|
||||||
*
|
*
|
||||||
* @param int $size
|
* @param int|null $size
|
||||||
* The size of the file in bytes.
|
* The size of the file in bytes, or NULL if it could not be determined.
|
||||||
*/
|
*/
|
||||||
public function setSize($size);
|
public function setSize($size);
|
||||||
|
|
||||||
|
@ -133,8 +137,8 @@ interface FileInterface extends ContentEntityInterface, EntityChangedInterface,
|
||||||
/**
|
/**
|
||||||
* Returns the file entity creation timestamp.
|
* Returns the file entity creation timestamp.
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int|null
|
||||||
* Creation timestamp of the file entity.
|
* Creation timestamp of the file entity, or NULL if unknown.
|
||||||
*/
|
*/
|
||||||
public function getCreatedTime();
|
public function getCreatedTime();
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ class MigrateFileTest extends MigrateDrupal7TestBase {
|
||||||
* Tests that all expected files are migrated.
|
* Tests that all expected files are migrated.
|
||||||
*/
|
*/
|
||||||
public function testFileMigration() {
|
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.
|
// Ensure temporary file was not migrated.
|
||||||
$this->assertNull(File::load(4));
|
$this->assertNull(File::load(4));
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ class MigratePrivateFileTest extends MigrateDrupal7TestBase {
|
||||||
* Tests that all expected files are migrated.
|
* Tests that all expected files are migrated.
|
||||||
*/
|
*/
|
||||||
public function testFileMigration() {
|
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('image-test.jpg', $file->getFilename());
|
||||||
$this->assertSame('public://image-test.jpg', $file->getFileUri());
|
$this->assertSame('public://image-test.jpg', $file->getFileUri());
|
||||||
$this->assertSame('2', $file->getOwnerId());
|
$this->assertSame('2', $file->getOwnerId());
|
||||||
$this->assertSame('1901', $file->getSize());
|
$this->assertSame(1901, $file->getSize());
|
||||||
$this->assertSame('image/jpeg', $file->getMimeType());
|
$this->assertSame('image/jpeg', $file->getMimeType());
|
||||||
|
|
||||||
$file = array_shift($files);
|
$file = array_shift($files);
|
||||||
|
|
Loading…
Reference in New Issue