Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: 'PHPStan Static Analysis'

on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]

jobs:
phpstan:
name: PHPStan
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.2'
coverage: none
tools: composer:v2

- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest --no-interaction

- name: Run PHPStan
run: composer phpstan
10 changes: 8 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
"lucatume/di52": "^3.0",
"lucatume/wp-browser": "^3.0.14",
"codeception/module-phpbrowser": "^1.0.0",
"codeception/module-asserts": "^1.0.0"
"codeception/module-asserts": "^1.0.0",
"phpstan/phpstan": "^1.12",
"szepeviktor/phpstan-wordpress": "^1.3"
},
"autoload": {
"psr-4": {
Expand All @@ -45,5 +47,9 @@
"type": "git",
"url": "https://github.com/wordpress/wordpress-develop.git"
}
]
],
"scripts": {
"phpstan": "phpstan analyse --memory-limit=512M",
"phpstan:baseline": "phpstan analyse --generate-baseline=phpstan-baseline.neon --memory-limit=512M"
}
}
180 changes: 176 additions & 4 deletions composer.lock

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

26 changes: 26 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
includes:
- vendor/szepeviktor/phpstan-wordpress/extension.neon

parameters:
# Level 5 is a good balance between strictness and practicality
level: 5

# Paths to analyze
paths:
- src

# Exclude paths
excludePaths:
- vendor/*
- _wordpress/*
- _plugins/*

# Ignore specific errors if needed
ignoreErrors:
# Add specific error patterns to ignore here if needed

# PHP version (must be an integer)
phpVersion: 70200

# Treat missing return types as mixed
treatPhpDocTypesAsCertain: false
4 changes: 3 additions & 1 deletion src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public static function setHookPrefix(string $prefix)
/**
* @since 1.0.0
*
* @return never
* @throws ValidationExceptionInterface
*/
public static function throwValidationException()
Expand Down Expand Up @@ -118,6 +119,7 @@ public static function setValidationExceptionClass(string $validationExceptionCl
/**
* @since 1.0.0
*
* @return never
* @throws InvalidArgumentException
*/
public static function throwInvalidArgumentException()
Expand Down Expand Up @@ -162,7 +164,7 @@ public static function initialize()
return;
}

if (empty(self::$container)) {
if (self::$container === null) {
throw new RuntimeException('A service container must be set before initializing the library');
}

Expand Down
4 changes: 3 additions & 1 deletion src/Exceptions/Contracts/ValidationExceptionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace StellarWP\Validation\Exceptions\Contracts;

interface ValidationExceptionInterface
use Throwable;

interface ValidationExceptionInterface extends Throwable
{

}
1 change: 1 addition & 0 deletions src/Rules/Abstracts/ConditionalRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public static function fromString(string $options = null): ValidationRule
$conditionSet->and($rule[0], '=', $rule[1]);
}

// @phpstan-ignore-next-line
return new static($conditionSet);
}

Expand Down
1 change: 1 addition & 0 deletions src/Rules/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static function id(): string
*/
public static function fromString(string $options = null): ValidationRule
{
// @phpstan-ignore-next-line
return new static($options);
}

Expand Down
Loading