-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add var rule and refacto rules (#172)
- Loading branch information
1 parent
76deacb
commit b850eca
Showing
33 changed files
with
340 additions
and
84 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
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
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,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TwigCsFixer\Rules; | ||
|
||
use TwigCsFixer\Report\Report; | ||
use TwigCsFixer\Runner\FixerInterface; | ||
use TwigCsFixer\Token\Token; | ||
|
||
abstract class AbstractFixableRule extends AbstractRule implements FixableRuleInterface | ||
{ | ||
private ?FixerInterface $fixer = null; | ||
|
||
protected function init( | ||
?Report $report, | ||
array $ignoredViolations = [], | ||
?FixerInterface $fixer = null | ||
): void { | ||
parent::init($report, $ignoredViolations); | ||
$this->fixer = $fixer; | ||
} | ||
|
||
public function fixFile(array $stream, FixerInterface $fixer, array $ignoredViolations = []): void | ||
{ | ||
$this->init(null, $ignoredViolations, $fixer); | ||
|
||
foreach (array_keys($stream) as $index) { | ||
$this->process($index, $stream); | ||
} | ||
} | ||
|
||
protected function addFixableWarning( | ||
string $message, | ||
Token $token, | ||
?string $messageId = null | ||
): ?FixerInterface { | ||
$added = $this->addWarning($message, $token, $messageId); | ||
if (!$added) { | ||
return null; | ||
} | ||
|
||
return $this->fixer; | ||
} | ||
|
||
protected function addFixableError( | ||
string $message, | ||
Token $token, | ||
?string $messageId = null | ||
): ?FixerInterface { | ||
$added = $this->addError($message, $token, $messageId); | ||
if (!$added) { | ||
return null; | ||
} | ||
|
||
return $this->fixer; | ||
} | ||
} |
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
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,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TwigCsFixer\Rules; | ||
|
||
use TwigCsFixer\Report\ViolationId; | ||
use TwigCsFixer\Runner\FixerInterface; | ||
use TwigCsFixer\Token\Token; | ||
|
||
interface FixableRuleInterface | ||
{ | ||
/** | ||
* @param array<int, Token> $stream | ||
* @param list<ViolationId> $ignoredViolations | ||
*/ | ||
public function fixFile(array $stream, FixerInterface $fixer, array $ignoredViolations = []): void; | ||
} |
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
Oops, something went wrong.