-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e7d822f
commit f858620
Showing
12 changed files
with
462 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/.composer | ||
/.idea | ||
/playground | ||
/vendor | ||
|
||
composer.lock | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Blumilk\Codestyle\Fixers; | ||
|
||
use PhpCsFixer\Fixer\FixerInterface; | ||
use PhpCsFixer\Fixer\Whitespace\NoExtraBlankLinesFixer; | ||
use PhpCsFixer\FixerDefinition\CodeSample; | ||
use PhpCsFixer\FixerDefinition\FixerDefinition; | ||
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; | ||
use PhpCsFixer\Tokenizer\Tokens; | ||
use PhpCsFixerCustomFixers\TokenRemover; | ||
use SplFileInfo; | ||
|
||
final class NoCommentFixer implements FixerInterface | ||
{ | ||
public function getDefinition(): FixerDefinitionInterface | ||
{ | ||
$codeSample = <<<'EOF' | ||
<?php | ||
class Migration | ||
{ | ||
public function up() | ||
{ | ||
Schema::create("sessions", function (Blueprint $table) { | ||
// test | ||
$table->string("id")->primary(); | ||
$table->text("payload"); | ||
}); | ||
} | ||
}; | ||
EOF; | ||
|
||
return new FixerDefinition( | ||
"There can be no comments.", | ||
[ | ||
new CodeSample($codeSample), | ||
], | ||
); | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return "Blumilk/no_comments"; | ||
} | ||
|
||
public function getPriority(): int | ||
{ | ||
$fixer = new NoExtraBlankLinesFixer(); | ||
return $fixer->getPriority() + 1; | ||
} | ||
|
||
public function supports(SplFileInfo $file): bool | ||
{ | ||
return true; | ||
} | ||
|
||
public function isCandidate(Tokens $tokens): bool | ||
{ | ||
return $tokens->isAnyTokenKindsFound([T_COMMENT, T_DOC_COMMENT]); | ||
} | ||
|
||
public function isRisky(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
public function fix(SplFileInfo $file, Tokens $tokens): void | ||
{ | ||
for ($index = $tokens->count() - 1; $index > 0; $index--) { | ||
if (!$tokens[$index]->isGivenKind([T_COMMENT])) { | ||
continue; | ||
} | ||
|
||
TokenRemover::removeWithLinesIfPossible($tokens, $index); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
namespace Blumilk\Codestyle\Tests; | ||
|
||
class CommonRulesetTest extends CodestyleTestCase | ||
{ | ||
/** | ||
* @dataProvider providePhp80Fixtures | ||
* @requires PHP >= 8.0 | ||
* @throws Exception | ||
*/ | ||
public function testPhp80Fixtures(string $name): void | ||
{ | ||
$this->testFixture($name); | ||
} | ||
|
||
/** | ||
* @dataProvider providePhp81Fixtures | ||
* @requires PHP >= 8.1 | ||
* @throws Exception | ||
*/ | ||
public function testPhp81Fixtures(string $name): void | ||
{ | ||
$this->testFixture($name); | ||
} | ||
|
||
/** | ||
* @dataProvider providePhp82Fixtures | ||
* @requires PHP >= 8.2 | ||
* @throws Exception | ||
*/ | ||
public function testPhp82Fixtures(string $name): void | ||
{ | ||
$this->testFixture($name); | ||
} | ||
|
||
public static function providePhp80Fixtures(): array | ||
{ | ||
return [ | ||
["noExtraBlankLines"], | ||
["nullableTypeForDefaultNull"], | ||
["operatorSpacing"], | ||
["singleQuotes"], | ||
["strictTypes"], | ||
["trailingCommas"], | ||
["unionTypes"], | ||
["references"], | ||
["classAttributesSeparation"], | ||
["uselessParenthesis"], | ||
["laravelMigrations"], | ||
["phpdocs"], | ||
["yodaStyle"], | ||
["objectOperators"], | ||
["anonymousFunctions"], | ||
["namespaces"], | ||
["emptyLines"], | ||
["importsOrder"], | ||
]; | ||
} | ||
|
||
public static function providePhp81Fixtures(): array | ||
{ | ||
return [ | ||
["enums"], | ||
["readonlies"], | ||
]; | ||
} | ||
|
||
public static function providePhp82Fixtures(): array | ||
{ | ||
return [ | ||
["php82"], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Blumilk\Codestyle\Tests; | ||
class PurgeTest extends CodestyleTestCase | ||
{ | ||
/** | ||
* @throws Exception | ||
*/ | ||
public function testPhp82Fixtures(): void | ||
{ | ||
$this->testFixture("noComments"); | ||
} | ||
|
||
protected function getConfigPath(): string | ||
{ | ||
return "./tests/codestyle/config/config.purge.php"; | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Blumilk\Codestyle\Config; | ||
use Blumilk\Codestyle\Configuration\Defaults\Paths; | ||
|
||
$config = new Config( | ||
paths: new Paths("tests/codestyle/tmp"), | ||
); | ||
|
||
return $config->purgeMode()->config(); |
Oops, something went wrong.