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 <[email protected]> | ||
*/ | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -322,22 +322,22 @@ public function execute(): void | |
// Give credit to any graphic library's, software library's, plugins etc | ||
Utils::$context['credits_software_graphics'] = [ | ||
'graphics' => [ | ||
'<a href="http://p.yusukekamiyamane.com/">Fugue Icons</a> | © 2012 Yusuke Kamiyamane | These icons are licensed under a Creative Commons Attribution 3.0 License', | ||
'<a href="https://techbase.kde.org/Projects/Oxygen/Licensing#Use_on_Websites">Oxygen Icons</a> | These icons are licensed under <a href="http://www.gnu.org/copyleft/lesser.html">GNU LGPLv3</a>', | ||
'<a href="https://p.yusukekamiyamane.com/">Fugue Icons</a> | © 2012 Yusuke Kamiyamane | These icons are licensed under a Creative Commons Attribution 3.0 License', | ||
'<a href="https://techbase.kde.org/Projects/Oxygen/Licensing#Use_on_Websites">Oxygen Icons</a> | These icons are licensed under <a href="https://www.gnu.org/licenses/lgpl-3.0.html">GNU LGPLv3</a>', | ||
], | ||
'software' => [ | ||
'<a href="https://jquery.org/">JQuery</a> | © John Resig | Licensed under <a href="https://github.com/jquery/jquery/blob/master/LICENSE.txt">The MIT License (MIT)</a>', | ||
'<a href="https://briancherne.github.io/jquery-hoverIntent/">hoverIntent</a> | © Brian Cherne | Licensed under <a href="https://en.wikipedia.org/wiki/MIT_License">The MIT License (MIT)</a>', | ||
'<a href="https://www.sceditor.com/">SCEditor</a> | © Sam Clarke | Licensed under <a href="https://en.wikipedia.org/wiki/MIT_License">The MIT License (MIT)</a>', | ||
'<a href="http://wayfarerweb.com/jquery/plugins/animadrag/">animaDrag</a> | © Abel Mohler | Licensed under <a href="https://en.wikipedia.org/wiki/MIT_License">The MIT License (MIT)</a>', | ||
'<a href="https://github.com/mzubala/jquery-custom-scrollbar">jQuery Custom Scrollbar</a> | © Maciej Zubala | Licensed under <a href="http://en.wikipedia.org/wiki/MIT_License">The MIT License (MIT)</a>', | ||
'<a href="http://slippry.com/">jQuery Responsive Slider</a> | © booncon ROCKETS | Licensed under <a href="http://en.wikipedia.org/wiki/MIT_License">The MIT License (MIT)</a>', | ||
'<a href="https://github.com/code-of-kpp/jquery-animadrag/blob/master/animadrag.js">animaDrag</a> | © Abel Mohler | Licensed under <a href="https://en.wikipedia.org/wiki/MIT_License">The MIT License (MIT)</a>', | ||
'<a href="https://github.com/mzubala/jquery-custom-scrollbar">jQuery Custom Scrollbar</a> | © Maciej Zubala | Licensed under <a href="https://en.wikipedia.org/wiki/MIT_License">The MIT License (MIT)</a>', | ||
'<a href="https://slippry.com/">jQuery Responsive Slider</a> | © booncon ROCKETS | Licensed under <a href="https://en.wikipedia.org/wiki/MIT_License">The MIT License (MIT)</a>', | ||
'<a href="https://github.com/ichord/At.js">At.js</a> | © [email protected] | Licensed under <a href="https://github.com/ichord/At.js/blob/master/LICENSE-MIT">The MIT License (MIT)</a>', | ||
'<a href="https://github.com/ttsvetko/HTML5-Desktop-Notifications">HTML5 Desktop Notifications</a> | © Tsvetan Tsvetkov | Licensed under <a href="https://github.com/ttsvetko/HTML5-Desktop-Notifications/blob/master/License.txt">The Apache License Version 2.0</a>', | ||
'<a href="https://github.com/enygma/gauth">GAuth Code Generator/Validator</a> | © Chris Cornutt | Licensed under <a href="https://github.com/enygma/gauth/blob/master/LICENSE">The MIT License (MIT)</a>', | ||
'<a href="https://github.com/enyo/dropzone">Dropzone.js</a> | © Matias Meno | Licensed under <a href="http://en.wikipedia.org/wiki/MIT_License">The MIT License (MIT)</a>', | ||
'<a href="https://github.com/matthiasmullie/minify">Minify</a> | © Matthias Mullie | Licensed under <a href="http://en.wikipedia.org/wiki/MIT_License">The MIT License (MIT)</a>', | ||
'<a href="https://github.com/true/php-punycode">PHP-Punycode</a> | © True B.V. | Licensed under <a href="http://en.wikipedia.org/wiki/MIT_License">The MIT License (MIT)</a>', | ||
'<a href="https://github.com/enyo/dropzone">Dropzone.js</a> | © Matias Meno | Licensed under <a href="https://en.wikipedia.org/wiki/MIT_License">The MIT License (MIT)</a>', | ||
'<a href="https://github.com/matthiasmullie/minify">Minify</a> | © Matthias Mullie | Licensed under <a href="https://en.wikipedia.org/wiki/MIT_License">The MIT License (MIT)</a>', | ||
'<a href="https://github.com/true/php-punycode">PHP-Punycode</a> | © True B.V. | Licensed under <a href="https://en.wikipedia.org/wiki/MIT_License">The MIT License (MIT)</a>', | ||
], | ||
'fonts' => [ | ||
'<a href="https://fontlibrary.org/en/font/anonymous-pro"> Anonymous Pro</a> | © 2009 | This font is licensed under the SIL Open Font License, Version 1.1', | ||
|
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