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
Coding-standard - Magento PHP CodeSniffer Coding Standard

ECG Magento Code Sniffer Coding Standard ECG Magento Code Sniffer Coding Standard is a set of rules and sniffs for PHP_CodeSniffer tool. It allows aut

Magento ECG 309 Jan 3, 2023
Documentation on clean coding and demonstration of studied clean coding principals with PHP.

practice-php-clean-code Documentation on clean coding and demonstration of studied clean coding principals with PHP. The document contained in this re

Ferdous Islam 1 Feb 21, 2022
Free Functions To Connect To The Database ( Mysql ) For Php Programmers

Update ?? The biggest update ever DB-php Free Functions To Connect To The Database ( Mysql ) For Php Programmers This Version : 2.0 connect to databas

Ali 3 May 27, 2022
For beginner programmers, a list of exercises.

Hacktoberfest 2021 Junte-se ao Hacktoberfest - Aqui! Support open source throughout October! Hacktoberfest incentiva a participação na comunidade de c

Igor Gomes 5 Oct 18, 2022
A tool to automatically fix PHP Coding Standards issues

PHP Coding Standards Fixer The PHP Coding Standards Fixer (PHP CS Fixer) tool fixes your code to follow standards; whether you want to follow PHP codi

null 11.6k Jan 1, 2023
A tool to automatically fix Twig Coding Standards issues

Twig CS Fixer Installation This standard can be installed with the Composer dependency manager. Add the coding standard as a dependency of your projec

Vincent Langlet 50 Jan 6, 2023
Orangescrum is a simple yet powerful free and open source project management software that helps team to organize their tasks, projects and deliver more.

Free, open source Project Management software Introduction Orangescrum is the simple yet powerful free and open source project management software tha

Orangescrum 110 Dec 30, 2022
This car rental project system project in PHP focuses mainly on dealing with customers regarding their car rental hours and certain transactions.

Car-Rental Online Car Rental Management System This car rental project system project in PHP focuses mainly on dealing with customers regarding their

Adarsh Kumar Singh 2 Sep 29, 2022
A PocketMine-MP plugin that replaces a block to another block when breaks, then back to the original block after a certain time

BlockReplacer A PocketMine-MP plugin that replaces a block to another block when breaks, then back to the original block after a certain time How to I

AIPTU 11 Sep 2, 2022
A PocketMine-MP plugin to regulate player hunger and prohibit eating certain foods easily

NoEats A PocketMine-MP plugin to regulate player hunger and prohibit eating certain foods easily. Features Managing hunger. Permission bypass. Support

null 2 Jan 16, 2022
This Plugin runs commands when a player does a certain emote

The EmoteCommands Plugin This Plugin runs commands when a player does a certain emote You will need a pocketmine server of at least version 4.0.0 Usag

DiamondStrider1 1 Jan 24, 2022
Prevent players from passing a certain point in your server worlds

WorldBorder Info ~ Prevent players from passing a certain point in your server worlds! Stops glitchers trying to get past the border locking them in a

Hydro 1 Mar 27, 2022
This package implements 0-1 Knapsack Problem algorithm i.e. allows to find the best way to fill a knapsack of a specified volume with items of a certain volume and value.

This package implements "0-1 Knapsack Problem" algorithm i.e. allows to find the best way to fill a knapsack of a specified volume with items of a certain volume and value.

Alexander Makarov 9 Sep 8, 2022
An open source tool that lets you create a SaaS website from docker images in 10 minutes.

简体中文 Screenshots for members ( who subscribe the plan ) for admin ⚠️ This document was translated into English by deepl and can be improved by PR An o

Easy 669 Jan 5, 2023
QaraTMS is open source test case, test suites, test plans and test runs management tool.

QaraTMS - Open Source Test Management System QaraTMS is open source test management software for managing test suites, test cases, test plans, test ru

Alex H 29 Dec 22, 2022
Fsociety RAT, The Open Source C++ Remote Administration Tool (RAT)

Fsociety-RAT It was really fun to make this project! This project have a lot of great features and a very good website control for the bots. The final

Elliot Alderson 11 Nov 30, 2022
Drall - a tool to that helps run drush commands on multi-site Drupal installations

Drall Drall is a tool to that helps run drush commands on multi-site Drupal installations. One command to drush them all. — Jigarius A big thanks and

Jigar Mehta 23 Nov 25, 2022
Ideation Tool helps with the collection, enrichment, rating, and prioritization of ideas.

About Ideation Tool Ideation Tool helps with the collection, enrichment, rating, and prioritization of ideas. We believe having access to simple to us

Innovategy Oy 3 Jun 15, 2022
PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.

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 defined coding standard, and a second phpcbf script to automatically correct coding standard violations. PHP_CodeSniffer is an essential development tool that ensures your code remains clean and consistent.

Squiz Labs 9.9k Jan 5, 2023