Skip to content

Commit

Permalink
Code: modernize (phpstan, codesniffer, git)
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Dec 22, 2022
1 parent c87b327 commit 3e1ec75
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ indent_style = tab
indent_size = tab
tab_width = 4

[{*.json, *.yaml, *.yml, *.md}]
[{*.json,*.yml,*.yaml,*.md}]
indent_style = space
indent_size = 2
4 changes: 2 additions & 2 deletions .github/workflows/codesniffer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ on:
- cron: "0 8 * * 1"

jobs:
build:
codesniffer:
name: "Codesniffer"
uses: contributte/.github/.github/workflows/codesniffer.yml@master
uses: contributte/.github/.github/workflows/codesniffer.yml@v1
15 changes: 15 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: "Coverage"

on:
pull_request:

push:
branches: ["*"]

schedule:
- cron: "0 8 * * 1"

jobs:
coverage:
name: "Nette Tester"
uses: contributte/.github/.github/workflows/nette-tester-coverage.yml@v1
4 changes: 2 additions & 2 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ on:
- cron: "0 8 * * 1"

jobs:
build:
phpstan:
name: "Phpstan"
uses: contributte/.github/.github/workflows/phpstan.yml@master
uses: contributte/.github/.github/workflows/phpstan.yml@v1
45 changes: 29 additions & 16 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,51 @@ on:
pull_request:

push:
branches: ["*"]
branches: [ "*" ]

schedule:
- cron: "0 8 * * 1"

jobs:
build81:
test82:
name: "Nette Tester"
uses: contributte/.github/.github/workflows/nette-tester.yml@master
uses: contributte/.github/.github/workflows/nette-tester.yml@v1
with:
php: "8.1"
php: "8.2"

build80:
test81:
name: "Nette Tester"
uses: contributte/.github/.github/workflows/nette-tester.yml@master
uses: contributte/.github/.github/workflows/nette-tester.yml@v1
with:
php: "8.0"
php: "8.1"

build74:
test80:
name: "Nette Tester"
uses: contributte/.github/.github/workflows/nette-tester.yml@master
uses: contributte/.github/.github/workflows/nette-tester.yml@v1
with:
php: "7.4"
php: "8.0"

build73:
test74:
name: "Nette Tester"
uses: contributte/.github/.github/workflows/nette-tester.yml@master
uses: contributte/.github/.github/workflows/nette-tester.yml@v1
with:
php: "7.3"
php: "7.4"

build72:
test73:
name: "Nette Tester"
uses: contributte/.github/.github/workflows/nette-tester.yml@master
uses: contributte/.github/.github/workflows/nette-tester.yml@v1
with:
php: "7.2"
php: "7.3"

test72:
name: "Nette Tester"
uses: contributte/.github/.github/workflows/nette-tester.yml@v1
with:
php: "7.2"

testlower:
name: "Nette Tester"
uses: contributte/.github/.github/workflows/nette-tester.yml@v1
with:
php: "7.2"
composer: "composer update --no-interaction --no-progress --prefer-dist --prefer-stable --prefer-lowest"
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@
/composer.lock

# Tests
/temp
/coverage.xml
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ qa: phpstan cs

cs:
ifdef GITHUB_ACTION
vendor/bin/codesniffer -q --report=checkstyle src tests | cs2pr
vendor/bin/phpcs --standard=ruleset.xml --encoding=utf-8 --extensions="php,phpt" --colors -nsp -q --report=checkstyle src tests | cs2pr
else
vendor/bin/codesniffer src tests
vendor/bin/phpcs --standard=ruleset.xml --encoding=utf-8 --extensions="php,phpt" --colors -nsp src tests
endif

csf:
vendor/bin/codefixer src tests
vendor/bin/phpcbf --standard=ruleset.xml --encoding=utf-8 --colors -nsp src tests

phpstan:
vendor/bin/phpstan analyse -c phpstan.neon src
vendor/bin/phpstan analyse -c phpstan.neon

tests:
vendor/bin/tester -s -p php --colors 1 -C tests/cases
vendor/bin/tester -s -p php --colors 1 -C tests/Cases

coverage:
ifdef GITHUB_ACTION
vendor/bin/tester -s -p phpdbg --colors 1 -C --coverage coverage.xml --coverage-src src tests/cases
vendor/bin/tester -s -p phpdbg --colors 1 -C --coverage coverage.xml --coverage-src src tests/Cases
else
vendor/bin/tester -s -p phpdbg --colors 1 -C --coverage coverage.html --coverage-src src tests/cases
vendor/bin/tester -s -p phpdbg --colors 1 -C --coverage coverage.html --coverage-src src tests/Cases
endif
10 changes: 10 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,15 @@ parameters:
level: 9
phpVersion: 70200

scanDirectories:
- src

fileExtensions:
- php

paths:
- src

ignoreErrors:
- '#Unsafe usage of new static\(\).#'
- '#Strict comparison using === between non-empty-array<int, string> and false will always evaluate to false#'
29 changes: 14 additions & 15 deletions ruleset.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
<?xml version="1.0"?>
<ruleset>
<rule ref="./vendor/ninjify/coding-standard/contributte.xml">
<exclude name="Squiz.Commenting.FunctionComment.InvalidTypeHint"/>
<!-- Useless for yield in tests -->
<exclude name="SlevomatCodingStandard.ControlStructures.ControlStructureSpacing.IncorrectLinesCountBeforeControlStructure"/>
<exclude name="SlevomatCodingStandard.ControlStructures.ControlStructureSpacing.IncorrectLinesCountAfterControlStructure"/>
</rule>
<?xml version="1.0" encoding="UTF-8"?>
<ruleset
name="Contributte"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd"
>
<!-- Rulesets -->
<rule ref="./vendor/ninjify/coding-standard/contributte.xml"/>

<!-- Package specific rules -->
<!-- Rules -->
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
<properties>
<property name="rootNamespaces" type="array" value="
src=>Contributte\Utils,
tests/cases=>Tests\Contributte\Utils,
"/>
<property name="extensions" type="array" value="php, phpt"/>
<property name="rootNamespaces" type="array">
<element key="src" value="Contributte\Utils"/>
<element key="tests" value="Tests"/>
</property>
</properties>
</rule>

<!-- Exclude folders -->
<!-- Excludes -->
<exclude-pattern>/tests/tmp</exclude-pattern>
</ruleset>
3 changes: 3 additions & 0 deletions src/Deeper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Deeper
* @template T
* @param array-key $key
* @param array<T> $arr
* @param non-empty-string $sep
*/
public static function has($key, array $arr, string $sep = '.'): bool
{
Expand All @@ -26,6 +27,7 @@ public static function has($key, array $arr, string $sep = '.'): bool
* @template T
* @param array-key $key
* @param array<T> $arr
* @param non-empty-string $sep
* @param ?T $default
* @return ?T
*/
Expand All @@ -40,6 +42,7 @@ public static function get($key, array $arr, string $sep = '.', $default = null)

/**
* @param string|int|bool|null $key
* @param non-empty-string $sep
* @return string[]
*/
public static function flat($key, string $sep = '.'): array
Expand Down

0 comments on commit 3e1ec75

Please sign in to comment.