Analyze PHP code with one command

Related tags

Code Analysis phpqa
Overview

PHPQA

Analyze PHP code with one command.

License Latest Stable Version Total Downloads Build Status Windows status

Requirements

Why?

Every analyzer has different arguments and options in different formats (no surprise in PHP world :). If you ever tried to get ignoring directories to work then you know what I mean. On the other hand CLI tools are cool because you can analyze any directory or file. Unfortunately Jenkins, Travis, Scrutiziner needs special configuration file. What if you want to analyze every bundle in your Symfony app? Will you create e.g. Jenkins project/task for each bundle?

  • I want to analyze selected directory without complex configuration and creating extra files/tasks
  • I don't care about format of ignored directories in phploc, phpmd, ...
  • I don't want to update all projects when QA tool is updated or if I've found cool tool like PHPMetrics
  • I don't want to analyze XML files → tool should be able to build html reports
  • I want fast execution time → tools should run in parallel (thanks Robo)

Available tools

Tool Description
phploc Measure the size of a PHP project
phpcpd Copy/Paste Detector (CPD) for PHP code
phpcs Detect violations of a coding standard
pdepend PHP adaptation of JDepend
phpmd Scan PHP project for messy code
phpmetrics Static analysis tool for PHP
Suggested tools

Newly added tools aren't preinstalled. You have to install relevant composer packages if you want to use them.

Tool PHP Supported since Description
security-checker >= 5.6 1.24 Check composer.lock for known security issues
php-cs-fixer >= 5.3 1.12 Automatically detect and fix PHP coding standards issues
phpunit >= 5.3 1.13 The PHP Unit Testing framework
phpstan >= 7.0 1.9 Discover bugs in your code without running it
psalm >= 5.6 1.14 A static analysis tool for finding errors in PHP applications
parallel-lint >= 5.4 1.9 Check syntax of PHP files
MacFJA/phpqa-extensions - - PHP Assumptions, Magic Number Detector, ...

Tip: use bin/suggested-tools.sh install for installing the tools.

Install

Clone + composer

# install phpqa
git clone https://github.com/EdgedesignCZ/phpqa.git && cd phpqa && composer install --no-dev

# make phpqa globally accessible
## you can symlink binary
sudo ln -s /path-to-phpqa-repository/phpqa /usr/bin/phpqa
## or add this directory to your PATH in your ~/.bash_profile (or ~/.bashrc)
export PATH=~/path-to-phpqa-repository-from-pwd:$PATH

Composer

# global installation
composer global require edgedesign/phpqa --update-no-dev
# Make sure you have ~/.composer/vendor/bin/ in your PATH.

# local installation
composer require edgedesign/phpqa --dev

Of course you can add dependency to require-dev section in your composer.json. But I wouldn't recommend it. In my experience one QA tool which analyzes N projects is better than N projects with N analyzers. It's up to you how many repositories you want to update when new version is released.

Symfony3 components

Symfony3 is supported since version 1.7. Install at least version ~3.0 of sebastian/phpcpd, otherwise you'll get error The helper "progress" is not defined.

{
    "require-dev": {
        "edgedesign/phpqa": ">=1.7",
        "sebastian/phpcpd": "~3.0"
    }
}
Fake global installation in local project

Do you have problems with dependencies and you can't install phpqa globally? Install phpqa in subdirectory.

#!/bin/sh

