Skip to content

Commit

Permalink
Loosen caption typehints where possible (forward compatibility with N…
Browse files Browse the repository at this point in the history
…ette Forms 3.2)
  • Loading branch information
xificurk committed Jan 9, 2024
1 parent 47256f3 commit cc9bc9f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
6 changes: 3 additions & 3 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ parameters:
count: 1
path: src/FileUploadControl/FileUploadControl.php
-
message: "#^Parameter \\#1 \\$caption \\(Nette\\\\Utils\\\\Html\\|string\\|null\\) of method Nepada\\\\FileUploadControl\\\\FileUploadControl\\:\\:getLabel\\(\\) should be contravariant with parameter \\$caption \\(object\\|string(?:\\|null)?\\) of method Nextras\\\\FormComponents\\\\Fragments\\\\UIControl\\\\BaseControl\\:\\:getLabel\\(\\)$#"
message: "#^Parameter \\#1 \\$caption \\(string\\|Stringable\\|null\\) of method Nepada\\\\FileUploadControl\\\\FileUploadControl\\:\\:getLabel\\(\\) should be contravariant with parameter \\$caption \\(object\\|string(?:\\|null)?\\) of method Nextras\\\\FormComponents\\\\Fragments\\\\UIControl\\\\BaseControl\\:\\:getLabel\\(\\)$#"
count: 1
path: src/FileUploadControl/FileUploadControl.php
-
message: "#^Parameter \\#2 \\$errorMessage \\(Nette\\\\Utils\\\\Html\\|string\\|null\\) of method Nepada\\\\FileUploadControl\\\\FileUploadControl\\:\\:addRule\\(\\) should be contravariant with parameter \\$errorMessage \\(object\\|string(?:\\|null)?\\) of method Nextras\\\\FormComponents\\\\Fragments\\\\UIControl\\\\BaseControl\\:\\:addRule\\(\\)$#"
message: "#^Parameter \\#2 \\$errorMessage \\(string\\|Stringable\\|null\\) of method Nepada\\\\FileUploadControl\\\\FileUploadControl\\:\\:addRule\\(\\) should be contravariant with parameter \\$errorMessage \\(object\\|string(?:\\|null)?\\) of method Nextras\\\\FormComponents\\\\Fragments\\\\UIControl\\\\BaseControl\\:\\:addRule\\(\\)$#"
count: 1
path: src/FileUploadControl/FileUploadControl.php
-
message: "#^Parameter \\#1 \\$value \\(bool\\|string\\|Stringable\\) of method Nepada\\\\FileUploadControl\\\\FileUploadControl\\:\\:setRequired\\(\\) should be contravariant with parameter \\$value \\(bool\\|object\\|string\\) of method Nextras\\\\FormComponents\\\\Fragments\\\\UIControl\\\\BaseControl\\:\\:setRequired\\(\\)$#"
count: 1
path: src/FileUploadControl/FileUploadControl.php
-
message: "#^Method Nepada\\\\FileUploadControl\\\\Validation\\\\FakeUploadControl\\:\\:getCaption\\(\\) should return Nette\\\\Utils\\\\Html\\|string\\|null but returns object\\|string\\.$#"
message: "#^Method Nepada\\\\FileUploadControl\\\\Validation\\\\FakeUploadControl\\:\\:getCaption\\(\\) should return string\\|Stringable\\|null but returns object\\|string\\.$#"
count: 1
path: src/FileUploadControl/Validation/FakeUploadControl.php
-
Expand Down
6 changes: 3 additions & 3 deletions src/FileUploadControl/FileUploadControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class FileUploadControl extends BaseControl

private bool $httpDataLoaded = false;

public function __construct(StorageManager $storageManager, string|Html|null $caption = null)
public function __construct(StorageManager $storageManager, string|\Stringable|null $caption = null)
{
parent::__construct($caption);
$this->storageManager = $storageManager;
Expand Down Expand Up @@ -214,7 +214,7 @@ public function getLabelPrototype(): Html

/**
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
* @param string|Html|null $caption
* @param string|\Stringable|null $caption
*/
public function getLabel($caption = null): Html
{
Expand All @@ -226,7 +226,7 @@ public function getLabel($caption = null): Html
/**
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
* @param callable|string $validator
* @param string|Html|null $errorMessage
* @param string|\Stringable|null $errorMessage
* @return $this
*/
public function addRule($validator, $errorMessage = null, mixed $arg = null): static
Expand Down
3 changes: 1 addition & 2 deletions src/FileUploadControl/Validation/FakeUploadControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Nette\Forms\Controls\UploadControl;
use Nette\Forms\Form;
use Nette\Http\FileUpload;
use Nette\Utils\Html;

/**
* @internal
Expand Down Expand Up @@ -38,7 +37,7 @@ public function getFileUploadControl(): FileUploadControl
return $this->fileUploadControl;
}

public function getCaption(): Html|string|null
public function getCaption(): \Stringable|string|null
{
return $this->fileUploadControl->getCaption();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/conditional.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
'count' => 1,
];
$config['parameters']['ignoreErrors'][] = [
'message' => '#^Return type \\(Nette\\\\Utils\\\\Html\\|string\\|null\\) of method Nepada\\\\FileUploadControl\\\\Validation\\\\FakeUploadControl\\:\\:getCaption\\(\\) should be covariant with return type \\(object\\|string\\) of method Nette\\\\Forms\\\\Controls\\\\BaseControl\\:\\:getCaption\\(\\)$#',
'message' => '#^Return type \\(string\\|Stringable\\|null\\) of method Nepada\\\\FileUploadControl\\\\Validation\\\\FakeUploadControl\\:\\:getCaption\\(\\) should be covariant with return type \\(object\\|string\\) of method Nette\\\\Forms\\\\Controls\\\\BaseControl\\:\\:getCaption\\(\\)$#',
'path' => '../../src/FileUploadControl/Validation/FakeUploadControl.php',
'count' => 1,
];
Expand Down

0 comments on commit cc9bc9f

Please sign in to comment.