{"id":15014445,"url":"https://github.com/adamculp/php-code-quality","last_synced_at":"2025-08-20T10:32:58.599Z","repository":{"id":41559638,"uuid":"86473405","full_name":"adamculp/php-code-quality","owner":"adamculp","description":"Docker image containing multiple code quality tools for PHP (phpqatools and more).","archived":false,"fork":false,"pushed_at":"2022-10-26T17:48:22.000Z","size":63,"stargazers_count":156,"open_issues_count":1,"forks_count":25,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-12-09T12:54:07.117Z","etag":null,"topics":["code-quality","docker","docker-image","pdepend","php","php-codesniffer","php7","php8","phpcpd","phploc","phpmd","phpmetrics","phpqatools","phpstan","phpunit","static-analysis"],"latest_commit_sha":null,"homepage":"https://hub.docker.com/r/adamculp/php-code-quality/","language":"Dockerfile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adamculp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["adamculp","beachcasts"]}},"created_at":"2017-03-28T14:59:38.000Z","updated_at":"2024-12-04T19:16:21.000Z","dependencies_parsed_at":"2023-01-19T23:40:36.448Z","dependency_job_id":null,"html_url":"https://github.com/adamculp/php-code-quality","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamculp%2Fphp-code-quality","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamculp%2Fphp-code-quality/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamculp%2Fphp-code-quality/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamculp%2Fphp-code-quality/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adamculp","download_url":"https://codeload.github.com/adamculp/php-code-quality/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230415318,"owners_count":18222158,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code-quality","docker","docker-image","pdepend","php","php-codesniffer","php7","php8","phpcpd","phploc","phpmd","phpmetrics","phpqatools","phpstan","phpunit","static-analysis"],"created_at":"2024-09-24T19:45:38.607Z","updated_at":"2024-12-19T10:10:19.244Z","avatar_url":"https://github.com/adamculp.png","language":"Dockerfile","readme":"# php-code-quality\nMy objective is to include multiple PHP code quality tools in an easy-to-use Docker image. The tools include PHP static analysis, lines of PHP code report, mess detector, code smell highlighting, copy/paste detection, and the application compatibility from one version of PHP to another for modernization efforts.\n\nMore specifically the Docker image includes:\n\n- phpstan/phpstan\n- squizlabs/php_codesniffer\n- phpcompatibility/php-compatibility\n- phploc/phploc\n- phpmd/phpmd\n- pdepend/pdepend\n- sebastian/phpcpd\n- phpmetrics/phpmetrics\n- phpunit/phpunit\n- friendsofphp/php-cs-fixer\n\nNow available through both Docker Hub and GitHub Container Repository. (see below)\n\n## Usage\n\nNote: This image does nothing when invoking it without a followup command (as shown below in `Some example commands` for each tool), such as:\n\n```\ncd \u003c/path/to/desired/directory\u003e\ndocker run -it --rm -v \"$PWD\":/usr/src/myapp -w /usr/src/myapp \\\nadamculp/php-code-quality:latest \u003cfollowup-command-with-arguments\u003e\n```\n\nAlso, note the example above is for using the Docker Hub repository. Alternatively, you can also use the GitHub Package repository as well by prepending `ghcr.io/` to the image identifier, like the following: (Replacing the placeholders in angle brackets with your values.)\n\n```\ncd \u003c/path/to/your/project\u003e\ndocker run -it --rm -v \"$PWD\":/usr/src/myapp -w /usr/src/myapp \\\n adamculp/php-code-quality:latest \u003cfollowup-command-with-arguments\u003e\n```\n\nWINDOWS USERS: The use of \"$PWD\" for present working directory will not work as expected, instead use \"%cd%\" or the full path. Such as \"//c/Users/adamculp/project\".\n\nIn the example above, Docker runs an interactive terminal to be removed when all is completed, and mounts the current host directory ($PWD) inside the container, sets this as the current working directory, and then loads the image `adamculp/php-code-quality` or `ghcr.io/adamculp/php-code-quality` as the case may be.\n\nFollowing this the user can add any commands to be executed within the container. (such as running the tools provided by the image)\n\nThis is the most common use case, enabling the user to run the tools on everything in and/or below the working directory.\n\nAvailable commands provided by the adamculp/php-code-quality image:\n\n* sh (or any other command) + args\n* php + args\n* composer + args\n* vendor/bin/\u003cchosen-tool-command-below\u003e + args\n\n### Some example commands:\n\nIMPORTANT: If using the commands below \"as-is\", please create a 'php_code_quality' folder within the project first. This will be used, by the commands, to contain the results of the various tools. Modify as desired.\n\nIMPORTANT: If you run into memory issues, where the output states the process ran out of memory, you can alter the amount of memory the PHP process uses for a given command by adding the -d flag to the PHP command. Note that the following example is for extreme cases since the image already sets the memory limit to 512M. (not recommended)\n\n```\nphp -d memory_limit=1G\n```\n\n#### PHPStan\n\nSee [PHPStan Documentation](https://phpstan.org/user-guide/getting-started) for more documentation on use.\n\n```\ndocker run -it --rm --name php-code-quality -v \"$PWD\":/usr/src/myapp -w /usr/src/myapp \\\nadamculp/php-code-quality:latest sh -c 'php /usr/local/lib/php-code-quality/vendor/bin/phpstan \\\n analyse -l 0 --error-format=table \u003e ./php_code_quality/phpstan_results.txt .'\n```\n\n#### PHP Codesniffer (phpcs)\n\nSee [PHP_CodeSniffer Wiki](https://github.com/squizlabs/PHP_CodeSniffer/wiki) for more usage details of this tool. (Note: The following command instructs PHP_CodeSniffer to use the PSR-12 standards, instead of the default PEAR standards. Also, note the . on the end.)\n\n```\ndocker run -it --rm -v \"$PWD\":/usr/src/myapp -w /usr/src/myapp adamculp/php-code-quality:latest \\\nphp /usr/local/lib/php-code-quality/vendor/bin/phpcs -sv --standard=PSR12 \\\n --extensions=php --ignore=vendor --report-file=./php_code_quality/codesniffer_results.txt .\n```\n\n#### PHPCompatibility rules applied to PHP Codesniffer\n\nSee [PHPCompatibility Readme](https://github.com/PHPCompatibility/PHPCompatibility) and [PHP_CodeSniffer Wiki](https://github.com/squizlabs/PHP_CodeSniffer/wiki) above for more usage details of this tool. PHPCompatibility is a collection of sniffs to be used with PHP_CodeSniffer.\n\nNote: The following command is different from others, because it passes 2 PHP commands instead of a single command. This enables loading of the PHPCompatibility sniffs, prior to use.\n\n```\ndocker run -it --rm -v \"$PWD\":/usr/src/myapp -w /usr/src/myapp adamculp/php-code-quality:latest sh -c \\\n'php /usr/local/lib/php-code-quality/vendor/bin/phpcs -sv --config-set installed_paths  /usr/local/lib/php-code-quality/vendor/phpcompatibility/php-compatibility \u0026\u0026 \\\nphp /usr/local/lib/php-code-quality/vendor/bin/phpcs -sv --standard='PHPCompatibility' --extensions=php --ignore=vendor \\\n--report-file=./php_code_quality/phpcompatibility_results.txt .'\n```\n\n#### PHP Lines of Code (PHPLoc)\n\nSee [PHPLOC Readme](https://github.com/sebastianbergmann/phploc) for more usage details of this tool.\n\n```\ndocker run -it --rm -v \"$PWD\":/usr/src/myapp -w /usr/src/myapp adamculp/php-code-quality:latest \\\nphp /usr/local/lib/php-code-quality/vendor/bin/phploc  \\\n--exclude vendor . \u003e ./php_code_quality/phploc.txt\n```\n\n#### PHP Mess Detector (phpmd)\n\nIMPORTANT: Currently experiencing errors using this tool. See this [issue](https://github.com/phpmd/phpmd/issues/919).\n\nSee [PHPMD Readme](https://github.com/phpmd/phpmd) for more usage details of this tool.\n\n```\ndocker run -it --rm -v \"$PWD\":/usr/src/myapp -w /usr/src/myapp adamculp/php-code-quality:latest \\\nphp /usr/local/lib/php-code-quality/vendor/bin/phpmd . xml codesize --exclude 'vendor' \\\n--reportfile './php_code_quality/phpmd_results.xml'\n```\n\n#### PHP Depends (Pdepend)\n\nIMPORTANT: Currently experiencing errors using this tool. See this [issue](https://github.com/phpmd/phpmd/issues/919).\n\nSee [PDepend Docs](https://pdepend.org/) for more usage details of this tool.\n\nNote: I haven't used this for a while, and notice it may require a Tidelift subscription for use.\n\n```\ndocker run -it --rm -v \"$PWD\":/usr/src/myapp -w /usr/src/myapp adamculp/php-code-quality:latest \\\nphp /usr/local/lib/php-code-quality/vendor/bin/pdepend --ignore='vendor' \\\n--summary-xml='./php_code_quality/pdepend_output.xml' \\\n--jdepend-chart='./php_code_quality/pdepend_chart.svg' \\\n--overview-pyramid='./php_code_quality/pdepend_pyramid.svg' .\n```\n\n#### PHP Copy/Paste Detector (phpcpd)\n\nSee [PHPCPD Readme](https://github.com/sebastianbergmann/phpcpd) for more usage details of this tool.\n\n```\ndocker run -it --rm -v \"$PWD\":/usr/src/myapp -w /usr/src/myapp adamculp/php-code-quality:latest \\\nphp /usr/local/lib/php-code-quality/vendor/bin/phpcpd . \\\n--exclude 'vendor' \u003e ./php_code_quality/phpcpd_results.txt\n```\n\n#### PHPMetrics\n\nSee http://www.phpmetrics.org/ for more usage details of this tool.\n\n```\ndocker run -it --rm -v \"$PWD\":/usr/src/myapp -w /usr/src/myapp adamculp/php-code-quality:latest \\\nphp /usr/local/lib/php-code-quality/vendor/bin/phpmetrics --excluded-dirs 'vendor' \\\n--report-html=./php_code_quality/metrics_results .\n```\n\n## Alternative Preparations\n\nRather than allowing Docker to retrieve the image from the Docker Hub or GitHub Container Repositories, users may also build the docker image locally by cloning the image repo from GitHub.\n\nWhy? As an example, a different version of PHP may be desired. Or a specific version of any tools might be required.\n\nAfter cloning, navigate to the location:\n\n```\ngit clone https://github.com/adamculp/php-code-quality.git\ncd php-code-quality\n```\n\nAlter the Dockerfile as desired, then build the image locally: (don't miss the dot at the end)\n\n```\ndocker build -t adamculp/php-code-quality .\n```\n\nOr a user may simply desire the image as-is, and cache for later use:\n\n```\ndocker build -t adamculp/php-code-quality https://github.com/adamculp/php-code-quality.git\n```\n\n## Enjoy!\n\nPlease star, on [Docker Hub](https://hub.docker.com/repository/docker/adamculp/php-code-quality), [GitHub Container Repository](https://github.com/adamculp/php-code-quality/pkgs/container/php-code-quality), or [GitHub](https://github.com/adamculp/php-code-quality), if you find this helpful.\n","funding_links":["https://github.com/sponsors/adamculp","https://github.com/sponsors/beachcasts"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadamculp%2Fphp-code-quality","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadamculp%2Fphp-code-quality","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadamculp%2Fphp-code-quality/lists"}