PHPCheckstyle is an open-source tool that helps PHP programmers adhere to certain coding conventions.

Overview

PHPCheckstyle

Build Status

Overview

PHPCheckstyle is an open-source tool that helps PHP programmers adhere to certain coding conventions. The tools checks the input PHP source code and reports any deviations from the coding convention.

The tool uses the PEAR Coding Standards as the default coding convention. But it allows you to configure it to suit your coding standards.

Please visit https://github.com/PHPCheckstyle/phpcheckstyle/wiki for more information and documentation

Requirements

  • PHP 5.0 or newer.
  • Web browser to view the checkstyle report (only for html view)
  • That's all.

Installation

Installation with Composer

composer require phpcheckstyle/phpcheckstyle

or Add phpcheckstyle/phpcheckstyle as a requirement to composer.json:

{
    "require": {
        "phpcheckstyle/phpcheckstyle": "dev-master"
    }
}

Update your packages with composer update or if installing from fresh, with composer install.

Manual Installation

Just download https://github.com/PHPCheckstyle/phpcheckstyle/archive/master.zip and unzip the distribution.

$> unzip PhpCheckstyle.zip

This will create a directory called phpcheckstyle and expand all files in it.

Testing with Vagrant

  • install VirtualBox

  • install Vagrant

  • launch vagrant up in the project root directory to start the VM

  • In case of problem with the "guest additions", launch :

vagrant plugin install vagrant-vbguest

  • to run PHPCheckstyle on itself, type vagrant provision --provision-with run_phpcheckstyle
  • to run PHPUnit, type vagrant provision --provision-with run_phpunit
  • to log inside the VM, type vagrant ssh

Usage

  • Change directory to the PHPCheckstyle installation directory.

    $> cd phpcheckstyle
  • Execute the run.php script providing the --src option.

    $> php run.php --src <php source directory/file>
  • Use the --help option to see more options

    $> php run.php --help

License

See LICENSE

Comments
  • Question: join forces

    Question: join forces

    Hi! Your project is similar to our - check code style. We, on the other hand, also fix it in place! What about joining forces and work together on https://github.com/FriendsOfPHP/PHP-CS-Fixer ?

    opened by keradus 13
  • Magic methods being picked up by function regex pattern

    Magic methods being picked up by function regex pattern

    This issue is being raised on __construct:

    Function __construct name should follow the pattern /^[a-z_][a-zA-Z0-9]$/.
    

    The __construct method and any other magic methods should be exempt from this. Do you agree @tchule?

    bug 
    opened by jbrooksuk 11
  • Cannot define idependent rules for function parameter namings and local variable namings

    Cannot define idependent rules for function parameter namings and local variable namings

    I am trying to integrate phpcheckstyle, sadly I could not find a way to separate two cases:

    • function parameter (variable) naming
    • local variable naming

    We would like to use different namings for local vars and different namings for parameter namings. In JS and Java checkstyles this is handled independently, since they are also independent levels of definition. Is there a way to solve it in phpcheckstyle?

    opened by dpalic 5
  • [Question] Encapsed variable + Single quote preference

    [Question] Encapsed variable + Single quote preference

    I would like to make sure that single quotes are preferred but allow the use of double quotes for encapsed variables. Is there a way to allow such a configuration?

    opened by popojargo 5
  • Composer and

    Composer and "secure-http"

    Command

    composer require phpcheckstyle/phpcheckstyle
    

    Error

    You are running composer with xdebug enabled. This has a major impact on runtime
     performance. See https://getcomposer.org/xdebug
    Using version ^0.14.3 for phpcheckstyle/phpcheckstyle
    ./composer.json has been updated
    Loading composer repositories with package information
    Updating dependencies (including require-dev)
      - Installing phpcheckstyle/phpcheckstyle (V0.14.3)
        Checking out /tags/V0.14.3/@331
    
    Installation failed, reverting ./composer.json to its original content.
    
    
      [RuntimeException]
      Package could not be downloaded, Your configuration does not allow connecti
      ons to http://svn.code.sf.net/p/phpcheckstyle/code//tags/V0.14.3/@331. See
      https://getcomposer.org/doc/06-config.md#secure-http for details.
    

    Composers "secure-http" default value is true. That's why only HTTPS URLs are allowed to be downloaded via Composer. https://getcomposer.org/doc/06-config.md#secure-http

    How to fix this error without changing the default composer settings?

    opened by odan 5
  • PHPCheckstyle is timing out on itself

    PHPCheckstyle is timing out on itself

    If you run PHPCheckstyle against the actual PHPCheckstyle.php file itself, it crashes. I don't know if this is related to a memory bug or something, but it's unable to process itself.

    bug 
    opened by jbrooksuk 5
  • False error

    False error "The function parameters must match those in its docblock @param" when using local variable tag

    Hi,

    I've been successfully using phpcheckstyle. Thank you for the great work. I noticed today the following: if you tag a local variable with a type, then the whole function reports incorrect parameters. Let me give you an example: The code below will show: The function test parameters must match those in its docblock @param.

    <?php
    class Example
    {
        /**
        * @param string $param1
        * @param string $param2
        * @return void 
        **/
        public function test($param1, $param2)
        {
            /** @var SomeClass | null */
            $someObject = null;
        }
    }
    

    To resolve the error, I must remove the tag from the local variable. This will pass:

    <?php
    class Example
    {
        /**
        * @param string $param1
        * @param string $param2
        * @return void 
        **/
        public function test($param1, $param2)
        {
            $someObject = null;
        }
    }
    

    It looks as if somehow the @var tag is added to the list of parameters already defined by the function ($param1, $param2). As a consequence, the linter reports a mismatch. I need the initial tag, so how could I work around this issue? Any thoughts?

    opened by profidocs 4
  • Avoid confusion with the Sourceforge repository

    Avoid confusion with the Sourceforge repository

    Hi,

    AFAIU the main repository for PHPCheckstyle is the one on sourceforge: https://sourceforge.net/projects/phpcheckstyle/

    This is not immediately clear from the github page, and the user may end up fetching some outdated code with git, at least compared with the code fetched by composer.

    Can you please try to improve this situation?

    Thanks.

    opened by ao2 4
  • Autoloader problem when not using Composer

    Autoloader problem when not using Composer

    See : https://code.google.com/p/phpcheckstyle/issues/detail?id=89

    We have added the vendor directory in .gitignore. We need to find a way to be compatible for people who use the project directly through GitHub and COmposer and for the people who download the source to use locally without Composer.

    enhancement 
    opened by tchule 4
  • Grouped cases must contain a break

    Grouped cases must contain a break

    When a select or switch has multiple cases that join together:

    case T_COMMENT:
    case T_ML_COMMENT:
    case T_DOC_COMMENT:
        $this->_processComment($token);
        break;
    

    The The case statement must contain a break. warning is being returned. We need to add a check on the case token that it's not immediately followed by another case.

    bug 
    opened by jbrooksuk 4
  • Use Bootstrap4 for styling

    Use Bootstrap4 for styling

    Hey guys!

    Big fan of your codestyle-checker. Only thing is that it is quite hard in big projects to distinguish between "info" and "error" by scrolling through the tables. I did some quickfix for me and included bootstrap into your project which is quite nice for the eyes:

    screenshot_1

    opened by HCrane 3
  • --exclude is being ignored

    --exclude is being ignored

    I'm setting up a test environment for my upcoming project (in CodeIgniter4, if it's relevant) and stumbled upon this weird behavior. I execute the following (in my CI4 project folder):

    php /path/to/run.php --config /path/to/my.cfg.xml --src app/Views/ --exclude app/Views/welcome_message.php

    But the excluded file is still parsed: image

    If I exclude the relative path portion of the exclusion, it does skip the file (but I assume it would also exclude other unintended files):

    php /path/to/run.php --config /path/to/my.cfg.xml --src app/Views/ --exclude welcome_message.php

    After searching the reported issues, I thought it could have something to do with Issue 78, so I tried executing from the installation directory:

    php run.php --config /path/to/my.cfg.xml --src /full/path/to/app/Views/ --exclude /full/path/to/app/Views/welcome_message.php

    And it still fails to exclude the indicated file.

    Tested in:

    • Version 0.14.8
    • Commit b16777125e2023efbf47e5576cda32443091a9fd

    With PHP 8.0.25. Manual installation.

    opened by roflo1 3
  • Could not open input file: vendor/bin/run.php

    Could not open input file: vendor/bin/run.php

    Installed with

    composer require phpcheckstyle/phpcheckstyle --dev
    

    Installed version V0.14.7

    Running vendor/bin/phpcheckstyle or vendor/bin/phpcheckstyle -h

    Recieved: Could not open input file: vendor/bin/run.php

    Changed version to dev-master - using commit 12794c040998979c8720ae80bfd29ddf7a88b566

    Same error

    opened by lsv 4
  • [Feature request] Bracket position for closure

    [Feature request] Bracket position for closure

    Hi! I am using "new line" open curly brace position in my code. But in closure need position in same line.

    $response->setCallback(function () use($path) {
        readfile($path);
    });
    
    opened by Slavenin 1
  • Run the run.php script from within any directory

    Run the run.php script from within any directory

    First of all: big thanks for this awesome tool!

    Trying it out however, I have run into a small problem with using relative paths. Running the following line:

    php /composer/vendor/phpcheckstyle/phpcheckstyle/run.php --src "./src"
    

    I receive the error

    Fatal error: Uncaught Error: Class 'PHPCheckstyle\PHPCheckstyle' not found in /composer/vendor/phpcheckstyle/phpcheckstyle/run.php:172
    Stack trace:
    #0 {main}
      thrown in /composer/vendor/phpcheckstyle/phpcheckstyle/run.php on line 172
    

    Trying to load the /composer/vendor/autoload.php solves this, but it will still complain about not finding the default config file, as it is defined relatively to the location the script is run from, not relatively to the script itself.

    This dependency on the location where php is run from is found on other lines as well:

    Is there some way to update run.php to make the script run from anywhere? Or even make it possible to run it as a binary in /composer/vendor/bin (which might take advantage from these same changes)? Honestly, I'm not really sure if these would be the only changes needed to being able to run the above line, as --src "./src" is still using a relative path to the location the script has been called from...

    Thanks for looking into this. I would be glad to help to provide further details if needed.

    opened by MetalArend 20
