PHP code example of hfryan / php-cop

1. Go to this page and download the library: Download hfryan/php-cop library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hfryan / php-cop example snippets

bash
# Install globally
composer global ATH
php ~/.composer/vendor/hfryan/php-cop/bin/phpcop.php setup
bash
# Install in your PHP project
composer in/phpcop.php scan
bash
# Basic CI check - fail on any vulnerabilities
phpcop scan --fail-on=low --quiet
echo "Exit code: $?"

# Production deployment - fail only on high/critical vulnerabilities
phpcop scan --fail-on=high --format=json > security-report.json
echo "Exit code: $?"

# Security-focused scan - exclude dev dependencies
phpcop scan --exclude-dev --min-severity=moderate --exit-code=enhanced
echo "Exit code: $?"

# Legacy compatibility mode (simple 0/1 exit codes)
phpcop scan --exit-code=legacy --fail-on=high
echo "Exit code: $?"
yaml
- name: PHPCop Scan
  id: phpcop
  uses: hfryan/php-cop@main
  with:
    fail-on: 'critical'
    
- name: Handle Results
  run: |
    echo "Exit code: ${{ steps.phpcop.outputs.exit-code }}"
    echo "Issues found: ${{ steps.phpcop.outputs.issues-found }}"
    echo "Vulnerabilities: ${{ steps.phpcop.outputs.vulnerabilities-found }}"
dockerfile
RUN wget https://github.com/hfryan/php-cop/releases/latest/download/phpcop.phar && \
    php phpcop.phar scan --exclude-dev --fail-on=high