Skip to content

Commit

Permalink
Fix some issues reported by phpstan2
Browse files Browse the repository at this point in the history
  • Loading branch information
CatoTH committed Nov 17, 2024
1 parent da0c515 commit 0e70b0e
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 21 deletions.
4 changes: 2 additions & 2 deletions models/db/ConsultationUserGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ public static function loadGroupsByIdForConsultation(Consultation $consultation,
// Iterating over the userIds attached to a user group is faster than over the groupIds of a user,
// as there are way more users, and we would need to perform more queries that way.
// Note that this method should only be used for read-only operations, as the cache is not flushed yet.
/** @var null|int[][] */
private static ?array $userIdCache = [];
/** @var int[][] */
private static array $userIdCache = [];

public function getUserIds(): array
{
Expand Down
3 changes: 1 addition & 2 deletions models/db/MotionSection.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,8 @@ public function getConsultation(): Consultation
if ($motion) {
return Consultation::findOne($motion->consultationId);
} else {
/** @var Motion $motion */
$section = ConsultationSettingsMotionSection::findOne($this->sectionId);
/** @var ConsultationSettingsMotionSection $section */
$section = ConsultationSettingsMotionSection::findOne($this->sectionId);
return $section->motionType->getConsultation();
}
}
Expand Down
1 change: 0 additions & 1 deletion models/db/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ public static function findIdentity($userId)
* @return IdentityInterface the identity object that matches the given token.
* Null should be returned if such an identity cannot be found
* or the identity is not in an active state (disabled, deleted, etc.)
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public static function findIdentityByAccessToken($token, $type = null)
{
Expand Down
4 changes: 2 additions & 2 deletions models/forms/AdminMotionFilterForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ public function getFilteredMotions(): array
$matches = false;
}

if ($this->status !== null && $this->status !== '' && $motion->status !== $this->status) {
if ($this->status !== null && $motion->status !== $this->status) {
$matches = false;
}

Expand Down Expand Up @@ -756,7 +756,7 @@ public function getFilteredAmendments(array $filteredMotions): array
$matches = false;
}

if ($this->status !== null && $this->status !== "" && $amend->status !== $this->status) {
if ($this->status !== null && $amend->status !== $this->status) {
$matches = false;
}

Expand Down
2 changes: 1 addition & 1 deletion models/layoutHooks/StdHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function breadcrumbs(string $before): string
{
$out = '';
$showBreadcrumbs = (!$this->consultation || !$this->consultation->site || $this->consultation->site->getSettings()->showBreadcrumbs);
if (is_array($this->layout->breadcrumbs) && $showBreadcrumbs) {
if (count($this->layout->breadcrumbs) > 0 && $showBreadcrumbs) {
$out .= '<nav aria-label="' . \Yii::t('base', 'aria_breadcrumb') . '"><ol class="breadcrumb">';
foreach ($this->layout->breadcrumbs as $link => $name) {
if ($link === '' || is_numeric($link)) {
Expand Down
11 changes: 2 additions & 9 deletions models/settings/JsonConfigTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,8 @@ public function __construct(null|string|array $data)
private function propertyIsInt(\ReflectionClass $reflectionClass, string $key): bool
{
$propertyType = $reflectionClass->getProperty($key)->getType();
if (is_a($propertyType, \ReflectionNamedType::class)) {
$typeName = $propertyType->getName();
} else {
// Use the deprecated method in PHP <= 7.4
/** @var \ReflectionType $propertyType */
$typeName = trim($propertyType->__toString(), '?');
}

return $typeName === 'int';
return is_a($propertyType, \ReflectionNamedType::class) && $propertyType->getName() === 'int';
}

public static function decodeJson5(?string $json): ?array
Expand Down Expand Up @@ -81,7 +74,7 @@ protected function setPropertiesFromJSON(null|string|array $data): void
$dataArr = self::decodeJson5($data);
}
if ($dataArr === null) {
/** @var string $data */
/** @var non-falsy-string $data */
throw new ConfigurationError('Invalid JSON string: ' . $data);
}

Expand Down
1 change: 0 additions & 1 deletion plugins/ModuleBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ public static function calculateVoteResultsForApi(VotingBlock $voting, array $vo

/**
* @return class-string<VotingData>|null
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public static function getVotingDataClass(Consultation $consultation): ?string
{
Expand Down
3 changes: 0 additions & 3 deletions plugins/green_manager/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ public static function getForcedLayoutHooks(Layout $layoutSettings, ?Consultatio
];
}

/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public static function getSiteSettingsClass(Site $site): string
{
return SiteSettings::class;
Expand Down

0 comments on commit 0e70b0e

Please sign in to comment.