name: Coding Standards

on: pull_request

jobs:
  tests:
    name: PHPCS
    runs-on: ubuntu-latest

    steps:
      - name: Cancel previous runs of this workflow (pull requests only)
        if: ${{ github.event_name == 'pull_request' }}
        uses: styfle/cancel-workflow-action@0.5.0
        with:
          access_token: ${{ github.token }}

      - name: Checkout code
        uses: actions/checkout@v2

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

      - name: Log information
        run: |
          echo "$GITHUB_REF"
          echo "$GITHUB_EVENT_NAME"
          git --version
          php --version
          composer --version

      - name: Validate Composer
        run: composer validate --strict

      - name: Install dependencies
        uses: ramsey/composer-install@v1
        with:
          composer-options: "--ignore-platform-reqs"

      - name: Run Linter
        run: composer lint

      - name: Run PHPCS
        run: composer phpcs
