Skip to content

Commit

Permalink
+ .phpcs.xml to use rule PSR12 instead of the default rule PEAR
Browse files Browse the repository at this point in the history
… and manually ignore `vendor` & `bootstrap/cache` when running `phpc{s,bf}` as it doesn't support `.gitignore`: squizlabs/PHP_CodeSniffer#2242

* add one space before self-closing tags @ phpunit.xml & psalm.xml
* fix all violation of PHPStorm inspection `Unnecessary fully qualified name`
$ ./vendor/bin/phpcbf . && ./vendor/bin/pint
@ be
  • Loading branch information
n0099 committed Sep 15, 2024
1 parent 37dbe24 commit be5d95f
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 28 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/be_base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/be
# https://github.com/staabm/annotate-pull-request-from-checkstyle
- run: >
./vendor/bin/phpstan analyse --error-format=checkstyle
| tee >(cs2pr --notices-as-warnings --graceful-warnings --prepend-filename --prepend-source)
# https://github.com/staabm/annotate-pull-request-from-checkstyle
shell: bash
psalm:
Expand Down Expand Up @@ -65,4 +65,5 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/be
- run: ./vendor/bin/phpmd . github cleancode,codesize,controversial,design,naming,unusedcode --exclude vendor # https://github.com/phpmd/phpmd/issues/506
# https://github.com/phpmd/phpmd/issues/506
- run: ./vendor/bin/phpmd . github cleancode,codesize,controversial,design,naming,unusedcode --exclude vendor
10 changes: 10 additions & 0 deletions be/.phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<ruleset>
<rule ref="PSR12" />
<arg name="extensions" value="php" />
<exclude-pattern>*.blade.php</exclude-pattern>
<exclude-pattern>_ide_helper*.php</exclude-pattern>
<!-- https://github.com/squizlabs/PHP_CodeSniffer/issues/2242 -->
<exclude-pattern>vendor/*</exclude-pattern>
<exclude-pattern>bootstrap/cache/*</exclude-pattern>
</ruleset>
3 changes: 2 additions & 1 deletion be/app/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ public static function jsonDecode(string $json, bool $assoc = true)
}

public static function xmlResponse(string|\Stringable $xml): \Illuminate\Http\Response
{ // https://laracasts.com/discuss/channels/laravel/syntax-error-unexpected-identifier-version-1
{
// https://laracasts.com/discuss/channels/laravel/syntax-error-unexpected-identifier-version-1
return response('<?xml version="1.0" encoding="UTF-8"?>' . "\n$xml")
->withHeaders(['Content-Type' => 'text/xml']);
}
Expand Down
3 changes: 2 additions & 1 deletion be/app/Http/Controllers/ThreadsSitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class ThreadsSitemap extends Controller
public static int $maxUrls = 50000;

public function query(Http\Request $request, int $fid): Http\Response
{ // https://stackoverflow.com/questions/59554777/laravel-how-to-set-default-value-in-validator-at-post-registeration/78707950#78707950
{
// https://stackoverflow.com/questions/59554777/laravel-how-to-set-default-value-in-validator-at-post-registeration/78707950#78707950
['cursor' => $cursor] = $request->validate([
'cursor' => 'integer',
]) + ['cursor' => 0];
Expand Down
8 changes: 4 additions & 4 deletions be/app/Http/PostsQuery/BaseQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public function reOrderNestedPosts(Collection $nestedPosts): array
* @param string $childPostTypePluralName
* @return Collection<int, Collection<string, mixed|Collection<int, Collection<string, mixed>>>>
*/
$setSortingKeyFromCurrentAndChildPosts = function (Collection $curPost, string $childPostTypePluralName): \Illuminate\Support\Collection {
$setSortingKeyFromCurrentAndChildPosts = function (Collection $curPost, string $childPostTypePluralName): Collection {
/** @var Collection<int, Collection<string, mixed>> $childPosts sorted child posts */
$childPosts = $curPost[$childPostTypePluralName];
$curPost[$childPostTypePluralName] = $childPosts->values(); // reset keys
Expand Down Expand Up @@ -394,12 +394,12 @@ public function reOrderNestedPosts(Collection $nestedPosts): array

return $curPost;
};
$sortBySortingKey = fn(Collection $posts): \Illuminate\Support\Collection => $posts
$sortBySortingKey = fn(Collection $posts): Collection => $posts
->sortBy(fn(Collection $i) => $i['sortingKey'], descending: $this->orderByDesc);
$removeSortingKey = /**
* @psalm-return \Illuminate\Support\Collection<array-key, \Illuminate\Support\Collection>
* @psalm-return Collection<array-key, Collection>
*/
static fn(Collection $posts): \Illuminate\Support\Collection => $posts
static fn(Collection $posts): Collection => $posts
->map(fn(Collection $i) => $i->except('sortingKey'));
$ret = $removeSortingKey($sortBySortingKey(
$nestedPosts->map(
Expand Down
8 changes: 3 additions & 5 deletions be/app/Http/PostsQuery/IndexQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,10 @@ public function query(QueryParams $params, ?string $cursor): self
->selectRaw("{$fid} AS fid, COUNT(*) AS count")
->where($postIDName, $postID))
->reduce(/**
* @return \Illuminate\Contracts\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder
*
* @psalm-return \Illuminate\Contracts\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder<\Illuminate\Database\Eloquent\Model>|\Illuminate\Database\Query\Builder
* @return BuilderContract|EloquentBuilder|QueryBuilder
* @psalm-return BuilderContract|EloquentBuilder<\Illuminate\Database\Eloquent\Model>|QueryBuilder
*/
static fn(?BuilderContract $acc, EloquentBuilder|QueryBuilder $cur): \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|\Illuminate\Contracts\Database\Query\Builder =>
$acc === null ? $cur : $acc->union($cur),
static fn(?BuilderContract $acc, EloquentBuilder|QueryBuilder $cur): EloquentBuilder|QueryBuilder|BuilderContract => $acc === null ? $cur : $acc->union($cur),
)
->get()
->where('count', '!=', 0);
Expand Down
24 changes: 12 additions & 12 deletions be/phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
Expand All @@ -18,16 +18,16 @@
</include>
</source>
<php>
<env name="APP_ENV" value="testing"/>
<env name="APP_MAINTENANCE_DRIVER" value="file"/>
<env name="BCRYPT_ROUNDS" value="4"/>
<env name="CACHE_STORE" value="array"/>
<!-- <env name="DB_CONNECTION" value="sqlite"/> -->
<!-- <env name="DB_DATABASE" value=":memory:"/> -->
<env name="MAIL_MAILER" value="array"/>
<env name="PULSE_ENABLED" value="false"/>
<env name="QUEUE_CONNECTION" value="sync"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="TELESCOPE_ENABLED" value="false"/>
<env name="APP_ENV" value="testing" />
<env name="APP_MAINTENANCE_DRIVER" value="file" />
<env name="BCRYPT_ROUNDS" value="4" />
<env name="CACHE_STORE" value="array" />
<!-- <env name="DB_CONNECTION" value="sqlite" /> -->
<!-- <env name="DB_DATABASE" value=":memory:" /> -->
<env name="MAIL_MAILER" value="array" />
<env name="PULSE_ENABLED" value="false" />
<env name="QUEUE_CONNECTION" value="sync" />
<env name="SESSION_DRIVER" value="array" />
<env name="TELESCOPE_ENABLED" value="false" />
</php>
</phpunit>
6 changes: 3 additions & 3 deletions be/psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
findUnusedCode="true"
>
<projectFiles>
<directory name="app"/>
<directory name="app" />
<ignoreFiles>
<directory name="vendor"/>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<plugins>
<pluginClass class="Psalm\LaravelPlugin\Plugin"/>
<pluginClass class="Psalm\LaravelPlugin\Plugin" />
</plugins>
</psalm>

0 comments on commit be5d95f

Please sign in to comment.