Coder Social home page Coder Social logo

danielantelo / php-project-tools Goto Github PK

View Code? Open in Web Editor NEW
5.0 3.0 2.0 30 KB

Composer based project tools to automate the following: - Check php files for syntax errors - Check php files for PSR Coding Standads - Check php files for possible bugs, unused parameters, suboptimal code, etc. - Ensure all project tests are being passed

PHP 99.35% JavaScript 0.25% CSS 0.40%

php-project-tools's Introduction

Php Project Tools

Composer based project tools to automate the following:

  • Check php files for syntax errors
  • Check php files for PSR Coding Standads
  • Check php files for possible bugs, unused parameters, suboptimal code, etc.
  • Ensure all project tests are being passed
  • Lint assets (js, css, etc)

INSTALLATION:

Simply add daa/project-tools as a composer dependency.

# composer.json

    "require-dev": {
        ...
        "daa/project-tools": "~1.0"
    }

USAGE:

If you are using git for your project use the scripts provided to configure the automate checks.

# composer.json

    "scripts": {
        "post-update-cmd": "Project\\Script\\GitHooks::setup",
        "post-install-cmd": "Project\\Script\\GitHooks::setup"
    }

After a composer update --dev, when ever you carry out a git commit, it will ensure there are no errors, coding standard issues or failing tests before processing the commit.

Note: May not work in some IDEs (eg. git hooks are ignored in Netbeans). I tend to use the command line.

You can configure the the pre-commit rules by modifying the $conf array in .git/hooks/pre-commit, the defaults are:

$conf = array(
    'excludeTests' => false,
    'codingStandard' => 'PSR2',
    'messRules' => 'controversial',
    ''
);

and advanced configuration can be:

$conf = array(
    'excludeTests' => true,
    'codingStandard' => array('PSR2', 'symfony2'),
    'messRules' => array('controversial', 'codesize', 'unusedcode'),
    'customChecks' => array(
        array('cmd' => 'scss-lint', 'ext' => 'css'),
        array('cmd' => 'jscs --preset=jquery', 'ext' => 'js')
    )
);

As you can see, in this example we hve added linters for our assets, but these extra checks could be anything.

ALTERNATIVE USE:

If you are not using git or don't want the checks to be automated hooks, you can use the tools manually.

use Project\Tool\CodeQualityTool;

// check an entire composer project
$tool = new CodeQualityTool();
$tool->run();

// check an entire composer project but without executing tests
$tool = new CodeQualityTool();
$tool->excludeTests();
$tool->run();

// check a set of files
$files = array('file1.php', 'file2.php');
$tool = new CodeQualityTool($files);
$tool->run();

// check a set of files without executing tests
$files = array('file1.php', 'file2.php');
$tool = new CodeQualityTool($files, true);
$tool->run();

You can also use individual modules

use Project\Tool\Checker\SyntaxErrorChecker;
use Project\Tool\Checker\CodingStandardsChecker;

// example of how to use a checker to check whole project
$checker = new SyntaxErrorChecker($projectDir);
if (!$checker->check()) {
    throw new \Exception('There are syntax errors!');
}

// example of how to use a checker to check a set of files
$files = array('file1.php', 'file2.php');
$checker = new SyntaxErrorChecker($projectDir);
if (!$checker->check($files)) {
    throw new \Exception('There are syntax errors!');
}

Have a look at Hooks/git/pre-commit and Tools/CodeQualityTool.php for more usage information.

php-project-tools's People

Contributors

danielantelo avatar mickaelandrieu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.