if [ ! -f qa/phpqa ];
then
    echo "installing phpqa"
    (git clone https://github.com/EdgedesignCZ/phpqa.git ./qa  && cd qa && composer install --no-dev)
fi

qa/phpqa

Docker

Official docker image repository is https://hub.docker.com/r/zdenekdrahos/phpqa/. Images can be used at Gitlab CI.

docker run --rm -it zdenekdrahos/phpqa:v1.24.0-php7.2 phpqa tools
# using a tool without phpqa
docker run --rm -it zdenekdrahos/phpqa:v1.24.0-php7.2 phploc -v
Image PHP version Composer version Tools versions
zdenekdrahos/phpqa:v1.24.0-php7.2 7.2 1.8.0 Versions that supports symfony2 components from default composer.lock. Not latest versions.
zdenekdrahos/phpqa:v1.24.0-php7.4 7.4 2.0.7 Generally, latest versions available at the moment. If you need different versions, then build custom docker image

Beware that images as lean as possible. That can be a problem for running PHPUnit tests. In that case, you might need different PHP version, miss PHP extensions for database etc. You can install phpqa in another php image Or build custom docker image.

docker run --rm -it zdenekdrahos/phpqa:v1.24.0-php7.2 sh -c "php --version && composer --version && composer outdated --direct --all && phpqa tools"
docker run --rm -it zdenekdrahos/phpqa:v1.24.0-php7.4 sh -c "php --version && composer --version && composer outdated --direct --all && phpqa tools"

There are also available images eko3alpha/docker-phpqa and sparkfabrik/docker-phpqa. phpqa is used as an entrypoint (I haven't been able to use these images at Gitlab CI + Windows probably needs different environment variable).

docker run --rm -u $UID -v $PWD:/app eko3alpha/docker-phpqa --report --ignoredDirs vendor,build,migrations,test

Analyze

Command Description
phpqa --help Show help - available options, tools, default values, ...
phpqa --analyzedDirs ./ --buildDir ./build Analyze current directory and save output to build directory
phpqa --analyzedDirs src,tests Analyze source and test directory (phpmetrics analyzes only src)
phpqa --analyzedDir ./ Deprecated in v1.8 in favor of --analyzedDirs
phpqa --ignoredDirs build,vendor Ignore directories
phpqa --ignoredFiles RoboFile.php Ignore files
phpqa --tools phploc,phpcs Run only selected tools
phpqa --tools phpmd:1,phpcs:0,phpcpd:0 Check number of errors and exit code. New in v1.6
phpqa --verbose Show output from executed tools
phpqa --quiet Show no output at all
phpqa --output cli CLI output instead of creating files in --buildDir
phpqa --execution no-parallel Don't use parallelism if --execution != parallel
phpqa --config ./my-config Use custom configuration
phpqa --report Build html reports
phpqa --report offline Build html reports with bundled assets. New in v1.16
phpqa tools Show versions of available tools

Tip: CLI options can be defined in .phpqa.yml

Output modes

Tool --output file (default) - generated files --output cli
phploc phploc.xml
phpcpd phpcpd.xml
phpcs checkstyle.xml full report
pdepend pdepend-jdepend.xml, pdepend-summary.xml, pdepend-dependencies.xml, pdepend-jdepend.svg, pdepend-pyramid.svg
phpmd phpmd.xml
phpmetrics phpmetrics.html (v1), phpmetrics/index.html (v2), phpmetrics.xml
php-cs-fixer php-cs-fixer.html
parallel-lint parallel-lint.html
phpstan phpstan.html, phpstan-phpqa.neon , phpstan-phpqa.neon
psalm psalm.html, psalm.xml, psalm-phpqa.xml , psalm-phpqa.xml

Exit code

phpqa can return non-zero exit code since version 1.6. It's optional feature that is by default turned off. You have to define number of allowed errors for phpcpd, phpcs, phpmd in --tools.

mode Supported version What is analyzed?
--output file >= 1.6 Number of errors in XML files, or exit code for tools without XML
--output cli >= 1.9 Exit code

Let's say your Travis CI or Circle CI build should fail when new error is introduced. Define number of allowed errors for each tools and watch the build:

phpqa --report --tools phpcs:0,phpmd:0,phpcpd:0,parallel-lint:0,phpstan:0,phpmetrics,phploc,pdepend

Number of allowed errors can be also defined in .phpqa.yml.

phpqa:
    # can be overriden by CLI: phpqa --tools phpcs:1
    tools:
        - phpcs:0

File mode

screenshot from 2016-07-23 13 53 34

Tip: override phpcs.ignoreWarnings if you want to count just errors without phpcs warnings.

CLI mode

screenshot from 2016-12-21 14 31 27

Tip: use echo $? for displaying exit code.

Advanced configuration - .phpqa.yml

Provide CLI options from .phpqa.yml:

CLI option .phpqa.yml
phpqa --analyzedDirs ./ phpqa.analyzedDirs: ./
phpqa --buildDir ./build phpqa.buildDir: ./build
phpqa --ignoredDirs build,vendor phpqa.ignoredDirs: build,vendor
phpqa --ignoredFiles RoboFile.php phpqa.ignoredFiles: RoboFile.php
phpqa --tools phploc,phpcs:0 phpqa.tools: phploc,phpcs:0
phpqa --report phpqa.report: true
phpqa --execution no-parallel phpqa.execution: no-parallel
phpqa --output cli phpqa.output: cli
phpqa --verbose phpqa.verbose: true

Override tools' settings with .phpqa.yml:

Tool Settings Default Value Your value
phpqa.extensions PHP File extensions php Name of php file to parse, you can specify it like a string php,inc,modules or like a yaml array.
phpcs.standard Coding standard PSR2 Name of existing standard (PEAR, PHPCS, PSR1, PSR2, Squiz, Zend), or path to your coding standard. To specify multiple standards, you can use an array
phpcs.ignoreWarnings If number of allowed errors is compared with warnings+errors, or just errors from checkstyle.xml false Boolean value
phpcs.reports Report types full report in cli mode, checkstyle in file mode Predefined report types or custom reports
php-cs-fixer.rules Coding standard rules @PSR2 String value
php-cs-fixer.allowRiskyRules Whether risky rules may run false Boolean value
php-cs-fixer.config Load configuration from file null Path to .phpcs file
php-cs-fixer.isDryRun If code is just analyzed or fixers are applied true Boolean value
phpmetrics.config Configuration for phpmetrics v1 null Path to .phpmetrics.yml file
phpmetrics.git phpmetrics v2 analyses based on Git History null Boolean value or path to git binary
phpmetrics.junit phpmetrics v2 evaluates metrics according to JUnit logs null Path to JUnit xml
phpmetrics.composer phpmetrics v2 analyzes composer dependencies null Path to composer.json when the file is not included in analyzedDirs
pdepend.coverageReport Load Clover style CodeCoverage report null Path to report produced by PHPUnit's --coverage-clover option
phpmd.standard Ruleset Edgedesign's standard Path to ruleset. To specify multiple rule sets, you can use an array
phpcpd Minimum number of lines/tokens for copy-paste detection 5 lines, 70 tokens
phpstan Level, config file, memory limit Level 0, %currentWorkingDirectory%/phpstan.neon, memoryLimit: null Take a look at phpqa config in tests/.ci
phpunit.binary Phpunit binary phpqa's phpunit Path to phpunit executable in your project, typically vendor/bin/phpunit
phpunit.config PHPUnit configuration, analyzedDirs and ignoredDirs are not used, you have to specify test suites in XML file null Path to phpunit.xml file
phpunit.reports Report types no report List of reports and formats, corresponds with CLI option, e.g. --log-junit is log: [junit] in .phpqa.yml
psalm.config Psalm configuration, analyzedDirs and ignoredDirs are appended to projectFiles Predefined config Path to psalm.xml file
psalm.deadCode Enable or not --find-dead-code option of psalm false Boolean value
psalm.threads Set the number of process to use in parallel (option --threads of psalm) (Only if --execution == parallel for phpqa) 1 Number (>= 1)
psalm.showInfo Display or not information (non-error) messages (option --show-info= of psalm) true Boolean value
psalm.memoryLimit Custom memory limit, ignore unless you are getting Fatal error: Allowed memory size of ... bytes exhausted null String value, e.g. '1024M', '1G'

.phpqa.yml is automatically detected in current working directory, but you can specify directory via option:

# use .phpqa.yml from defined directory
phpqa --config path-to-directory-with-config

You don't have to specify full configuration. Missing or empty values are replaced with default values from our .phpqa.yml. Example of minimal config that defines only standard for CodeSniffer:

phpcs:
    standard: Zend

Tip: use PHP Coding Standard Generator for generating phpcs/phpmd standards.

You can specify multiple configurations directory (separated by ,). They are loaded in the order they are defined. This can be useful if you have a common configuration file that you want to use across multiple project but you still want to have per project configuration. Also, path inside configuration file are relative to where the configuration file is, so if you have a package that bundle a custom tool, the .phpqa.yml in the package can refers files within it.

phpqa --config ~/phpqa/,my-config/,$(pwd)

HTML reports

If you don't have Jenkins or other CI server, then you can use HTML reports. HTML files are built when you add option --report. Take a look at report from phpqa.

# build html reports
phpqa --report

Custom templates

Define custom templates if you don't like default templates. You have to define path to xsl files in your .phpqa.yml:

# use different template for PHPMD, use default for other tools
report:
    phpmd: my-templates/phpmd.xsl

Be aware that all paths are relative to .phpqa.yml. Don't copy-paste section report if you don't have custom templates!

Requirements

xsl extension must be installed and enabled for exporting HTML reports. Otherwise you'll get error PHP Fatal error: Class 'XSLTProcessor' not found.

# install xsl extension in Ubuntu
sudo apt-get update
sudo apt-get install php5-xsl
sudo service apache2 restart

Continuous integration

We use Jenkins-CI in Edgedesign. Below you can find examples of Phing, Robo and bash tasks.

Project with one directory

Typically in Symfony project you have project with src directory with all the code and tests. So you don't need ignore vendors, web directory etc.

Phing - build.xml

<target name="ci-phpqa">
    <exec executable="phpqa" passthru="true">
        <arg value="--analyzedDirs=./src" />
        <arg value="--buildDir=./build/logs" />
        <arg value="--report" />
    </exec>
</target>

Robo - RoboFile.php

public function ciPhpqa()
{
    $this->taskExec('phpqa')
        ->option('analyzedDirs', './src')
        ->option('buildDir', './build/logs')
        ->option('report')
        ->run();
}

Project with multiple directories (src, tests, ...)

When you analyze root directory of your project don't forget to ignore vendors and other non-code directories. Otherwise the analysis could take a very long time.

Since version 1.8 phpqa supports analyzing multiple directories. Except phpmetrics that analyzes only first directory. Analyze root directory and ignore other directories if you rely on phpmetrics report.

Phing - build.xml

<target name="ci-phpqa">
    <exec executable="phpqa" passthru="true">
        <arg value="--analyzedDirs=./" />
        <arg value="--buildDir=./build/logs" />
        <arg value="--ignoredDirs=app,bin,build,vendor,web" />
        <arg value="--ignoredFiles= " />
        <arg value="--verbose" />
        <arg value="--report" />
    </exec>
</target>

Robo - RoboFile.php

public function ciPhpqa()
{
    $this->taskExec('phpqa')
        ->option('verbose')
        ->option('report')
        ->option('analyzedDirs', './')
        ->option('buildDir', './build')
        ->option('ignoredDirs', 'build,bin,vendor')
        ->option('ignoredFiles', 'RoboFile.php,error-handling.php')
        ->run();
}

Bash

phpqa --verbose --report --analyzedDirs ./ --buildDir ./var/CI --ignoredDirs=bin,log,temp,var,vendor,www

Circle.ci - artifacts + global installation

machine:
    php:
        version: 7.0.4

dependencies:
    cache_directories:
        - ~/.composer/cache
    post:
        - 'git clone https://github.com/EdgedesignCZ/phpqa.git ./qa && cd qa && composer install --no-dev'

test:
    override:
        - vendor/bin/phpunit --testdox-html ./var/tests/testdox.html --testdox-text ./var/tests/testdox.txt --log-junit $CIRCLE_TEST_REPORTS/phpunit/junit.xml
        - qa/phpqa --report --verbose --buildDir var/QA --ignoredDirs vendor --tools=phpcs:0,phpmd:0,phpcpd:0,phploc,pdepend,phpmetrics
    post:
        - cp -r ./var/QA $CIRCLE_ARTIFACTS
        - cp -r ./var/tests $CIRCLE_ARTIFACTS

Gitlab.ci - docker installation + composer cache + artifacts

stages:
  - test

test:
  stage: test
  image: zdenekdrahos/phpqa:v1.24.0-php7.2
  variables:
    BACKEND_QA: "*/backend/var/QA"
    BACKEND_CACHE: $CI_PROJECT_DIR/.composercache
  cache:
    paths:
    - $BACKEND_CACHE
  script:
    - 'export COMPOSER_CACHE_DIR=$BACKEND_CACHE'
    - 'composer install --ignore-platform-reqs --no-progress --no-suggest'
    - 'phpqa --report --tools phpcs:0,phpunit:0 --buildDir var/QA --analyzedDirs ./ --ignoredDirs var,vendor'
  artifacts:
    when: always
    paths:
    - $BACKEND_QA

Contributing

Contributions from others would be very much appreciated! Send pull request/issue. Thanks!

License

Copyright (c) 2015, 2016, 2017, 2018 Edgedesign.cz. MIT Licensed, see LICENSE for details.

Comments
  • compatibility with consolidation/robo v3.x

    compatibility with consolidation/robo v3.x

    Hi,

    consolidation/robo v2.x is using league/container v2.x, that is using the deprecated package container-interop/container-interop

    https://packagist.org/packages/consolidation/robo#2.2.2 https://packagist.org/packages/league/container#2.5.0 https://packagist.org/packages/container-interop/container-interop

    is it possible to add the compatibility with consolidation/robo v3.x that is using league/container v3.x, that has replace the deprecated package by psr/container ?

    https://packagist.org/packages/consolidation/robo#3.0.3 https://packagist.org/packages/league/container#3.3.5 https://packagist.org/packages/psr/container

    thanks,

    Laurent

    opened by spipu 10
  • psalm fails because of missing config file

    psalm fails because of missing config file

    Thanks a lot for phpqa!

    Sadly i found an problem with the integration of psalm.

    #steps to reproduce:

    Installation

        - composer global require edgedesign/phpqa --update-no-dev
        - composer global require jakub-onderka/php-parallel-lint jakub-onderka/php-console-highlighter phpstan/phpstan vimeo/psalm friendsofphp/php-cs-fixer
        - mkdir -p public/phpqa
        - PATH="$PATH:$HOME/.composer/vendor/bin/"
        - phpqa --report --analyzedDirs Packages/Application/PackageName --buildDir public/phpqa --tools phploc,phpcpd,phpcs,pdepend,phpmd,phpmetrics,php-cs-fixer,parallel-lint,phpstan,psalm
    

    .phpqa.yml

    phpcs:
        standard: PSR2
        # number of allowed errors is compared with warnings+errors, or just errors from checkstyle.xml
        ignoreWarnings: false
        # https://github.com/squizlabs/PHP_CodeSniffer/wiki/Reporting
        reports:
            cli:
                - full
            #file:
                # checkstyle is always included and overriden
                # checkstyle: checkstyle.xml
                # you can include custom reports (https://github.com/wikidi/codesniffer/blob/master/reports/wikidi/Summary.php#L39)
                # ./vendor/owner/package/src/MySummaryReport.php: phpcs-summary.html
    
    php-cs-fixer:
        # http://cs.sensiolabs.org/#usage
        rules: '@PSR2'
        allowRiskyRules: false
        # by default the tool is runned in dry-run mode (no fixers are applied)
        isDryRun: true
    
    phpstan:
        level: 0
    
    phpunit:
        # binary: vendor/bin/phpunit
        binary: bin/phpunit
        # phpunit.xml
        config: Build/BuildEssentials/PhpUnit/UnitTests.xml
        reports:
            file: []
                # log: [junit, tap, json]
                # testdox: [html, text]
                # coverage: [html, clover, crap4j, php, text, xml] # requires XDebug extension
    
    psalm:
        config: .psalm.xml
        deadCode: true
        threads: 5
        showInfo: true
    
    # Php file extensions to parse.
    extensions:
        - php
    

    Result

    The result is an exit code larger than zero.

    Additionally there is an output in the phpqa.html#psalm which is: DOMDocument::load(): I/O warning : failed to load external entity "/builds/projects/public/phpqa/psalm.xml".

    The phpqa/pslam.xml does not exist, BUT there is an psalm-phpqa.xml

    Maybe you can either point me to the correct config or accept that as an bug.

    opened by kaystrobach 9
  • RoboFile related error

    RoboFile related error

    Hello,

    trying to get PHPQA running in a CI job using GitHub actions. But I am not able to cope with an error message - maybe just an obvious beginner issue.

    Here is what I did so far:

    Installed version 1.23.2 using composer.

    Added a .phpqa.yml file containing:

    phpqa.analyzedDirs: ./src/
    phpqa.ignoredDirs: vendor
    phpqa.report: true
    phpqa.output: cli
    

    Running these commands:

    php ./vendor/bin/phpqa-extensions.php --add phpa phpca phpmnd
    
    ./vendor/bin/phpqa
    

    Which results in this error:

    PHP Fatal error:  Uncaught Error: Class 'RoboFile' not found in /home/runner/work/.../vendor/consolidation/robo/src/Runner.php:61
    Stack trace:
    #0 /home/runner/work/.../vendor/edgedesign/phpqa/phpqa(55): Robo\Runner->execute(Array)
    #1 {main}
      thrown in /home/runner/work/.../vendor/consolidation/robo/src/Runner.php on line 61
    

    Originally I had no YAML file, but added the parameters as CLI arguments. Did not change anything, same error occured.

    Any idea what I am missing here?

    opened by Guite 7
  • phpqa report dashboard

    phpqa report dashboard

    Hello,

    On my "circleci" project, i'm launching all the tasks in parallel: Capture d’écran 2019-09-30 à 17 02 12 => Directory reports: reports/phpcs/phpcs.xml -- reports/phpunit/phpunit.xml -- .....

    Example cmd: qa/phpqa --report --buildDir reports/phpmetrics --analyzedDirs ./ --ignoredDirs features,data,scripts,public,vendor --tools=phpmetrics

    In the last job "reports" i want to create the dashboard reporting like this (without re-running all tests) based on the custom reports directories: https://edgedesigncz.github.io/phpqa/report/phpqa.html

    Any ideas ?

    opened by li-adrienloiseau 7
  • Psalm v3 support?

    Psalm v3 support?

    Hi!

    I'd like to use Psalm v3 but for now it doesn't works, what can I do to add support of Psalm v3 (ideally with PHPUnit plugin) into phpqa?

    Mickaël

    Thanks for your awesome project :heart:

    opened by mickaelandrieu 7
  • PHPUnit and issues with html code coverage

    PHPUnit and issues with html code coverage

    When using

    phpunit:
         config: phpunit.xml
         reports:
            file:
                coverage: [html]
    

    This creates incorrect command line arguments and menu items for html code coverage

    First - the --coverage-html argument takes a directory path, NOT a filename. If you send it a filename it treats it as a directory name Second the men item says "coverage.html" and links to "coverage.html.html" - which is in fact a directory

    I've changed the code in Phpunit.php to cover the "weird" use case of coverage in html format with a special path for the coverage format when html is selected. It detects that the format is coverage and the format is html, creates a filename as a directory name for the arguments, and creates a menu item in userReports that links to the index.html in the code coverage directory

                foreach ($this->config->value('phpunit.reports.file') as $report => $formats) {
                    foreach ($formats as $format) {
                        if($report == 'coverage' && $format == 'html') {
                            $filename = "{$report}-{$format}";
                            $args["{$report}-{$format}"] = $this->options->toFile($filename);
                            $this->tool->userReports["{$report}.{$format}"] = $this->options->rawFile($filename . '/index.html');
                        } else {
                            $extension = array_key_exists($format, $extensions) ? $extensions[$format] : $format;
                            $filename = "{$report}-{$format}.{$extension}";
                            $args["{$report}-{$format}"] = $this->options->toFile($filename);
                            $this->tool->userReports["{$report}.{$format}"] = $this->options->rawFile($filename);
                        }
                    }
                }
    

    I've tested this with all the other code coverage, testdoxs, and log output

    opened by auroraeosrose 7
  • phpcs ignoreWarnings does not work in CLI mode

    phpcs ignoreWarnings does not work in CLI mode

    composer info | grep phpqa
    edgedesign/phpqa                      v1.18.0 Analyze PHP code with one command.
    
    composer info | grep php_code
    squizlabs/php_codesniffer             3.2.3   PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards
    

    ignoreWarnings: in my .phpqa.yml seems ignored.

    1° set true the output cli show warnings 2° final repport too

    +---------------+-------------------+-----------+--------+--+
    | Tool          | Allowed exit code | Exit code | Is OK? |  |
    +---------------+-------------------+-----------+--------+--+
    | phpcs         | 0                 | 1         | x      |  |
    | parallel-lint | 0                 | 0         | ✓      |  |
    +---------------+-------------------+-----------+--------+--+
    | phpqa         |                   | 1         | x      |  |
    +---------------+-------------------+-----------+--------+--+
    

    I've solve it

    .../vendor/edgedesign/phpqa/src/Tools/Analyzer/Phpcs.php

    I've added

            if ($this->tool->errorsType) {
                $args[] = '-n';
            }
    

    in

        protected function buildPhpcs(array $installedStandards)
        {
            $this->tool->errorsType = $this->config->value('phpcs.ignoreWarnings') === true;
            $standard = $this->config->value('phpcs.standard');
            if (!in_array($standard, $installedStandards)) {
                $standard = \Edge\QA\escapePath($this->config->path('phpcs.standard'));
            }
            $args = array(
                '-p',
                'standard' => $standard,
                $this->options->ignore->phpcs(),
                $this->options->getAnalyzedDirs(' '),
                'extensions' => $this->config->csv('extensions')
            );
            if ($this->tool->errorsType) {
                $args[] = '-n';
            }
            if ($this->options->isSavedToFiles) {
    
    

    https://patch-diff.githubusercontent.com/raw/EdgedesignCZ/phpqa/pull/120.patch

    opened by Moosh-be 7
  • Error with PhpCpd progress helper

    Error with PhpCpd progress helper

    Hi Guys,

    first of all thanks for your tool, it's really great ! I encounter an issue with phpcpd running via phpqa. I've trying with parallel and non parallel execution, here the console output.

    Output for  /Users/Cyril/.composer/vendor/edgedesign/phpqa/../../bin/phpcpd --progress  --exclude=build --exclude=vendor --exclude=Tests --exclude=scripts --exclude=var --exclude=web "./src" --min-lines 5 --min-tokens 70 --log-pmd "./build/phpcpd.xml" 
    phpcpd 2.0.4 by Sebastian Bergmann.
    
    
    
    
      [Symfony\Component\Console\Exception\InvalidArgumentException]  
      The helper "progress" is not defined.                           
    
    
    phpcpd [--names NAMES] [--names-exclude NAMES-EXCLUDE] [--exclude EXCLUDE] [--log-pmd LOG-PMD] [--min-lines MIN-LINES] [--min-tokens MIN-TOKENS] [--fuzzy] [--progress] [--] [<values>]...
    
    
    
     [Edge\QA\Task\NonParallelExec]  Exit code 2  Time 68.85s
    
    

    With phpcpd 2.0.1 with same arguments no problem. Can you help me please ? Thanks Cyril

    opened by nbk195 7
  • Exit code is ignored from phpmd (parsing errors for new php syntax)

    Exit code is ignored from phpmd (parsing errors for new php syntax)

    Phpmd (v2.10.0) fails for a particular reason in this case (issue with trailing commas in function arguments):

    ERROR while parsing 
    --------------------
    Unexpected token: ), line: 56, col: 5, file
    

    The exit code is printed correctly but phpqa considers this a success.

     73/73 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100% 
     [Edge\QA\Task\ParallelExec] Output for "/app/vendor/edgedesign/phpqa/../../../vendor/bin/phpmd" "src","tests" xml "/app/phpmd.xml"  --exclude /vendors/,/var/,/tests/_support/_generated/ --suffixes php --reportfile ".phpqa-report/phpmd.xml":
    
    
     [Edge\QA\Task\ParallelExec]  Exit code 3  Time 0.447s
    
    [phpqa] 
    +---------+----------------+--------------+--------+----------------------------+
    | Tool    | Allowed Errors | Errors count | Is OK? | HTML report                |
    +---------+----------------+--------------+--------+----------------------------+
    | phpcs   | 0              | 0            | ✓      | .phpqa-report/phpcs.html   |
    | phpmd   | 0              | 0            | ✓      | .phpqa-report/phpmd.html   |
    | phpcpd  | 0              | 0            | ✓      | .phpqa-report/phpcpd.html  |
    | phpstan | 0              | 0            | ✓      | .phpqa-report/phpstan.html |
    +---------+----------------+--------------+--------+----------------------------+
    | phpqa   |                | 0            | ✓      | .phpqa-report/phpqa.html   |
    +---------+----------------+--------------+--------+----------------------------+
    
    [phpqa] No failed tools
    
    opened by archfz 6
  • phpcpd exclude pattern not work as expected.

    phpcpd exclude pattern not work as expected.

    Recently I had to ugrade phpqa and all its tools to latest. I have noticed when used phpcpd 6.0.3, then my exclude directory patterns were not working as expected. Downgrading phpcd to 5.0.2 solved my problem.

    This issue could be related to: https://github.com/sebastianbergmann/phpcpd/issues/192

    This might be useful, if you facing with this issue.

    opened by LeeShan87 6
  • Fix executing php-cs-fixer w/o path if config file given

    Fix executing php-cs-fixer w/o path if config file given

    Taking this statement

    By default --path-mode is set to override, which means, that if you specify the path to a file or a directory via command arguments, then the paths provided to a Finder in config file will be ignored.

    from php-cs-fixer documentation into account, your path setting from config file won't be applied if called with path argument at the same time. As phpqa always applied the --analyzedDirs values as path argument, config file was always omitted.

    opened by grudda 6
  • Custom binary location is relative to phpqa.yml

    Custom binary location is relative to phpqa.yml

    I've tried to run phpqa with phive installed PHPUnit in a Docker container. My setup looks like: Phpqa and phive installed at /phpqa folder. I mount the application to /application folder.

    phpqa:
       tools:
          - phpunit
    phpunit:
        binary: ../phpqa/tools/phpunit
        config: phpunit.xml
        reports:
            file: 
                coverage: [html, clover, crap4j, xml]
    tool:
        phpunit: Edge\QA\Tools\Analyzer\Phpunit
    

    If I tried to run phpunit with absolute path to the binary the tool was not found. I've added a var_dump before https://github.com/EdgedesignCZ/phpqa/blob/master/src/Config.php#L80 And found out it became: string(33) "/application//phpqa/tools/phpunit"

    Just a note if someone has a similar issue using custom phar binaries. Keep up the good work. I really love your tool. :)

    opened by LeeShan87 0
Releases(v1.26.2)
  • v1.26.2(Sep 20, 2022)

  • v1.26.1(May 8, 2022)

  • v1.26.0(Apr 30, 2022)

  • v1.25.0(May 25, 2021)

    • tools
      • support Robo v3.X #226, #227
      • upgrade pdepend, phpmd (partial php7.4 and php8 syntax) #231
      • drop support for phpcs v2 (php8 syntax in phpcs 3.6) #232
      • refine handling phpmd parsing errors (visual warning in html, enable counting them for exit code) #230, #237
      • add deptrac #229, #235
    • custom binaries
      • refine loading versions from custom binaries #233
      • run custom binaries, refactoring #234
    • html reports
      • fix replacing text with multiple file paths, hotfix bootstrap menu with many tools #239
    • internal
      • CI - building docker images after release - #224
      • CI - fix phpstan/psalm config #236
      • Refine docs (github actions example, .phpqa.yml config) #238
    Source code(tar.gz)
    Source code(zip)
  • v1.24.0(Feb 8, 2021)

    • tools
      • upgrade pdepend, phpmd, psalm #218
      • refactoring testing different php versions and installing suggested tools #220
      • phpcpd - support extensions configuration #193, ~~#192~~, enable v6 #206, #209
      • phpstan - fix supporting v0.12 #194, require neon dependency #196, #197
      • security-checker - replace the abandoned Sensiolabs security checker with the Enlightn security checker #216, #215, ~~#214~~
      • parallel-lint - don't use abandoned parallel-lint packages #207
      • psalm/phpstan - memory-limit for psalm and phpstan #202
    • composer
      • fix loading versions installed by composer 2.0 #212, #213
      • allow to define vendor and vendor-bin with environment variables #198
      • enable symfony5 #205, twig3 #203, robo3 #208
    • internal
      • migrate from travis to github actions, add php 7.4/8.0 #195, #217, #219, #221
      • build default and updated docker image #222
      • update docs (docker helper, present copyright year) #199, #210, #223
    Source code(tar.gz)
    Source code(zip)
  • v1.23.3(Nov 30, 2019)

  • v1.23.2(Nov 2, 2019)

  • v1.23.1(Sep 13, 2019)

  • v1.23.0(Aug 31, 2019)

    • #180 php-cs-fixer.config BC - php-cs-fixer.config is relative to .phpqa.yml, previously it was relative to cwd
    • #182 Fix loading composer's versions if project has custom bin-dir
    • CI
      • #183 - Fix Windows build on Appveyor
    Source code(tar.gz)
    Source code(zip)
  • v1.22.1(Jul 14, 2019)

  • v1.22.0(Jul 14, 2019)

    • .phpqa.yml
      • #173 Support multiple phpcs standards
        phpcs:
            standard:
                - PSR2
                - phpcs.xml
        
      • #175 Optional phpqa configuration in yml file instead of CLI options
        Alternatives:
        # CLI options
        phpqa --verbose --report --tools phploc,phpcs:0
        # load "CLI options" from yaml file
        phpqa --config ./
        
        # ./.phpqa.yml
        phpqa:
            report: true
            verbose: true
            tools:
                - phploc
                - phpcs:0
        
      • #177 Configuration changes
        • b450040 BC allowedErrorsCount is no longer supported, configure errors count in phpqa.tools
        • de736d6 Extensions should be configured in phpqa.extensions
        # preferred configuration
        phpqa:
            extensions: php
        
        # deprecated configuration
        extensions: php
        
    • Internal
      • #172 CI - test php-cs-fixer on Windows, fix Travis php7.1 build (support phpunit > 5, security-checker)
      • 29262ef Delete php-eye badge
    Source code(tar.gz)
    Source code(zip)
  • v1.21.1(May 2, 2019)

  • v1.21.0(May 2, 2019)

  • v1.20.0(Dec 22, 2018)

    • #157 - support Psalm 3.x (#158 internalClass refactoring)
    • #156 - upgrade phpcs, enable defining allowed errors count in . phpqa.yml
    • #150 - phpstan - use --errorFormat only if version < 0.10.3
    • #149 - fix displaying psalm issue line numbers
    • #147 - phpmd - fix excluding files on Windows
    • #145 - fix psalm issues (v2 compatibility - #142 stopOnFirstError, UntypedParam, #144/#146 --use-ini-defaults)
    • #140 - fix ignoring subdirectories on Windows
    • #138 - fix phpunit issues (#136 spaces in path, #137 html/xml coverage directory)
    • CI
      • #139 - fix installing phpstan
      • #154 - fix phpunit CVE, add php 7.3
      • #141 - Windows build on Appveyor
    Source code(tar.gz)
    Source code(zip)
  • v1.19.0(Jun 14, 2018)

    • HTML reports
      • #117 - fix phpmetrics menu
      • #133 - load correct initial page
    • .phpqa.yml
      • #128 - .phpqa.yml options - phpmetrics (git, junit, composer), pdepend (coverage report
      • #134 - keep tools order from --tools option
    • Other
      • #119 - fix ignoring PHPCS warnings in CLI mode
      • #131 - fix clone + composer installation
      • #132 - fix Travis build (hhvm, psalm)
      • #135 - update pdepend, suggested tools doc
    Source code(tar.gz)
    Source code(zip)
  • v1.18.0(Feb 9, 2018)

  • v1.17.0(Feb 4, 2018)

  • v1.16.0(Oct 25, 2017)

  • v1.15.0(Sep 30, 2017)

    • Optional tools
      • #94 vimeo/psalm - dynamic configuration
    • #92 Improved reports (summary, page load)
    • Upgrade QA tools (phpcs)
    • Internal changes
      • #93 Refactoring tools (tool per class, experimental configuration in .phpqa.yml)
      • #94 Fix composer.lock, enable phpstan/psalm in travis
    Source code(tar.gz)
    Source code(zip)
  • v1.14.0(Sep 24, 2017)

  • v1.13.0(Aug 5, 2017)

    • Optional tools
      • #80 phpunit (experimental)
    • #72 Support phploc v4.X (drop --progress option)
    • #74 Support phpmetrics v1 configuration, evaluate exit code
    • #83 Make php extensions configurable in .phpqa.yml
    • Bugfixes
      • #75 Fix ignoring phpmd/pdepend directories on Windows
      • #76 Fix escaping binary path
      • #77 Don't use default 60s timeout is non-parallel execution
      • #79 Fix typo in docker example in Readme
    Source code(tar.gz)
    Source code(zip)
  • v1.12.1(Jun 10, 2017)

  • v1.12.0(Jun 10, 2017)

  • v1.11.0(Apr 10, 2017)

  • v1.10.0(Mar 4, 2017)

  • v1.9.1(Jan 8, 2017)

  • v1.9.0(Jan 8, 2017)

    • Optional tools
      • #41 parallel-lint (stable)
      • #43 phpstan v0.5 (experimental)
    • #40 Support exit code and summary in CLI mode
    • #42 Show parsing errors in phpmd report
    • #44 phpqa tools - load package information from composer
    • #47 Custom binary location (#46 Changing composer bin-dir breaks tools path)
    • #48 Refine documentation
    Source code(tar.gz)
    Source code(zip)
  • v1.8.0(Dec 18, 2016)

    • #37 Stop phpqa when .phpqa.yml or specified standard doesn't exist
    • #39 Analyze multiple directories + deprecate analyzing one directory
      • Before: phpqa --analyzedDir ./
      • After: phpqa --analyzedDirs ./
    • Drop outdated versioneye badge in favor of composer outdated --direct
    • Upgrade QA tools (phpcs, phpmd, pdepend)
    Source code(tar.gz)
    Source code(zip)
  • v1.7.3(Nov 23, 2016)

  • v1.7.2(Oct 22, 2016)

A full-scale PHP sandbox class that utilizes PHP-Parser to prevent sandboxed code from running unsafe code

A full-scale PHP 7.4+ sandbox class that utilizes PHP-Parser to prevent sandboxed code from running unsafe code. It also utilizes FunctionParser to di

Corveda 192 Dec 10, 2022
A full-scale PHP 5.3.2+ sandbox class that utilizes PHPParser to prevent sandboxed code from running unsafe code.

##DEPRECATED: The PHPSandbox project has transfered to Corveda/PHPSandbox and will be actively maintained there. This branch is no longer being active

Elijah Horton 219 Sep 2, 2022
Library for counting the lines of code in PHP source code

sebastian/lines-of-code Library for counting the lines of code in PHP source code. Installation You can add this library as a local, per-project depen

Sebastian Bergmann 715 Jan 5, 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 collection of tools to help with PHP command line utilities

PHP Command Line Tools A collection of functions and classes to assist with command line development. Requirements PHP >= 5.3 Suggested PHP extensions

WP-CLI 651 Dec 21, 2022
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
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
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
Copy/Paste Detector (CPD) for PHP code.

PHP Copy/Paste Detector (PHPCPD) phpcpd is a Copy/Paste Detector (CPD) for PHP code. Installation This tool is distributed as a PHP Archive (PHAR): $

Sebastian Bergmann 2.2k Jan 1, 2023
Performs advanced static analysis on PHP code

PHP Analyzer Please report bugs or feature requests via our website support system ? in bottom right or by emailing [email protected]. Contri

Continuous Inspection 443 Sep 23, 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
Instant Upgrades and Instant Refactoring of any PHP 5.3+ code

Rector - Speedup Your PHP Development Rector helps you with 2 areas - major code changes and in daily work. Do you have a legacy code base? Do you wan

RectorPHP 6.5k Jan 8, 2023
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
phpcs-security-audit is a set of PHP_CodeSniffer rules that finds vulnerabilities and weaknesses related to security in PHP code

phpcs-security-audit v3 About phpcs-security-audit is a set of PHP_CodeSniffer rules that finds vulnerabilities and weaknesses related to security in

Floe design + technologies 655 Jan 3, 2023
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
PHP code scanner to use with gettext/gettext

PHP code scanner to use with gettext/gettext

Gettext 12 Nov 11, 2022
Code Climate CLI

Code Climate CLI Overview codeclimate is a command line interface for the Code Climate analysis platform. It allows you to run Code Climate engines on

Code Climate 2.4k Dec 26, 2022
Static code analysis to find violations in a dependency graph

PhpDependencyAnalysis PhpDependencyAnalysis is an extendable static code analysis for object-oriented PHP-Projects to generate dependency graphs from

Marco Muths 546 Dec 7, 2022