Skip to main content

Python wrapper for PHP-CS-Fixer with a bundled static PHP binary

Project description

php-cs-fixer-py

PHP-CS-Fixer in Python — check and fix PHP code style through a typed API.

Python wrapper for PHP-CS-Fixer — no local PHP or Composer required.

Install

# via uv
uv add php-cs-fixer-py

# or via pip
pip install php-cs-fixer-py

Requires Python >= 3.11. Platform wheels bundle PHP-CS-Fixer 3.95.3 (as PHAR) and a static PHP 8.4 binary (built on static-php-py); a php on PATH is the fallback when no bundled binary matches the host. fixer_version() reports the bundled version at runtime.

Usage

from php_cs_fixer_py import fix, check, Source

# Two verbs. fix changes, check diagnoses. Both return a FixResult.

# Fix files in place
result = fix("src/", rules={"@Symfony": True, "array_syntax": {"syntax": "short"}})
print(f"changed {len(result.files)} files")

# Check files (dry-run) — nothing written
report = check("src/", rules={"@PSR12": True})
if not report.compliant:                 # CI gate
    for f in report.files:
        print(f.name, f.applied_fixers)
    raise SystemExit(1)

# Fix a source string — wrap in Source.code, read the fixed text off .code
clean = fix(Source.code("<?php $a = array(1,2);"), rules={"@PSR12": True}).code

# Check a source string — same FixResult, ask for .compliant
ok = check(Source.code(clean), rules={"@PSR12": True}).compliant

API

Two verbs split on Command/Query Separation: fix (command) and check (query). Both return a unified FixResult, so the return type depends on the verb, never on the input. Input kind is carried by Source; a bare path works directly, raw source needs Source.code(...).

Function / Class Signature Description
fix (source, rules, *, risky=False, **opts) -> FixResult Apply fixes (in place for paths)
check (source, rules, *, risky=False, **opts) -> FixResult Dry-run; report what would change
Source.code (text) -> Source Tag raw PHP source (staged to a temp file)
Source.path (*targets) -> Source Tag file/directory paths
list_rule_sets () -> list[str] Available @-prefixed rule sets
fixer_version () -> str Bundled PHP-CS-Fixer version
Fixer (php=None) Class form; reuse one PHP/PHAR resolution
FixerConfig (rules, risky=…, …) Optional reusable configuration object
FixResult.code -> str Fixed source (after fix on a code source)
FixResult.compliant -> bool True when nothing would change
FixResult.files -> tuple[FileResult, …] Per-file diffs and applied fixers
FixResult.changed -> bool Any file changed / would change
FixResult.status -> FixStatus Decoded exit-code flags

Full specifications in docs/design.md.

Documentation

  • Concepts — problem scope, data flow, and core terminology.
  • Design — class specifications, public API, module structure.
  • Implementation — library APIs, CLI invocation, report schema, exit codes.

For Agents

Agent-consumable documentation index at docs/llms.txt (llmstxt.org format).

Citation

If you use this project in academic work, please cite our paper. BibTeX (placeholder until the paper is released):

@misc{beluga_placeholder,
  title  = {{TODO: paper title — not yet released}},
  author = {{TODO: authors}},
  year   = {{TODO}},
  note   = {Paper not yet released. Citation entry will be updated on publication.}
}

License

GPL-2.0 — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

php_cs_fixer_py-0.1.4-py3-none-win_amd64.whl (10.1 MB view details)

Uploaded Python 3Windows x86-64

php_cs_fixer_py-0.1.4-py3-none-manylinux_2_17_x86_64.musllinux_1_1_x86_64.whl (9.7 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64musllinux: musl 1.1+ x86-64

php_cs_fixer_py-0.1.4-py3-none-manylinux_2_17_aarch64.musllinux_1_1_aarch64.whl (9.8 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64musllinux: musl 1.1+ ARM64

php_cs_fixer_py-0.1.4-py3-none-macosx_11_0_x86_64.whl (10.2 MB view details)

Uploaded Python 3macOS 11.0+ x86-64

php_cs_fixer_py-0.1.4-py3-none-macosx_11_0_arm64.whl (9.8 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

Details for the file php_cs_fixer_py-0.1.4-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for php_cs_fixer_py-0.1.4-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 55e744dd445dd86c337807936e07a788d0a633360d9d29d52f849ff379ef7cc4
MD5 7ab719453b2f294dc3a273afb1c80f85
BLAKE2b-256 efcabc5d4a810399fc8a07940886745ffb416abe48a4bf66e9a69403cd82f2b8

See more details on using hashes here.

File details

Details for the file php_cs_fixer_py-0.1.4-py3-none-manylinux_2_17_x86_64.musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for php_cs_fixer_py-0.1.4-py3-none-manylinux_2_17_x86_64.musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 8c63029e6de434c4b0fcad7ae20088f84c5c48383504027d8c3257de9e6ae6f3
MD5 5a94ecd84f76ac63e253b0c1bac6d385
BLAKE2b-256 9f32c576c1668691bd27bde3c873240604998b372d1cedbb9c7acee51646ed8e

See more details on using hashes here.

File details

Details for the file php_cs_fixer_py-0.1.4-py3-none-manylinux_2_17_aarch64.musllinux_1_1_aarch64.whl.

File metadata

File hashes

Hashes for php_cs_fixer_py-0.1.4-py3-none-manylinux_2_17_aarch64.musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 197e9dba76013fcdd359f9a98e83a8bdf419a5a851e63b8f3a1d97b0f9fba38d
MD5 c5d6a107b10d6b681bd5daf1e172f206
BLAKE2b-256 fe0b727e938e48dde2b5f36fd7d09b9e4bb510af43bd1e9ee1fbdd329e484a5d

See more details on using hashes here.

File details

Details for the file php_cs_fixer_py-0.1.4-py3-none-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for php_cs_fixer_py-0.1.4-py3-none-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 655c1ecef285c02874e5e548c678ba1ec9af26e461f4e395202d8512f9134898
MD5 29df4672f0cc690d4dc3847777a015bc
BLAKE2b-256 84dfde831178efbc756a73fe947141e173730639e276d26e4904ef2b627ba8dd

See more details on using hashes here.

File details

Details for the file php_cs_fixer_py-0.1.4-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for php_cs_fixer_py-0.1.4-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 18fc62363536a2eaa502f0025dc29bd79ad715149cd44854def01d8de543f2f3
MD5 6acd68af342dee09240c6a113bcbac91
BLAKE2b-256 debfe6cc86045174811194a8803efca7d62662f6240e75e449d410723976a66e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page