yousha/codecop

A lightweight static analyzer that scan PHP files for quality issues.

1.0.0 2025-05-20 11:24 UTC

This package is auto-updated.

Last update: 2025-05-20 11:26:27 UTC


README

A lightweight static analyzer that scan PHP files for quality issues.

current version contributions welcome

Contents

Overview

CodeCop is a lightweight yet powerful static analysis tool designed specifically for PHP codebases. This command-line utility scans PHP files within a specified directory (and its subdirectories) to identify common code quality issues that can affect maintainability, reliability, and consistency of PHP applications. The tool focuses on enforcing modern PHP best practices and detecting potential problems before they make their way into production environments.

Features

  • No external dependency/library
  • Validates strict type(declare(strict_types=1)) declaration
  • Enforces final or abstract for all classes
  • Requires return types for all methods (except __construct)
  • Skips non-project directories automatically
  • Handles anonymous classes properly
  • Detects non-UTF-8 encoded files
  • Warns about UTF-8 BOM (Byte Order Mark)
  • Supported PHP: 8.3
  • Supported platforms: Windows, GNU/Linux, MacOS

Requirements

  1. PHP >= 8.3
  2. Composer >= 2

Installation

composer require yousha/codecop --dev

Usage

php vendor/bin/codecop.php

Output:

PHP Code Analyzer - Scans PHP files for code quality issues.

Usage: php bin/codecop.php

Options: --help Show this help message --version Show version information

Examples: php bin/codecop.php . php bin/codecop.php src/ php bin/codecop.php /path/to/your/project

Basic usage:

php vendor/bin/codecop.php src/

Check version:

php vendor/bin/codecop.php --version

Get help:

php vendor/bin/codecop.php --help

Support

Changelog

See CHANGELOG.txt file.

ToDo

See TODO.txt file.

Notice

See NOTICE.txt file.

License

This open-source software is distributed under the GPL-3.0 license. See LICENSE file.