forked from SimpleMachines/SMF
-
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.
Merge branch 'SimpleMachines:release-3.0' into crowdinUpate
- Loading branch information
Showing
10 changed files
with
182 additions
and
33 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 |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<?php | ||
/** | ||
* This file is modified from original CS fixer source code. | ||
* | ||
* Simple Machines Forum (SMF) | ||
* | ||
* @package SMF | ||
* @author Simple Machines https://www.simplemachines.org | ||
* @copyright 2024 Simple Machines and individual contributors | ||
* @license https://www.simplemachines.org/about/smf/license.php BSD | ||
* | ||
* @version 3.0 | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace SMF\Fixer\Whitespace; | ||
|
||
use PhpCsFixer\AbstractFixer; | ||
use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface; | ||
use PhpCsFixer\Fixer\Whitespace; | ||
use PhpCsFixer\FixerDefinition\CodeSample; | ||
use PhpCsFixer\FixerDefinition\FixerDefinition; | ||
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; | ||
use PhpCsFixer\Tokenizer\Tokens; | ||
use PhpCsFixer\Tokenizer\Token; | ||
|
||
/** | ||
* Ensure line endings match SMF standards. | ||
* | ||
* @author Jeremy Darwood <sleepy@simplemachines.org> | ||
*/ | ||
final class closing_tag_fixer extends AbstractFixer implements WhitespacesAwareFixerInterface | ||
{ | ||
public function getName(): string | ||
{ | ||
return 'SMF/closing_tag_fixer'; | ||
} | ||
|
||
public function getDefinition(): FixerDefinitionInterface | ||
{ | ||
return new FixerDefinition( | ||
'A PHP file must end with a closing tag.', | ||
[ | ||
new CodeSample("<?php\n\$a = 1;"), | ||
new CodeSample("<?php\n\$a = 1;\n?>"), | ||
new CodeSample("<?php\n\if (true){}"), | ||
new CodeSample("<?php\n\if (true){}\n\n?>"), | ||
] | ||
); | ||
} | ||
|
||
public function getPriority(): int | ||
{ | ||
return -110; | ||
} | ||
|
||
public function isCandidate(Tokens $tokens): bool | ||
{ | ||
$count = $tokens->count(); | ||
|
||
// No tokens, not a canidate. | ||
if ($count == 0) { | ||
return false; | ||
} | ||
|
||
// Last character is a white space, needs fixed. | ||
if ($tokens[$count - 1]->isGivenKind(T_WHITESPACE)) { | ||
return true; | ||
} | ||
|
||
// We have closing bracket then closing barcket, single white space and then closing tag. | ||
if ($tokens[$count - 1]->isGivenKind(T_CLOSE_TAG) && $tokens[$count - 2]->isGivenKind(T_WHITESPACE) && $tokens[$count - 3]->getContent() !== ';') { | ||
return true; | ||
} | ||
|
||
// We have a closing bracket, and then closing tag, no white space. | ||
if ($tokens[$count - 1]->isGivenKind(T_CLOSE_TAG) && $tokens[$count - 2]->getContent() === '}') { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
protected function applyFix(\SplFileInfo $file, Tokens $tokens): void | ||
{ | ||
$count = $tokens->count(); | ||
|
||
// Last character is a white space. Adds a closing tag. | ||
if ($count > 0 && $tokens[$count - 1]->isGivenKind(T_WHITESPACE)) { | ||
$tokens[$count - 1] = new Token([ | ||
T_WHITESPACE, | ||
$this->whitespacesConfig->getLineEnding() . $this->whitespacesConfig->getLineEnding() . '?' . '>' | ||
]); | ||
} | ||
|
||
// We have closing bracket then closing barcket, single white space and then closing tag. Add one more return. | ||
if ($count > 0 && $tokens[$count - 1]->isGivenKind(T_CLOSE_TAG) && $tokens[$count - 2]->isGivenKind(T_WHITESPACE) && $tokens[$count - 3]->getContent() !== ';') { | ||
$tokens[$count - 2] = new Token([ | ||
T_WHITESPACE, | ||
$this->whitespacesConfig->getLineEnding() . $this->whitespacesConfig->getLineEnding() | ||
]); | ||
} | ||
|
||
// We have a closing bracket, and then closing tag, no white space, add returns. | ||
// There is no ID/Name for closing curely bracket or semi-colon. | ||
if ($count > 0 && $tokens[$count - 1]->isGivenKind(T_CLOSE_TAG) && $tokens[$count - 2]->getContent() === '}') { | ||
|
||
$tokens[$count - 1] = new Token([ | ||
T_WHITESPACE, | ||
$this->whitespacesConfig->getLineEnding() . $this->whitespacesConfig->getLineEnding() . '?' . '>' | ||
]); | ||
} | ||
} | ||
} |
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,31 @@ | ||
on: | ||
push: | ||
branches: | ||
- release-2.1 | ||
pull_request: | ||
|
||
name: PHP Check | ||
jobs: | ||
php-cs-fixer: | ||
name: PHP-CS-Fixer | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Get changed files | ||
id: changed-files | ||
uses: tj-actions/changed-files@v42 | ||
|
||
- name: Get extra arguments for PHP-CS-Fixer | ||
id: phpcs-intersection | ||
run: | | ||
CHANGED_FILES=$(echo "${{ steps.changed-files.outputs.all_changed_and_modified_files }}" | tr ' ' '\n') | ||
if ! echo "${CHANGED_FILES}" | grep -qE "^(\\.php-cs-fixer(\\.dist)?\\.php|composer\\.lock)$"; then EXTRA_ARGS=$(printf -- '--path-mode=intersection\n--\n%s' "${CHANGED_FILES}"); else EXTRA_ARGS=''; fi | ||
echo "PHPCS_EXTRA_ARGS<<EOF" >> $GITHUB_ENV | ||
echo "$EXTRA_ARGS" >> $GITHUB_ENV | ||
echo "EOF" >> $GITHUB_ENV | ||
- name: PHP-CS-Fixer | ||
uses: docker://oskarstark/php-cs-fixer-ga | ||
with: | ||
args: --config=.php-cs-fixer.dist.php -v --dry-run --stop-on-violation --using-cache=no ${{ env.PHPCS_EXTRA_ARGS }}" |
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
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