Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

PHPDoc for EntryInterface::getAuthor is incorrect #83

Closed
2 tasks done
Synchro opened this issue Jun 22, 2018 · 1 comment
Closed
2 tasks done

PHPDoc for EntryInterface::getAuthor is incorrect #83

Synchro opened this issue Jun 22, 2018 · 1 comment
Labels

Comments

@Synchro
Copy link
Contributor

Synchro commented Jun 22, 2018

My IDE flagged a type mismatch on the results of a call to Entry::getAuthor() when there shouldn't be one.

Code to reproduce the issue

This line declares the interface for getAuthor as returning string|null, and the implementation in the Rss class declares it returns a string (and doesn't mention null), but it really returns an associative array containing a single name element, because it returns a single element of the return value of getAuthors(), as seen in this implementation in the Rss class.

The Atom class does something similar, but it's not quite the same as it doesn't build the assoc array with the name element, so it may actually be returning a string (I don't know exactly what $this->getExtension('Atom')->getAuthors() returns).

The PHPDocs need to be made consistent, and/or the function needs to be modified so it really does return a string and not an array. Altering the return type would be a BC break, even though it's not meant to work that way, so I suspect the PHPdoc change would be more appropriate.

@froschdesign
Copy link
Member

It's an array:

/**
* Get Author (Unencoded Text)
*/
public function testGetsAuthorFromAtom03()
{
$feed = Reader\Reader::importString(
file_get_contents($this->feedSamplePath . '/author/plain/atom03.xml')
);
$entry = $feed->current();
$this->assertEquals(
['name' => 'Joe Bloggs', 'email' => 'joe@example.com', 'uri' => 'http://www.example.com'],
$entry->getAuthor()
);
}
public function testGetsAuthorFromAtom10()
{
$feed = Reader\Reader::importString(
file_get_contents($this->feedSamplePath . '/author/plain/atom10.xml')
);
$entry = $feed->current();
$this->assertEquals(
['name' => 'Joe Bloggs', 'email' => 'joe@example.com', 'uri' => 'http://www.example.com'],
$entry->getAuthor()
);
}

public function testGetsAuthorFromRss20()
{
$feed = Reader\Reader::importString(
file_get_contents($this->feedSamplePath.'/author/plain/rss20.xml')
);
$entry = $feed->current();
$this->assertEquals(['name' => 'Joe Bloggs', 'email' => 'joe@example.com'], $entry->getAuthor());
}

weierophinney added a commit that referenced this issue Mar 5, 2019
Fixes #83 - PHPDoc for EntryInterface::getAuthor is incorrect
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants