Skip to content

Commit

Permalink
CI setup (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm authored Dec 14, 2023
1 parent 24ca517 commit a1b9d67
Show file tree
Hide file tree
Showing 12 changed files with 174 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/tests export-ignore
phpstan.neon export-ignore
29 changes: 29 additions & 0 deletions .github/workflows/php-linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: PHP Linter

on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened, ready_for_review]

jobs:
php-linter:
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false

steps:
- uses: actions/checkout@v4
with:
repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }}
ref: ${{ github.event.client_payload.pull_request.head.ref }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
coverage: none
tools: parallel-lint

- name: Lint PHP
run: composer exec --no-interaction -- parallel-lint src/ tests/
44 changes: 44 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Static Analysis

on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened, ready_for_review]

jobs:
phpstan:
name: phpstan static code analysis
runs-on: ${{ matrix.os }}

strategy:
matrix:
include:
- os: ubuntu-latest
php-version: '8.0'
- os: ubuntu-latest
php-version: '8.1'
- os: ubuntu-latest
php-version: '8.2'
- os: ubuntu-latest
php-version: '8.3'

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

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: gd, intl, pdo_mysql
coverage: none # disable xdebug, pcov

- name: Composer install
uses: ramsey/composer-install@v2
with:
composer-options: '--ansi --prefer-dist'

- name: Run phpstan analysis
run: vendor/bin/phpstan analyse --ansi
44 changes: 44 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Unit tests

on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened, ready_for_review]

jobs:
phpunit:
runs-on: ${{ matrix.os }}

strategy:
matrix:
include:
- os: ubuntu-latest
php-version: '8.0'
- os: ubuntu-latest
php-version: '8.1'
- os: ubuntu-latest
php-version: '8.2'

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

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: gd, intl, pdo_mysql
coverage: none # disable xdebug, pcov

- name: Composer install
uses: ramsey/composer-install@v2
with:
composer-options: '--ansi --prefer-dist'

- name: Setup Problem Matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Run unit tests
run: vendor/bin/phpunit tests/ --colors=always
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/vendor/
/composer.lock
/test.php
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Markus Staab

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@ includes:
```

</details>

## 💌 Give back some love

[Consider supporting the project](https://github.com/sponsors/staabm), so we can make this tool even better even faster for everyone.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

"require-dev": {
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^10.5"
"phpunit/phpunit": "^9 || ^10.5"
},

"autoload": {
Expand Down
8 changes: 7 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
includes:
- extension.neon

parameters:
level: 8

paths:
- src
- tests
- tests

excludePaths:
- tests/data/*
8 changes: 7 additions & 1 deletion src/TodoByRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;

/**
* @implements Rule<Node>
*/
final class TodoByRule implements Rule
{
private const PATTERN = '/^TODO:?\s*([0-9]{4}-[0-9]{2}-[0-9]{2})(.*)$/';
Expand All @@ -18,7 +21,10 @@ public function getNodeType(): string

public function processNode(\PhpParser\Node $node, \PHPStan\Analyser\Scope $scope): array
{
if ($node instanceof VirtualNode) {
if (
$node instanceof VirtualNode
|| $node instanceof Node\Expr
) {
// prevent duplicate errors
return [];
}
Expand Down
9 changes: 8 additions & 1 deletion tests/TodoByRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
use PHPStan\Testing\RuleTestCase;
use staabm\PHPStanTodoBy\TodoByRule;

/**
* @extends RuleTestCase<TodoByRule>
*/
final class TodoByRuleTest extends RuleTestCase
{
protected function getRule(): Rule
Expand Down Expand Up @@ -49,9 +52,13 @@ public function testRule(): void
27,
],
[
"'in method comment' expired on 2023-12-14.",
"'in method comment1' expired on 2023-12-14.",
29,
],
[
"'in method comment2' expired on 2023-12-14.",
31,
],
]);
}
}
11 changes: 6 additions & 5 deletions tests/data/example.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace ExampleTest;

function doFoo() {
function doFoo():void {

}

Expand All @@ -19,14 +19,15 @@ class X {}
//TODO: 2023-12-14 Expired commentX

// TODO: 2023-12-14
function doFooBar() {
function doFooBar():void {

}

class Z {
// TODO: 2023-12-14 method comment
public function XY() {
// TODO: 2023-12-14 in method comment

public function XY():void {
// TODO: 2023-12-14 in method comment1
$x = 1;
// TODO: 2023-12-14 in method comment2
}
}

0 comments on commit a1b9d67

Please sign in to comment.