Skip to content

Commit

Permalink
Allow d in short names (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba authored May 19, 2024
1 parent 9e216d5 commit ab11663
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/ObjectCalisthenics/Rules/NoShortNameRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ final class NoShortNameRule extends AbstractSymplifyRule implements Configurable
*/
public function __construct(
private readonly int $minNameLength,
private readonly array $allowedShortNames = ['i', 'j', 'y', 'z']
private readonly array $allowedShortNames = ['i', 'j', 'y', 'z', 'd', 'dd']
) {
}

Expand Down Expand Up @@ -130,6 +130,9 @@ private function isNameValid(string $name): bool
return true;
}

dump($name);
dump(in_array($name, $this->allowedShortNames, true));

return in_array($name, $this->allowedShortNames, true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

declare(strict_types=1);

function d()
{
// handle dump
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ public static function provideData(): Iterator
yield [__DIR__ . '/Fixture/SkipId.php', []];

$errorMessage = sprintf(NoShortNameRule::ERROR_MESSAGE, 'em', 3);
$yeErrorMEssage = sprintf(NoShortNameRule::ERROR_MESSAGE, 'YE', 3);
yield [__DIR__ . '/Fixture/ShortNamingClass.php', [[$errorMessage, 9], [$yeErrorMEssage, 11]]];
$yeErrorMessage = sprintf(NoShortNameRule::ERROR_MESSAGE, 'YE', 3);
yield [__DIR__ . '/Fixture/ShortNamingClass.php', [[$errorMessage, 9], [$yeErrorMessage, 11]]];

$errorMessage = sprintf(NoShortNameRule::ERROR_MESSAGE, 'n', 3);
yield [__DIR__ . '/Fixture/ShortClosureParam.php', [[$errorMessage, 11]]];
yield [__DIR__ . '/Fixture/ShortParam.php', [[$errorMessage, 9]]];

yield [__DIR__ . '/Fixture/AllowD.php', []];

$errorMessage = sprintf(NoShortNameRule::ERROR_MESSAGE, 'n', 3);
yield [
__DIR__ . '/Fixture/ShortAssignParameter.php',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ services:
minNameLength: 3
allowedShortNames:
- id
- d

0 comments on commit ab11663

Please sign in to comment.