From 83397249b0dfe96830e7014ef792114c3d463f3c Mon Sep 17 00:00:00 2001 From: Jake Hotson Date: Wed, 12 Mar 2025 01:30:12 +0000 Subject: [PATCH] [TASK] Initialize `KeyFrame` properties They fortunately have obvious default values. This change means it can be enforced that they are always non-empty strings. Type declarations have been updated to reflect that. --- CHANGELOG.md | 1 + config/phpstan-baseline.neon | 6 ------ src/CSSList/KeyFrame.php | 32 ++++++++++++++--------------- tests/Unit/CSSList/KeyFrameTest.php | 20 ++++++++++++++++++ 4 files changed, 37 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 36ef5ffc3..d3a0338ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ Please also have a look at our ### Changed +- Initialize `KeyFrame` properties to sensible defaults (#1146) - Make `OutputFormat` `final` (#1128) - Mark the `OutputFormat` constructor as `@internal` (#1131) - Mark `OutputFormatter` as `@internal` (#896) diff --git a/config/phpstan-baseline.neon b/config/phpstan-baseline.neon index 7ae723e9a..6c0a6d88c 100644 --- a/config/phpstan-baseline.neon +++ b/config/phpstan-baseline.neon @@ -96,12 +96,6 @@ parameters: count: 1 path: ../src/CSSList/KeyFrame.php - - - message: '#^Parameters should have "string" types as the only types passed to this method$#' - identifier: typePerfect.narrowPublicClassMethodParamType - count: 2 - path: ../src/CSSList/KeyFrame.php - - message: '#^Loose comparison via "\=\=" is not allowed\.$#' identifier: equal.notAllowed diff --git a/src/CSSList/KeyFrame.php b/src/CSSList/KeyFrame.php index 3177ac19c..40e0823dc 100644 --- a/src/CSSList/KeyFrame.php +++ b/src/CSSList/KeyFrame.php @@ -10,43 +10,43 @@ class KeyFrame extends CSSList implements AtRule { /** - * @var string|null + * @var non-empty-string */ - private $vendorKeyFrame; + private $vendorKeyFrame = 'keyframes'; /** - * @var string|null + * @var non-empty-string */ - private $animationName; + private $animationName = 'none'; /** - * @param string $vendorKeyFrame + * @param non-empty-string $vendorKeyFrame */ - public function setVendorKeyFrame($vendorKeyFrame): void + public function setVendorKeyFrame(string $vendorKeyFrame): void { $this->vendorKeyFrame = $vendorKeyFrame; } /** - * @return string|null + * @return non-empty-string */ - public function getVendorKeyFrame() + public function getVendorKeyFrame(): string { return $this->vendorKeyFrame; } /** - * @param string $animationName + * @param non-empty-string $animationName */ - public function setAnimationName($animationName): void + public function setAnimationName(string $animationName): void { $this->animationName = $animationName; } /** - * @return string|null + * @return non-empty-string */ - public function getAnimationName() + public function getAnimationName(): string { return $this->animationName; } @@ -74,17 +74,17 @@ public function isRootList(): bool } /** - * @return string|null + * @return non-empty-string */ - public function atRuleName() + public function atRuleName(): string { return $this->vendorKeyFrame; } /** - * @return string|null + * @return non-empty-string */ - public function atRuleArgs() + public function atRuleArgs(): string { return $this->animationName; } diff --git a/tests/Unit/CSSList/KeyFrameTest.php b/tests/Unit/CSSList/KeyFrameTest.php index 552dcada1..20be302c6 100644 --- a/tests/Unit/CSSList/KeyFrameTest.php +++ b/tests/Unit/CSSList/KeyFrameTest.php @@ -68,4 +68,24 @@ public function getLineNoReturnsLineNumberProvidedToConstructor(): void self::assertSame($lineNumber, $subject->getLineNo()); } + + /** + * @test + */ + public function getAnimationNameByDefaultReturnsNone(): void + { + $subject = new KeyFrame(); + + self::assertSame('none', $subject->getAnimationName()); + } + + /** + * @test + */ + public function getVendorKeyFrameByDefaultReturnsKeyframes(): void + { + $subject = new KeyFrame(); + + self::assertSame('keyframes', $subject->getVendorKeyFrame()); + } }