Skip to content

Commit

Permalink
fixes per review
Browse files Browse the repository at this point in the history
  • Loading branch information
clxmstaab authored and staabm committed Sep 8, 2022
1 parent ba9b91d commit ec536c1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
3 changes: 3 additions & 0 deletions conf/bleedingEdge.neon
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ parameters:
phpDocParserRequireWhitespaceBeforeDescription: true
runtimeReflectionRules: true
notAnalysedTrait: true

rules:
- PHPStan\Rules\Methods\MissingMagicSerializationMethodsRule
1 change: 0 additions & 1 deletion conf/config.level0.neon
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ rules:
- PHPStan\Rules\Methods\ExistingClassesInTypehintsRule
- PHPStan\Rules\Methods\FinalPrivateMethodRule
- PHPStan\Rules\Methods\MethodCallableRule
- PHPStan\Rules\Methods\MissingMagicSerializationMethodsRule
- PHPStan\Rules\Methods\MissingMethodImplementationRule
- PHPStan\Rules\Methods\MethodAttributesRule
- PHPStan\Rules\Methods\StaticMethodCallableRule
Expand Down
9 changes: 5 additions & 4 deletions src/Rules/Methods/MissingMagicSerializationMethodsRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use PHPStan\Rules\RuleErrorBuilder;
use Serializable;
use function sprintf;
use function strtolower;

/**
* @implements Rule<InClassNode>
Expand Down Expand Up @@ -51,10 +52,10 @@ public function processNode(Node $node, Scope $scope): array
$missingMagicSerialize = true;
$missingMagicUnserialize = true;
foreach ($nativeMethods as $method) {
if ($method->getName() === '__serialize') {
if (strtolower($method->getName()) === '__serialize') {
$missingMagicSerialize = false;
}
if ($method->getName() !== '__unserialize') {
if (strtolower($method->getName()) !== '__unserialize') {
continue;
}

Expand All @@ -65,13 +66,13 @@ public function processNode(Node $node, Scope $scope): array
$messages[] = RuleErrorBuilder::message(sprintf(
'Non-abstract class %s implements the Serializable interface, but does not implement __serialize().',
$classReflection->getDisplayName(),
))->build();
))->tip('See https://wiki.php.net/rfc/phase_out_serializable')->build();
}
if ($missingMagicUnserialize) {
$messages[] = RuleErrorBuilder::message(sprintf(
'Non-abstract class %s implements the Serializable interface, but does not implement __unserialize().',
$classReflection->getDisplayName(),
))->build();
))->tip('See https://wiki.php.net/rfc/phase_out_serializable')->build();
}

return $messages;
Expand Down
11 changes: 11 additions & 0 deletions tests/PHPStan/Rules/Methods/data/missing-serialization.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,14 @@ public function serialize() {
public function unserialize($data) {
}
}

abstract class allGood implements Serializable {
public function serialize() {
}
public function unserialize($data) {
}
public function __serialize() {
}
public function __unserialize($data) {
}
}

0 comments on commit ec536c1

Please sign in to comment.