Skip to content

Commit

Permalink
Merge branch 'improve-anonymous-fn'
Browse files Browse the repository at this point in the history
  • Loading branch information
lkrms committed Jan 18, 2025
2 parents 40ee45e + 9730250 commit 104b23c
Show file tree
Hide file tree
Showing 10 changed files with 303 additions and 108 deletions.
8 changes: 4 additions & 4 deletions box.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
{
"in": "vendor",
"notName": [
"/^(?:LICENSE|README|composer\\.(?:json|lock))$|phpstan\\.|\\.md$/"
"/^(?:(?:(?i)README|CHANGELOG)(?:\\.md)?|composer\\.(?:json|lock))$|phpstan\\./"
],
"notPath": [
"/^salient\\/contracts\\/(?:Curler|Db|Http|Sync)\\//",
"/^salient\\/contracts\\/(?:Core\\/Pipeline|Curler|Db|Http|Sync)\\//",
"/^lkrms\\/dice\\/src\\/Loader\\//",
"/^psr\\/(?:http-(?:client|message)|log\\/Psr\\/Log\\/Test)\\//"
]
Expand All @@ -27,8 +27,8 @@
"",
"(c) Luke Arms <[email protected]>",
"",
"For the full copyright and license information, please view the LICENSE",
"file that was distributed with this source code."
"For the full license and copyright notice, see the LICENSE file distributed",
"with the source code."
],
"compactors": [
"KevinGH\\Box\\Compactor\\Json",
Expand Down
5 changes: 4 additions & 1 deletion docs/Rules.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 71 additions & 9 deletions scripts/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ function die() {
((!s)) && exit 1 || exit "$s"
}

# usage [<error-message>]
function usage() {
if (($#)); then
cat >&2 && false || die "$@"
else
cat
fi <<EOF
usage: ${0##*/} run all tests
${0##*/} --phpstan run PHPStan
${0##*/} --phpunit run PHPUnit tests
${0##*/} --build build and test phar and man page${1:+
}
EOF
exit
}

# run <command> [<argument>...]
function run() {
printf '==> running:%s\n' "$(printf ' %q' "$@")" >&2
Expand All @@ -34,13 +50,59 @@ function run_with_php_versions() {
[[ ${BASH_SOURCE[0]} -ef scripts/run-tests.sh ]] ||
die "must run from root of package folder"

run scripts/generate.sh --check
run php83 tools/php-cs-fixer check --diff --verbose
run bin/pretty-php --diff
run_with_php_versions '' 74 vendor/bin/phpstan
run_with_php_versions 84 83 82 81 80 74 vendor/bin/phpunit
ASSETS=1
FORMATTING=1
PHPSTAN=1
PHPUNIT=1
BUILD=1
if [[ ${1-} == -* ]]; then
ASSETS=0
FORMATTING=0
PHPSTAN=0
PHPUNIT=0
BUILD=0
fi
while [[ ${1-} == -* ]]; do
case "$1" in
--phpstan)
PHPSTAN=1
;;
--phpunit)
PHPUNIT=1
;;
--build)
BUILD=1
;;
-h | --help)
usage
;;
*)
usage "invalid argument: $1"
;;
esac
shift
done

if ((ASSETS)); then
run scripts/generate.sh --check
fi

if ((FORMATTING)); then
run php83 tools/php-cs-fixer check --diff --verbose
run bin/pretty-php --diff
fi

if ((PHPSTAN)); then
run_with_php_versions '' 74 vendor/bin/phpstan
fi

if ((PHPUNIT)); then
run_with_php_versions 84 83 82 81 80 74 vendor/bin/phpunit
fi

run scripts/build.sh
run scripts/build.sh man
run scripts/build.sh man worktree
run_with_php_versions 84 83 82 81 80 74 build/dist/pretty-php.phar --verbose
if ((BUILD)); then
run scripts/build.sh
run scripts/build.sh man
run scripts/build.sh man worktree
run_with_php_versions 84 83 82 81 80 74 build/dist/pretty-php.phar --verbose
fi
34 changes: 34 additions & 0 deletions src/Rule/VerticalSpacing.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public static function getTokens(AbstractTokenIndex $idx): array
\T_FOR => true,
\T_OPEN_BRACE => true,
\T_QUESTION => true,
\T_USE => true,
],
$idx->Chain,
$idx->BooleanExceptNot,
Expand Down Expand Up @@ -198,6 +199,11 @@ public function reset(): void
* Newlines are added before both operators in ternary expressions where one
* operator has a leading newline.
*
* In anonymous functions with lexical variables after parameters that break
* over multiple lines, newlines are added before each parameter. If the
* list of variables after `use` breaks over multiple lines, newlines are
* also added before each variable.
*
* In method chains where an object operator (`->` or `?->`) has a leading
* newline, newlines are added before every object operator. If the
* `AlignChains` rule is enabled and strict PSR-12 compliance is not, the
Expand Down Expand Up @@ -329,6 +335,34 @@ public function processTokens(array $tokens): void
} elseif (!$op1Newline && $op2Newline) {
$token->Whitespace |= Space::LINE_BEFORE;
}
} elseif ($token->id === \T_USE) {
if (
($close = $token->PrevCode)
&& $close->id === \T_CLOSE_PARENTHESIS
&& !$close->hasNewlineAfterPrevCode()
&& $close->outer()->hasNewline()
) {
/** @var Token */
$open = $close->OpenBracket;
/** @var TokenCollection */
$items = $open->Data[Data::LIST_ITEMS];
$items->add($close)
->applyTokenWhitespace(Space::LINE_BEFORE);

/** @var Token */
$open = $token->NextCode;
if (
!$open->hasNewlineBeforeNextCode()
&& $open->outer()->hasNewline()
) {
/** @var Token */
$close = $open->CloseBracket;
/** @var TokenCollection */
$items = $open->Data[Data::LIST_ITEMS];
$items->add($close)
->applyTokenWhitespace(Space::LINE_BEFORE);
}
}
} else {
if ($token !== $token->Data[Data::CHAIN]) {
continue;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 104b23c

Please sign in to comment.