Skip to content

Commit d388760

Browse files
committed
added phpstan typecheck
1 parent 9c3adb3 commit d388760

6 files changed

Lines changed: 76 additions & 28 deletions

File tree

.github/workflows/code_checks.yaml

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,35 @@ on:
1010
workflow_dispatch: ~
1111

1212
jobs:
13+
phpstan:
14+
runs-on: ubuntu-latest
15+
timeout-minutes: 5
16+
env:
17+
APP_DEBUG: '1' # https://github.com/phpstan/phpstan-symfony/issues/37
18+
SYMFONY_REQUIRE: '^7.0'
19+
SYMFONY_PHPUNIT_VERSION: '9.5'
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Setup PHP
25+
uses: shivammathur/setup-php@v2
26+
with:
27+
php-version: '8.3'
28+
tools: flex
29+
coverage: none # disable xdebug, pcov
30+
ini-values: memory_limit=-1
31+
32+
- name: Update project dependencies
33+
run: |
34+
composer update --no-interaction --no-progress --ansi
35+
composer require --dev "phpstan/phpstan:^1.10" "phpstan/phpstan-strict-rules:^1.5" "phpstan/phpstan-phpunit: ^1.3" "phpstan/phpstan-deprecation-rules:^1.1"
36+
37+
- name: Run PHPStan analysis
38+
run: |
39+
./vendor/bin/phpstan --version
40+
./vendor/bin/phpstan analyse --no-interaction --no-progress --ansi
41+
1342
phpunit:
1443
runs-on: ubuntu-latest
1544
strategy:
@@ -82,30 +111,26 @@ jobs:
82111
code-coverage:
83112
name: Code Coverage
84113
runs-on: ubuntu-latest
114+
timeout-minutes: 5
115+
env:
116+
APP_DEBUG: '1' # https://github.com/phpstan/phpstan-symfony/issues/37
117+
SYMFONY_REQUIRE: '^5.0'
118+
SYMFONY_PHPUNIT_VERSION: '9.5'
85119
steps:
86-
- name: Checkout code
87-
uses: actions/checkout@v3
120+
- name: Checkout
121+
uses: actions/checkout@v4
88122

89123
- name: Setup PHP
90124
uses: shivammathur/setup-php@v2
91125
with:
92-
php-version: 7.4
126+
php-version: '7.4'
127+
tools: flex
93128
coverage: xdebug
129+
ini-values: memory_limit=-1
94130

95-
- name: Get Composer cache directory
96-
id: composer-cache
97-
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
98-
99-
- name: Cache Composer
100-
uses: actions/cache@v3
101-
with:
102-
path: ${{ steps.composer-cache.outputs.dir }}
103-
key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json **/composer.lock') }}
104-
restore-keys: |
105-
${{ runner.os }}-php-${{ matrix.php }}-composer-
106-
107-
- name: Install PHP dependencies
108-
run: composer install --no-interaction
131+
- name: Update project dependencies
132+
run: |
133+
composer update --no-interaction --no-progress --ansi
109134
110135
- name: Run code coverage
111136
run: vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover

Tests/Form/Recaptcha3TypeTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ public function testDefaultOptions()
2727
$form = $this->factory->create(Recaptcha3Type::class);
2828
$form->setData($data);
2929

30-
$this->assertTrue($form->isSynchronized());
31-
$this->assertEquals($data, $form->getData());
30+
self::assertTrue($form->isSynchronized());
31+
self::assertEquals($data, $form->getData());
3232

3333
$view = $form->createView();
34-
$this->assertSame(self::SITEKEY, $view->vars['site_key']);
35-
$this->assertSame(self::HOST, $view->vars['host']);
36-
$this->assertSame('homepage', $view->vars['action_name']);
37-
$this->assertSame('', $view->vars['script_nonce_csp']);
38-
$this->assertTrue($view->vars['enabled']);
34+
self::assertSame(self::SITEKEY, $view->vars['site_key']);
35+
self::assertSame(self::HOST, $view->vars['host']);
36+
self::assertSame('homepage', $view->vars['action_name']);
37+
self::assertSame('', $view->vars['script_nonce_csp']);
38+
self::assertTrue($view->vars['enabled']);
3939
}
4040
}

Tests/Services/HostProviderTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Services;
44

55
use Karser\Recaptcha3Bundle\Services\HostProvider;
6-
use Karser\Recaptcha3Bundle\Services\HostProviderInterface;
76
use PHPUnit\Framework\TestCase;
87

98
class HostProviderTest extends TestCase
@@ -12,7 +11,7 @@ class HostProviderTest extends TestCase
1211
public function test__construct()
1312
{
1413
$hostProvider = new HostProvider('www.a-domain.tld');
15-
self::assertInstanceOf(HostProviderInterface::class, $hostProvider);
14+
self::assertSame('www.a-domain.tld', $hostProvider->getHost());
1615
}
1716

1817
public function testGetHost()

Tests/TestKernel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function setConfigurationFilename($filename)
2222
/**
2323
* {@inheritdoc}
2424
*/
25-
public function registerBundles(): array
25+
public function registerBundles(): iterable
2626
{
2727
return [
2828
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),

Tests/Validator/Constraints/Recaptcha3ValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function testLastResponse()
105105
$this->recaptcha->nextSuccess = true;
106106

107107
$validator = new Recaptcha3Validator($this->recaptcha, $enabled = true, $this->resolver);
108-
self::assertNull($this->validator->getLastResponse());
108+
self::assertNull($validator->getLastResponse());
109109

110110
$validator->validate('test', new Recaptcha3());
111111
self::assertNotNull($validator->getLastResponse());

phpstan.neon

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
includes:
2+
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
3+
- vendor/phpstan/phpstan-strict-rules/rules.neon
4+
5+
parameters:
6+
level: 5
7+
reportUnmatchedIgnoredErrors: false
8+
checkMissingIterableValueType: false
9+
checkGenericClassInNonGenericObjectType: false
10+
inferPrivatePropertyTypeFromConstructor: true
11+
paths:
12+
- %currentWorkingDirectory%
13+
ignoreErrors:
14+
- '#Class Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder constructor invoked with 0 parameters, 1-3 required#'
15+
- '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder::root\(\)#'
16+
- '#Call to function method_exists\(\) with .*?TreeBuilder.*? and .*?getRootNode.*? will always evaluate to true#'
17+
- '#Comparison operation "<" between 70006 and 50200 is always false#'
18+
- '#Comparison operation ">=" between 7 and 6 is always true#'
19+
- '#Else branch is unreachable because ternary operator condition is always true#'
20+
21+
excludePaths:
22+
- %currentWorkingDirectory%/.github/*
23+
- %currentWorkingDirectory%/.idea/*
24+
- %currentWorkingDirectory%/vendor/*

0 commit comments

Comments
 (0)