Skip to content

Commit

Permalink
Initial fixes for raising PHPStan level to 6
Browse files Browse the repository at this point in the history
Will still require more work on filling in array item types.
  • Loading branch information
jtojnar committed Feb 8, 2023
1 parent ffec474 commit 8a6d6e7
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/controllers/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(Authentication $authentication, \daos\Tags $tagsDao,
$this->view = $view;
}

/* @var ?array<string, array{backColor: string, foreColor: string}> cache of tags and associated colors */
/** @var ?array<string, array{backColor: string, foreColor: string}> cache of tags and associated colors */
protected $tagsColors = null;

/**
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/ImageUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @author Tobias Zeising <[email protected]>
*/
class ImageUtils {
private static $iconRelWeights = [
private const ICON_REL_WEIGHTS = [
'apple-touch-icon-precomposed' => 3,
'apple-touch-icon' => 2,
'shortcut icon' => 1,
Expand Down Expand Up @@ -91,7 +91,7 @@ public static function parseShortcutIcons(string $html): array {

// then by rel priority
[function($val) {
return self::$iconRelWeights[$val['rel']];
return self::ICON_REL_WEIGHTS[$val['rel']];
}, Misc::ORDER_DESC],

// and finally by order to make the sorting stable
Expand Down
3 changes: 2 additions & 1 deletion src/helpers/SimplePieFileGuzzle.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ class SimplePieFileGuzzle extends File {
* @param ?array<string,string> $headers
* @param ?string $useragent
* @param bool $force_fsockopen
* @param array $curl_options
* @param array{'helpers\WebClient'?: WebClient} $curl_options
*/
public function __construct($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false, $curl_options = []) {
assert(isset($curl_options[WebClient::class]));
$this->webClient = $curl_options[WebClient::class];
$this->url = $url;
$this->permanent_url = $url;
Expand Down
10 changes: 5 additions & 5 deletions src/helpers/SpoutLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* @author Tobias Zeising <[email protected]>
*/
class SpoutLoader {
/** @var ?array<class-string<spout>, spout> array of available spouts */
/** @var ?array<class-string<spout<mixed>>, spout<mixed>> array of available spouts */
private $spouts = null;

/** @var Dice dependency injection container */
Expand All @@ -29,7 +29,7 @@ public function __construct(Dice $dice) {
/**
* returns all available spouts
*
* @return array<class-string<spout>, spout> available spouts
* @return array<class-string<spout<mixed>>, spout<mixed>> available spouts
*/
public function all(): array {
$this->readSpouts();
Expand All @@ -42,7 +42,7 @@ public function all(): array {
*
* @param class-string $spout a given spout type
*
* @return ?spout an instance of the spout, null if this spout doesn't exist
* @return ?spout<mixed> an instance of the spout, null if this spout doesn't exist
*/
public function get(string $spout): ?spout {
if (!class_exists($spout)) {
Expand Down Expand Up @@ -118,8 +118,8 @@ protected function loadClasses(string $location, string $parentClassName): array
/**
* compare spouts by name
*
* @param spout $spout1 Spout 1
* @param spout $spout2 Spout 2
* @param spout<mixed> $spout1 Spout 1
* @param spout<mixed> $spout2 Spout 2
*/
private static function compareSpoutsByName(spout $spout1, spout $spout2): int {
return strcasecmp($spout1->name, $spout2->name);
Expand Down
24 changes: 24 additions & 0 deletions src/spouts/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ public function getId(): string {
return $this->id;
}

/**
* @return static
*/
public function withId(string $id): self {
$modified = clone $this;
$modified->id = $id;
Expand All @@ -90,6 +93,9 @@ public function getTitle(): string {
return $this->title;
}

/**
* @return static
*/
public function withTitle(string $title): self {
$modified = clone $this;
$modified->title = $title;
Expand All @@ -107,6 +113,9 @@ public function getContent(): string {
return $this->content;
}

/**
* @return static
*/
public function withContent(string $content): self {
$modified = clone $this;
$modified->content = $content;
Expand All @@ -121,6 +130,9 @@ public function getThumbnail(): ?string {
return $this->thumbnail;
}

/**
* @return static
*/
public function withThumbnail(?string $thumbnail): self {
$modified = clone $this;
$modified->thumbnail = $thumbnail;
Expand All @@ -135,6 +147,9 @@ public function getIcon(): ?string {
return $this->icon;
}

/**
* @return static
*/
public function withIcon(?string $icon): self {
$modified = clone $this;
$modified->icon = $icon;
Expand All @@ -149,6 +164,9 @@ public function getLink(): string {
return $this->link;
}

/**
* @return static
*/
public function withLink(string $link): self {
$modified = clone $this;
$modified->link = $link;
Expand All @@ -163,6 +181,9 @@ public function getDate(): ?DateTimeInterface {
return $this->date;
}

/**
* @return static
*/
public function withDate(?DateTimeInterface $date = null): self {
$modified = clone $this;
$modified->date = $date;
Expand All @@ -179,6 +200,9 @@ public function getAuthor(): ?string {
return $this->author;
}

/**
* @return static
*/
public function withAuthor(?string $author): self {
$modified = clone $this;
$modified->author = $author;
Expand Down
2 changes: 2 additions & 0 deletions src/spouts/facebook/page.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
* @license GPLv3 (https://www.gnu.org/licenses/gpl-3.0.html)
* @author Tobias Zeising <[email protected]>
* @author Jan Tojnar <[email protected]>
*
* @extends \spouts\spout<null>
*/
class page extends \spouts\spout {
/** @var string name of source */
Expand Down
2 changes: 2 additions & 0 deletions src/spouts/github/commits.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* @license GPLv3 (https://www.gnu.org/licenses/gpl-3.0.html)
* @author Tobias Zeising <[email protected]>
* @author Tim Gerundt <[email protected]>
*
* @extends \spouts\spout<null>
*/
class commits extends \spouts\spout {
/** @var string name of source */
Expand Down
4 changes: 3 additions & 1 deletion src/spouts/reddit/reddit2.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
* @copyright Copyright (c) Tobias Zeising (http://www.aditu.de)
* @license GPLv3 (https://www.gnu.org/licenses/gpl-3.0.html)
* @author Tobias Zeising <[email protected]>
*
* @extends \spouts\spout<null>
*/
class reddit2 extends \spouts\spout {
/** @var string name of spout */
Expand Down Expand Up @@ -202,7 +204,7 @@ public function destroy(): void {
* Sign in to reddit using the credentials in params and save a session cookie
* for further requests.
*
* @param array $params source parameters
* @param array<string, string> $params source parameters
*
* @throws GuzzleHttp\Exception\GuzzleException When an error is encountered
* @throws \RuntimeException if the response body is not in JSON format
Expand Down
4 changes: 3 additions & 1 deletion src/spouts/twitter/usertimeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
* @copyright Copyright (c) Tobias Zeising (http://www.aditu.de)
* @license GPLv3 (https://www.gnu.org/licenses/gpl-3.0.html)
* @author Tobias Zeising <[email protected]>
*
* @extends \spouts\spout<null>
*/
class usertimeline extends \spouts\spout {
/** @var string name of source */
Expand Down Expand Up @@ -126,7 +128,7 @@ public function getHttpClient(
* Assumes client property is initialized to Guzzle client configured to access Twitter.
*
* @param string $endpoint API endpoint to use
* @param array $params extra query arguments to pass to the API call
* @param array<string, string> $params extra query arguments to pass to the API call
*
* @throws \Exception when API request fails
* @throws GuzzleHttp\Exception\GuzzleException when HTTP request fails for API-unrelated reasons
Expand Down
5 changes: 4 additions & 1 deletion tests/Spouts/YouTubeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ public function testBasic(string $url, string $feedTitle, string $firstItemTitle
$this->assertEquals($firstItemTitle, $yt->getItems()->current()->getTitle());
}

public function dataProvider() {
/**
* @return array<array{url: string, feedTitle: string, firstItemTitle: string}>
*/
public function dataProvider(): array {
return [
[
'url' => 'https://www.youtube.com/user/ZoggFromBetelgeuse',
Expand Down

0 comments on commit 8a6d6e7

Please sign in to comment.