From ca9617422a0d67693fbdec8d514893c5a10f3ecd Mon Sep 17 00:00:00 2001 From: itismadness Date: Sat, 3 Oct 2020 20:31:03 +0000 Subject: [PATCH] add getCreationDate method --- src/BencodeTorrent.php | 18 ++++++++++++------ tests/BencodeTorrentTest.php | 1 + 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/BencodeTorrent.php b/src/BencodeTorrent.php index b6ba2f2..311fe5a 100644 --- a/src/BencodeTorrent.php +++ b/src/BencodeTorrent.php @@ -209,10 +209,6 @@ class BencodeTorrent extends Bencode * 'official' flag (no accepted BEP on it), but it has become the defacto standard with more * clients supporting it natively. Returns a boolean on whether or not the source was changed * so that an appropriate screen can be shown to the user. - * - * @param string $source - * - * @return bool true if the source was set/changed, false if no change */ public function setSource(string $source): bool { @@ -228,19 +224,29 @@ class BencodeTorrent extends Bencode return true; } + /** + * Get the source flag if one has been set + */ public function getSource(): ?string { $this->hasData(); return $this->data['info']['source'] ?? null; } + /** + * Get the creation date for torrent if one has been set + */ + public function getCreationDate(): ?int + { + $this->hasData(); + return $this->data['creation date'] ?? null; + } + /** * Function to allow you set any number of keys and values in the data dictionary. You can * set the value in a dictionary by concatenating the keys into a string with a period * separator (ex: info.name will set name field in the info dictionary) so that the rest * of the dictionary is unaffected. - * - * @param array $array */ public function setValue(array $array): void { diff --git a/tests/BencodeTorrentTest.php b/tests/BencodeTorrentTest.php index c3ec442..1c6b617 100644 --- a/tests/BencodeTorrentTest.php +++ b/tests/BencodeTorrentTest.php @@ -144,6 +144,7 @@ class BencodeTorrentTest extends \PHPUnit\Framework\TestCase ] ]; $this->assertEquals($file_list, $bencode->getFileList()); + $this->assertSame(1425699508, $bencode->getCreationDate()); } public function testSetData(): void