Skip to content

Commit

Permalink
Use generics for Control typehint
Browse files Browse the repository at this point in the history
  • Loading branch information
xificurk committed Jan 8, 2024
1 parent 60637ef commit a89dad1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ parameters:
message: "#^Parameter \\#2 \\$size of class Nepada\\\\FileUploadControl\\\\Storage\\\\Metadata\\\\FileUploadMetadata constructor expects int, mixed given\\.$#"
count: 1
path: src/FileUploadControl/Storage/Metadata/FileUploadMetadata.php
-
message: "#^Parameter \\#1 \\$control \\(Nette\\\\Forms\\\\Control\\<mixed\\>\\) of method Nepada\\\\FileUploadControl\\\\FileUploadControl\\:\\:addConditionOn\\(\\) should be contravariant with parameter \\$control \\(Nette\\\\Forms\\\\IControl\\) of method Nextras\\\\FormComponents\\\\Fragments\\\\UIControl\\\\BaseControl\\:\\:addConditionOn\\(\\)$#"
count: 1
path: src/FileUploadControl/FileUploadControl.php
- # Used for checksum only
message: "#^Calling sha1\\(\\) is forbidden, use hash\\(\\) with at least SHA\\-256 for secure hash, or password_hash\\(\\) for passwords$#"
count: 1
Expand Down
1 change: 1 addition & 0 deletions src/FileUploadControl/Validation/UploadValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function addCondition($validator, mixed $value = null): Rules

/**
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
* @param Control<mixed> $control
* @param callable|string $validator
*/
public function addConditionOn(Control $control, $validator, mixed $value = null): Rules
Expand Down
7 changes: 7 additions & 0 deletions tests/PHPStan/conditional.config.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
declare(strict_types = 1);

use Composer\InstalledVersions;
use Composer\Semver\VersionParser;

$config = [];
Expand All @@ -22,4 +23,10 @@
];
}

if (InstalledVersions::satisfies(new VersionParser(), 'nette/forms', '<3.2')) {
$config['parameters']['ignoreErrors'][] = [
'message' => '~contains generic type Nette\\\\Forms\\\\Control<mixed> but interface Nette\\\\Forms\\\\Control is not generic~',
];
}

return $config;

0 comments on commit a89dad1

Please sign in to comment.