Skip to content

Commit

Permalink
Fix phpstan issues and update baseline files
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhwinder33445 committed Dec 4, 2023
1 parent c8771af commit ece0dc2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 47 deletions.
18 changes: 16 additions & 2 deletions application/forms/ChannelForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
use Icinga\Module\Notifications\Model\AvailableChannelType;
use Icinga\Web\Session;
use ipl\Html\Contract\FormSubmitElement;
use ipl\Html\FormElement\BaseFormElement;
use ipl\Html\FormElement\FieldsetElement;
use ipl\I18n\GettextTranslator;
use ipl\I18n\StaticTranslator;
use ipl\Sql\Connection;
use ipl\Validator\EmailAddressValidator;
Expand All @@ -33,7 +35,10 @@ public function __construct(Connection $db, ?int $channelId = null)
{
$this->db = $db;
$this->channelId = $channelId;
$this->locale = StaticTranslator::$instance->getLocale();

/** @var GettextTranslator $translateInstance */
$translateInstance = StaticTranslator::$instance;
$this->locale = $translateInstance->getLocale();
}

protected function assemble()
Expand All @@ -52,9 +57,14 @@ protected function assemble()

$query = AvailableChannelType::on($this->db)->columns(['type', 'name', 'config_attrs']);

/** @var string[] $typesConfig */
$typesConfig = [];

/** @var string[] $typeNamePair */
$typeNamePair = [];

$defaultType = null;
/** @var Channel $channel */
foreach ($query as $channel) {
if ($defaultType === null) {
$defaultType = $channel->type;
Expand All @@ -77,6 +87,7 @@ protected function assemble()
]
);

/** @var string $selectedType */
$selectedType = $this->getValue('type');
$this->createConfigElements($selectedType, $typesConfig[$selectedType]);

Expand Down Expand Up @@ -173,7 +184,9 @@ protected function onSuccess()
*/
protected function createConfigElements(string $type, string $config): void
{
/** @var array<int, stdClass> $elementsConfig */
$elementsConfig = json_decode($config, false);

if (empty($elementsConfig)) {
return;
}
Expand All @@ -182,6 +195,7 @@ protected function createConfigElements(string $type, string $config): void
$this->addElement($configFieldset);

foreach ($elementsConfig as $elementConfig) {
/** @var BaseFormElement $elem */
$elem = $this->createElement(
$this->getElementType($elementConfig),
$elementConfig->name,
Expand Down Expand Up @@ -237,7 +251,7 @@ protected function getElementType(stdClass $elementConfig): string
*
* @param stdClass $elementConfig
*
* @return array
* @return string[]
*/
protected function getElementOptions(stdClass $elementConfig): array
{
Expand Down
7 changes: 5 additions & 2 deletions library/Notifications/Model/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,16 @@ public function getIcon(): Icon
*
* @param Connection $conn
*
* @return array<int, string> All the channel names mapped as id => name
* @return string[] All the channel names mapped as id => name
*/
public static function fetchChannelNames(Connection $conn): array
{
$channels = [];
/** @var Channel $channel */
foreach (Channel::on($conn) as $channel) {
$channels[$channel->id] = $channel->name;
/** @var string $name */
$name = $channel->name;
$channels[$channel->id] = $name;
}

return $channels;
Expand Down
10 changes: 0 additions & 10 deletions phpstan-baseline-7x.neon
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
parameters:
ignoreErrors:
-
message: "#^Parameter \\#2 \\$assoc of function json_decode expects bool\\|null, int given\\.$#"
count: 1
path: application/forms/ChannelForm.php

-
message: "#^Parameter \\#2 \\.\\.\\.\\$args of function array_merge expects array, mixed given\\.$#"
count: 1
path: application/forms/ChannelForm.php

-
message: "#^Parameter \\#2 \\$str of function explode expects string, mixed given\\.$#"
count: 2
Expand Down
10 changes: 0 additions & 10 deletions phpstan-baseline-8x.neon
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
parameters:
ignoreErrors:
-
message: "#^Parameter \\#2 \\$associative of function json_decode expects bool\\|null, int given\\.$#"
count: 1
path: application/forms/ChannelForm.php

-
message: "#^Parameter \\#2 \\.\\.\\.\\$arrays of function array_merge expects array, mixed given\\.$#"
count: 1
path: application/forms/ChannelForm.php

-
message: "#^Parameter \\#2 \\$string of function explode expects string, mixed given\\.$#"
count: 2
Expand Down
26 changes: 3 additions & 23 deletions phpstan-baseline-standard.neon
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,6 @@ parameters:
count: 1
path: application/forms/BaseEscalationForm.php

-
message: "#^Call to an undefined method ipl\\\\Html\\\\Contract\\\\FormElement\\:\\:isChecked\\(\\)\\.$#"
count: 1
path: application/forms/ChannelForm.php

-
message: "#^Cannot call method getName\\(\\) on ipl\\\\Html\\\\Contract\\\\FormSubmitElement\\|null\\.$#"
count: 2
Expand Down Expand Up @@ -715,26 +710,11 @@ parameters:
count: 1
path: library/Notifications/Model/Behavior/HasAddress.php

-
message: "#^Cannot access property \\$id on mixed\\.$#"
count: 1
path: library/Notifications/Model/Channel.php

-
message: "#^Cannot access property \\$type on mixed\\.$#"
count: 2
path: library/Notifications/Model/Channel.php

-
message: "#^Method Icinga\\\\Module\\\\Notifications\\\\Model\\\\Channel\\:\\:createRelations\\(\\) has no return type specified\\.$#"
count: 1
path: library/Notifications/Model/Channel.php

-
message: "#^Method Icinga\\\\Module\\\\Notifications\\\\Model\\\\Channel\\:\\:fetchChannelTypes\\(\\) should return array\\<int, string\\> but returns array\\<int\\|string, mixed\\>\\.$#"
count: 1
path: library/Notifications/Model/Channel.php

-
message: "#^Method Icinga\\\\Module\\\\Notifications\\\\Model\\\\Channel\\:\\:getColumnDefinitions\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -1067,17 +1047,17 @@ parameters:

-
message: "#^Cannot access property \\$address on mixed\\.$#"
count: 4
count: 3
path: library/Notifications/Web/Form/ContactForm.php

-
message: "#^Cannot access property \\$id on mixed\\.$#"
count: 2
count: 1
path: library/Notifications/Web/Form/ContactForm.php

-
message: "#^Cannot access property \\$type on mixed\\.$#"
count: 4
count: 3
path: library/Notifications/Web/Form/ContactForm.php

-
Expand Down

0 comments on commit ece0dc2

Please sign in to comment.