Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Rules/Constants/ValueAssignedToClassConstantRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private function processSingleConstant(ClassReflection $classReflection, string
'Configuration defined type for constant %s::%s (%s) does not accept value %s.',
$constantReflection->getDeclaringClass()->getDisplayName(),
$constantName,
$configuredType->describe(VerbosityLevel::typeOnly()),
$configuredType->describe(VerbosityLevel::value()),
$valueExprType->describe($verbosity),
))->acceptsReasonsTip($accepts->reasons)->identifier('classConstant.value')->build(),
];
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Constants/ValueAssignedToDefineRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function processNode(Node $node, Scope $scope): array
$errors[] = RuleErrorBuilder::message(sprintf(
'Configuration defined type for constant %s (%s) does not accept value %s.',
$constantName,
$configuredType->describe(VerbosityLevel::typeOnly()),
$configuredType->describe(VerbosityLevel::value()),
$valueType->describe($verbosity),
))->acceptsReasonsTip($accepts->reasons)->identifier('constant.defineValue')->build();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Constants/ValueAssignedToGlobalConstantRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function processNode(Node $node, Scope $scope): array
$errors[] = RuleErrorBuilder::message(sprintf(
'Configuration defined type for constant %s (%s) does not accept value %s.',
$constantName,
$configuredType->describe(VerbosityLevel::typeOnly()),
$configuredType->describe(VerbosityLevel::value()),
$valueType->describe($verbosity),
))->acceptsReasonsTip($accepts->reasons)->identifier('constant.value')->build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public function testRule(): void
'Configuration defined type for constant ValueAssignedToClassConstantDynamicNames\Foo::MAYBE_BAR (int<1, max>) does not accept value int.',
14,
],
[
"Configuration defined type for constant ValueAssignedToClassConstantDynamicNames\Foo::A_NON_EMPTY_STRING (non-empty-string) does not accept value ''.",
15,
],
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ public function testRule(): void
'Configuration defined type for constant BAR_CONSTANT (int|string|null) does not accept value int|false.',
6,
],
[
"Configuration defined type for constant A_NON_EMPTY_STRING (non-empty-string) does not accept value ''.",
12,
],
[
'Configuration defined type for constant A_NON_EMPTY_STRING (non-empty-string) does not accept value string.',
14,
],
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public function testRule(): void
'Configuration defined type for constant MAYBE_CONSTANT (int<1, max>) does not accept value int.',
5,
],
[
"Configuration defined type for constant A_NON_EMPTY_STRING (non-empty-string) does not accept value ''.",
6,
],
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ class Foo
const BAR = false; // error - configured as int|string|null
const BAR2 = 1; // fine - not in dynamicConstantNames
const MAYBE_BAR = Bar::DYNAMIC; // error (maybe) - positive-int doesn't fully accept int
const A_NON_EMPTY_STRING = '';
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@
define('BAR_CONSTANT', null); // fine
define('BAR_CONSTANT', rand(0,1) ? 1 : 'hello'); // fine
define('OTHER_CONSTANT', false); // fine - not in dynamicConstantNames
define('A_NON_EMPTY_STRING', '');
define('A_NON_EMPTY_STRING', '0');
define('A_NON_EMPTY_STRING', getString());

function getString(): string {}
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
const BAR_CONSTANT = false; // error
const OTHER_CONSTANT = false; // fine - not in dynamicConstantNames
const MAYBE_CONSTANT = DYNAMIC_INT_CONSTANT; // error (maybe) - positive-int doesn't fully accept int
const A_NON_EMPTY_STRING = '';
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ parameters:
BAR_CONSTANT: 'int|string|null'
DYNAMIC_INT_CONSTANT: 'int'
MAYBE_CONSTANT: 'positive-int'
A_NON_EMPTY_STRING: 'non-empty-string'
ValueAssignedToClassConstantDynamicNames\Foo::BAR: 'int|string|null'
ValueAssignedToClassConstantDynamicNames\Bar::DYNAMIC: 'int'
ValueAssignedToClassConstantDynamicNames\Foo::MAYBE_BAR: 'positive-int'
ValueAssignedToClassConstantDynamicNames\Foo::A_NON_EMPTY_STRING: 'non-empty-string'
Loading