name: Lint php code
on:
  push:
  pull_request:
    types: [opened, reopened, synchronize]

jobs:
  changes:
    runs-on: ubuntu-latest
    outputs:
      php: ${{ steps.filter.outputs.php }}
    steps:
    - uses: actions/checkout@v2
      with:
        fetch-depth: 0
    - uses: dorny/paths-filter@v2
      id: filter
      with:
        filters: |
          php:
            - '**/*.php'
  lint:
    needs: changes
    if: ${{ needs.changes.outputs.php == 'true' }}
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - uses: shivammathur/setup-php@v2
        with:
          php-version: 8.0      
      - run: |
          composer config --no-plugins allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
          composer require nunomaduro/phpinsights --dev
          php vendor/bin/phpinsights --version
          php vendor/bin/phpinsights analyse --no-interaction --format=github-action \
          --min-style=100 --min-architecture=100 --min-quality=100