A tool to automatically fix PHP Coding Standards issues by Dragon Code.

A tool to automatically fix PHP Coding Standards issues by Dragon Code.

The Dragon Code 24 Aug 27, 2022
Deptrac is a static code analysis tool for PHP that helps you communicate, visualize and enforce architectural decisions in your projects

Deptrac is a static code analysis tool for PHP that helps you communicate, visualize and enforce architectural decisions in your projects. You can freely define your architectural layers over classes and which rules should apply to them.

QOSSMIC GmbH 2.2k Dec 30, 2022
PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.

About PHP_CodeSniffer is a set of two PHP scripts; the main phpcs script that tokenizes PHP, JavaScript and CSS files to detect violations of a define

Squiz Labs 9.9k Jan 4, 2023
Slevomat Coding Standard for PHP_CodeSniffer provides many useful sniffs

Slevomat Coding Standard Slevomat Coding Standard for PHP_CodeSniffer provides sniffs that fall into three categories: Functional - improving the safe

Slevomat 1.2k Jan 5, 2023
Provides functionality that helps writing PHP code that has runtime-specific (PHP / HHVM) execution paths

sebastian/environment This component provides functionality that helps writing PHP code that has runtime-specific (PHP / HHVM) execution paths. Instal

Sebastian Bergmann 6.5k Jan 3, 2023
PHPMD is a spin-off project of PHP Depend and aims to be a PHP equivalent of the well known Java tool PMD. PHPMD can be seen as an user friendly frontend application for the raw metrics stream measured by PHP Depend.

PHPMD PHPMD is a spin-off project of PHP Depend and aims to be a PHP equivalent of the well known Java tool PMD. PHPMD can be seen as an user friendly

PHP Mess Detector 2.1k Jan 8, 2023
PHP Architecture Tester - Easy to use architectural testing tool for PHP :heavy_check_mark:

Easy to use architecture testing tool for PHP Introduction ?? PHP Architecture Tester is a static analysis tool to verify architectural requirements.

Carlos A Sastre 765 Dec 30, 2022
PHP Static Analysis Tool - discover bugs in your code without running it!

PHPStan - PHP Static Analysis Tool PHPStan focuses on finding errors in your code without actually running it. It catches whole classes of bugs even b

PHPStan 11.6k Dec 30, 2022
A PHP code-quality tool

GrumPHP Sick and tired of defending code quality over and over again? GrumPHP will do it for you! This composer plugin will register some git hooks in

PHPro 3.9k Jan 1, 2023
Beautiful and understandable static analysis tool for PHP

PhpMetrics PhpMetrics provides metrics about PHP project and classes, with beautiful and readable HTML report. Documentation | Twitter | Contributing

PhpMetrics 2.3k Dec 22, 2022
A tool for quickly measuring the size of a PHP project.

PHPLOC phploc is a tool for quickly measuring the size and analyzing the structure of a PHP project. Installation This tool is distributed as a PHP Ar

Sebastian Bergmann 2.3k Jan 4, 2023
A command line refactoring tool for PHP

PHP Refactoring Browser Note: This software is under development and in alpha state. Refactorings do not contain all necessary pre-conditions and migh

QafooLabs 562 Dec 30, 2022
A static php code analysis tool using the Graph Theory

Mondrian Ok guyz, you have a master degree in Graph Theory, you follow Law of Demeter and you live on S.O.L.I.D principles ? Let's have some Fun ! (^ω

Florent Genette 391 Nov 30, 2022
PHP completion, refactoring, introspection tool and language server.

Phpactor This project aims to provide heavy-lifting refactoring and introspection tools which can be used standalone or as the backend for a text edit

Phpactor 882 Jan 1, 2023
A static analysis tool for finding errors in PHP applications

Psalm Psalm is a static analysis tool for finding errors in PHP applications. Installation To get started, check out the installation guide. Live Demo

Vimeo 5k Jan 2, 2023
A web tool to explore the ASTs generated by PHP-Parser.

phpast.com A web tool to explore the ASTs generated by PHP-Parser. About This web tool provides a GUI for exploring the AST of your PHP code. You can

Ryan Chandler 23 Nov 29, 2022
Search PHP source code for function & method calls, variables, and more from PHP.

Searching PHP source code made easy Search PHP source code for function & method calls, variable assignments, classes and more directly from PHP. Inst

Permafrost Software 22 Nov 24, 2022
Tool helping us to analyze software projects

Qafoo Quality Analyzer This software is a tool to visualize metrics and source code. We use this software for Code Reviews together with our customers

Qafoo GmbH 494 Dec 29, 2022
Baseline tool for PHP_CodeSniffer

PHP_CodeSniffer Baseliner This tool enables you to integrate PHP_CodeSniffer into an existing project by automatically adding phpcs:ignore and phpcs:d

ISAAC 13 Nov 26, 2022