parameters:
  cacheDirectory: $(Pipeline.Workspace)/phpcs
  reportFile: $(Pipeline.Workspace)/phpcs.xml

steps:
  - task: CacheBeta@0
    inputs:
      key: phpcs | $(Agent.OS) | $(Build.SourceVersion)
      path: ${{ parameters.cacheDirectory }}
      restoreKeys: |
        phpcs | $(Agent.OS)
        phpcs
    displayName: 'Cache PHP_CodeSniffer State'

  - script: mkdir -p ${{ parameters.cacheDirectory }}
    displayName: 'Create Cache Directory'

  - script: vendor/bin/phpcs -n -q --cache=${{ parameters.cacheDirectory }}/cache.json --report=junit --report-file=${{ parameters.reportFile }} --runtime-set ignore_warnings_on_exit true
    displayName: 'Run PHP_CodeSniffer'

  - task: PublishTestResults@2
    inputs:
      testRunner: JUnit
      testResultsFiles: ${{ parameters.reportFile }}
      failTaskOnFailedTests: true
      testRunTitle: PHP_CodeSniffer

parameters:
  cacheDirectory: $(Pipeline.Workspace)/phpcs
  reportFile: $(Pipeline.Workspace)/phpcs.xml

steps:
  - task: CacheBeta@0
    inputs:
      key: phpcs | $(Agent.OS) | $(Build.SourceVersion)
      path: ${{ parameters.cacheDirectory }}
      restoreKeys: |
        phpcs | $(Agent.OS)
        phpcs
    displayName: 'Cache PHP_CodeSniffer State'

  - script: mkdir -p ${{ parameters.cacheDirectory }}
    displayName: 'Create Cache Directory'

  - script: vendor/bin/phpcs -n -q --cache=${{ parameters.cacheDirectory }}/cache.json --report=junit --report-file=${{ parameters.reportFile }} --runtime-set ignore_errors_on_exit true --runtime-set ignore_warnings_on_exit true
    displayName: 'Run PHP_CodeSniffer'

  - task: PublishTestResults@2
    inputs:
      testRunner: JUnit
      testResultsFiles: ${{ parameters.reportFile }}
      failTaskOnFailedTests: true
      testRunTitle: PHP_CodeSniffer

Test results are not published if exit code is non-zero
Test results are not published if exit code is non-zero
