Skip to content

Commit eb6f887

Browse files
committed
Add error tips for better developer experience
1 parent fdb1523 commit eb6f887

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

src/Rules/Classes/CacheHandlerInstantiationRule.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,14 @@ public function processNode(Node $node, Scope $scope): array
5555
return [];
5656
}
5757

58-
return [RuleErrorBuilder::message(sprintf(
59-
'Calling new %s() directly is not allowed. Use CacheFactory::getHandler() to get the cache instance.',
60-
$reflection->getNativeReflection()->getShortName(),
61-
))->identifier('codeigniter.cacheHandlerInstance')->build()];
58+
return [
59+
RuleErrorBuilder::message(sprintf(
60+
'Calling new %s() directly is incomplete to get the cache instance.',
61+
$reflection->getNativeReflection()->getShortName(),
62+
))
63+
->tip('Use CacheFactory::getHandler() or the cache() function to get the cache instance instead.')
64+
->identifier('codeigniter.cacheHandlerInstance')
65+
->build(),
66+
];
6267
}
6368
}

src/Rules/Functions/FactoriesFunctionArgumentTypeRule.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ public function processNode(Node $node, Scope $scope): array
8989
$firstParameter->getName(),
9090
$function,
9191
$nameType->describe(VerbosityLevel::precise())
92+
))->tip(sprintf(
93+
'If %s is a valid class string, you can add its possible namespace(s) in <fg=cyan>codeigniter.additional%sNamespaces</> in your <fg=yellow>%%configurationFile%%</>.',
94+
$nameType->describe(VerbosityLevel::precise()),
95+
ucfirst($function)
9296
))->identifier(sprintf('codeigniter.%sArgumentType', $function))->build()];
9397
}
9498

tests/Rules/Classes/CacheHandlerInstantiationRuleTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ public function testRule(): void
3838
{
3939
$this->analyse([__DIR__ . '/../../Fixtures/Rules/Classes/cache-handler.php'], [
4040
[
41-
'Calling new FileHandler() directly is not allowed. Use CacheFactory::getHandler() to get the cache instance.',
41+
'Calling new FileHandler() directly is incomplete to get the cache instance.',
4242
18,
43+
'Use CacheFactory::getHandler() or the cache() function to get the cache instance instead.',
4344
],
4445
[
45-
'Calling new RedisHandler() directly is not allowed. Use CacheFactory::getHandler() to get the cache instance.',
46+
'Calling new RedisHandler() directly is incomplete to get the cache instance.',
4647
19,
48+
'Use CacheFactory::getHandler() or the cache() function to get the cache instance instead.',
4749
],
4850
]);
4951
}

tests/Rules/Functions/FactoriesFunctionArgumentTypeRuleTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@ public function testRule(): void
4747
[
4848
'Parameter #1 $name of function config expects a valid class string, \'bar\' given.',
4949
23,
50+
'If \'bar\' is a valid class string, you can add its possible namespace(s) in <fg=cyan>codeigniter.additionalConfigNamespaces</> in your <fg=yellow>%configurationFile%</>.',
5051
],
5152
[
5253
'Parameter #1 $name of function config expects a valid class string, \'Foo\\\\Bar\' given.',
5354
24,
55+
'If \'Foo\\\\Bar\' is a valid class string, you can add its possible namespace(s) in <fg=cyan>codeigniter.additionalConfigNamespaces</> in your <fg=yellow>%configurationFile%</>.',
5456
],
5557
[
5658
'Argument #1 $name (\'Foo\'|\'stdClass\') passed to function config does not extend CodeIgniter\\\\Config\\\\BaseConfig.',
@@ -63,6 +65,7 @@ public function testRule(): void
6365
[
6466
'Parameter #1 $name of function model expects a valid class string, \'foo\' given.',
6567
18,
68+
'If \'foo\' is a valid class string, you can add its possible namespace(s) in <fg=cyan>codeigniter.additionalModelNamespaces</> in your <fg=yellow>%configurationFile%</>.',
6669
],
6770
[
6871
'Argument #1 $name (\'stdClass\') passed to function model does not extend CodeIgniter\\\\Model.',
@@ -75,6 +78,7 @@ public function testRule(): void
7578
[
7679
'Parameter #1 $name of function model expects a valid class string, \'App\' given.',
7780
21,
81+
'If \'App\' is a valid class string, you can add its possible namespace(s) in <fg=cyan>codeigniter.additionalModelNamespaces</> in your <fg=yellow>%configurationFile%</>.',
7882
],
7983
[
8084
'Argument #1 $name (\'Foo\'|\'stdClass\') passed to function model does not extend CodeIgniter\\\\Model.',

0 commit comments

Comments
 (0)