Skip to content

Commit

Permalink
Configure ECS, PHPStan and Psalm
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmaudo committed Mar 8, 2024
1 parent 85c998e commit dc5165e
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Code Style
name: Coding Standards

on:
push:
Expand All @@ -7,8 +7,8 @@ on:
pull_request:

jobs:
code-style:
name: Code Style - PHP ${{ matrix.php }} Ubuntu
ecs:
name: ECS - PHP ${{ matrix.php }} Ubuntu

strategy:
fail-fast: false
Expand All @@ -31,9 +31,8 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: json, dom, libxml, mbstring, xml, xmlwriter
style: xdebug
tools: php-coveralls/php-coveralls
extensions: json
coverage: none

- name: Install dependencies
uses: ramsey/composer-install@v2
Expand All @@ -42,6 +41,6 @@ jobs:

- name: Run Easy Coding Standard
run: |
php -d memory_limit=-1 -d zend.enable_gc=0 -d error_reporting=-1 vendor/bin/ecs check;
php -d memory_limit=-1 -d zend.enable_gc=0 -d error_reporting=-1 vendor/bin/ecs --ansi --no-progress-bar;
env:
PHP_VERSION: ${{ matrix.php }}
84 changes: 84 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Static Analysis

on:
push:
branches:
- main
pull_request:

jobs:
phpstan:
name: PHPStan - PHP ${{ matrix.php }} Ubuntu

strategy:
fail-fast: false
matrix:
php:
- '8.0'
- '8.1'
- '8.2'
- '8.3'
dependencies:
- 'highest'

runs-on: ubuntu-latest

steps:
- name: Checkout the code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: json
coverage: none

- name: Install dependencies
uses: ramsey/composer-install@v2
with:
dependency-versions: ${{ matrix.dependencies }}

- name: Run Psalm
run: |
php -d memory_limit=-1 -d zend.enable_gc=0 -d error_reporting=-1 vendor/bin/phpstan --ansi --no-progress --error-format=github;
env:
PHP_VERSION: ${{ matrix.php }}

psalm:
name: Psalm - PHP ${{ matrix.php }} Ubuntu

strategy:
fail-fast: false
matrix:
php:
- '8.0'
- '8.1'
- '8.2'
- '8.3'
dependencies:
- 'highest'

runs-on: ubuntu-latest

steps:
- name: Checkout the code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: json
coverage: none

- name: Install dependencies
uses: ramsey/composer-install@v2
with:
dependency-versions: ${{ matrix.dependencies }}

- name: Run Psalm
run: |
php -d memory_limit=-1 -d zend.enable_gc=0 -d error_reporting=-1 vendor/bin/psalm --no-progress --output-format=github --shepherd;
env:
PHP_VERSION: ${{ matrix.php }}
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
fix := false

ecs:
ifeq ($(fix), true)
vendor/bin/ecs --fix --clear-cache --ansi
else
vendor/bin/ecs --clear-cache --ansi
endif

phpstan:
vendor/bin/phpstan --ansi

psalm:
vendor/bin/psalm --threads=4 --diff

coding-standards: ecs
code-quality: coding-standards phpstan psalm
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
"require": {
"symplify/easy-coding-standard": "^12.1"
},
"require-dev": {
"phpstan/phpstan": "^1.10",
"vimeo/psalm": "^5.22"
},
"autoload": {
"psr-4": {
"Hereldar\\": "src/"
Expand Down
7 changes: 7 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
parameters:
level: 9
paths:
- sets
- src
scanDirectories:
- vendor
29 changes: 29 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0"?>
<psalm
errorLevel="1"
findUnusedBaselineEntry="true"
findUnusedCode="true"
findUnusedVariablesAndParams="true"
resolveFromConfigFile="true"
strictBinaryOperands="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="sets"/>
<directory name="src"/>
<ignoreFiles>
<directory name="vendor"/>
</ignoreFiles>
</projectFiles>
<issueHandlers>
<InternalClass errorLevel="suppress"/>
<InternalMethod errorLevel="suppress"/>
<PropertyNotSetInConstructor>
<errorLevel type="suppress">
<referencedProperty name="PhpCsFixer\AbstractFixer::$whitespacesConfig" />
</errorLevel>
</PropertyNotSetInConstructor>
</issueHandlers>
</psalm>
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ public function isCandidate(Tokens $tokens): bool
protected function applyFix(SplFileInfo $file, Tokens $tokens): void
{
/**
* @var int $blockStartIndex
* @var int $index
* @var Token $token
*/
foreach ($tokens as $index => $token) {
/** @phpstan-ignore-next-line */
if (!$token->isGivenKind(self::TARGET_KINDS)
|| $token->equalsAny(self::TARGET_TOKENS)) {
continue;
Expand Down Expand Up @@ -126,6 +127,7 @@ private function containsAnyComparisonToken(Tokens $tokens, int $startIndex, int
{
for ($i = $startIndex; $i < $endIndex; ++$i) {
$token = $tokens[$i];
/** @phpstan-ignore-next-line */
if ($token->isGivenKind(self::COMPARISON_KINDS)
|| $token->equalsAny(self::COMPARISON_TOKENS)) {
return true;
Expand Down

0 comments on commit dc5165e

Please sign in to comment.