Skip to content

Commit

Permalink
Add narrow_return config (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik authored Jun 17, 2024
1 parent 06a5fb5 commit 476f8ee
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
4 changes: 4 additions & 0 deletions config/extension.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ parametersSchema:
# see https://doc.nette.org/en/schema for configuration
type_perfect: structure([
narrow_param: bool()
narrow_return: bool()
no_mixed: bool()
null_over_false: bool()
])
Expand All @@ -10,6 +11,7 @@ parametersSchema:
parameters:
type_perfect:
narrow_param: false
narrow_return: false
no_mixed: false
null_over_false: false

Expand All @@ -25,6 +27,8 @@ rules:
# narrow_param
- Rector\TypePerfect\Rules\NarrowPublicClassMethodParamTypeRule
- Rector\TypePerfect\Rules\NarrowPrivateClassMethodParamTypeRule

# narrow_return
- Rector\TypePerfect\Rules\NarrowReturnObjectTypeRule

# no_mixed
Expand Down
8 changes: 7 additions & 1 deletion src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,22 @@ public function __construct(
// enabed by default in tests
if (defined('PHPUNIT_COMPOSER_INSTALL')) {
$this->parameters['narrow_param'] = true;
$this->parameters['narrow_return'] = true;
$this->parameters['no_mixed'] = true;
$this->parameters['null_over_false'] = true;
}
}

public function isNarrowEnabled(): bool
public function isNarrowParamEnabled(): bool
{
return $this->parameters['narrow_param'] ?? false;
}

public function isNarrowReturnEnabled(): bool
{
return $this->parameters['narrow_return'] ?? false;
}

public function isNoMixedEnabled(): bool
{
return $this->parameters['no_mixed'] ?? false;
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/NarrowPrivateClassMethodParamTypeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function getNodeType(): string
*/
public function processNode(Node $node, Scope $scope): array
{
if (! $this->configuration->isNarrowEnabled() || $node->isFirstClassCallable()) {
if (! $this->configuration->isNarrowParamEnabled() || $node->isFirstClassCallable()) {
return [];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/NarrowPublicClassMethodParamTypeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function getNodeType(): string
*/
public function processNode(Node $node, Scope $scope): array
{
if (! $this->configuration->isNarrowEnabled()) {
if (! $this->configuration->isNarrowParamEnabled()) {
return [];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/NarrowReturnObjectTypeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function getNodeType(): string
*/
public function processNode(Node $node, Scope $scope): array
{
if (! $this->configuration->isNarrowEnabled()) {
if (! $this->configuration->isNarrowReturnEnabled()) {
return [];
}

Expand Down

0 comments on commit 476f8ee

Please sign in to comment.