Skip to content

Commit

Permalink
Merge pull request #3 from phpmd/master
Browse files Browse the repository at this point in the history
merge master
  • Loading branch information
frankdekker committed Jul 17, 2021
2 parents 1027dee + 42fb77b commit 7f87839
Show file tree
Hide file tree
Showing 59 changed files with 1,519 additions and 160 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

strategy:
matrix:
php: [5.3, 5.4, 5.5, 5.6, 7.0, 7.1, 7.2, 7.3, 7.4]
php: [5.3, 5.4, 5.5, 5.6, 7.0, 7.1, 7.2, 7.3, 7.4, 8.0]
dependency-version: [prefer-lowest, prefer-stable]
exclude:
- dependency-version: prefer-lowest
Expand Down Expand Up @@ -49,8 +49,12 @@ jobs:
restore-keys: |
${{ runner.os }}-php-${{ matrix.php }}-${{ matrix.dependency-version }}
- name: Upgrade PHPUnit
if: matrix.php >= 7.2
run: composer require phpunit/phpunit:^5.7.27 --no-update --no-interaction --dev

- name: Install dependencies
run: composer update --${{ matrix.dependency-version }} --prefer-dist --no-progress
run: composer update --${{ matrix.dependency-version }} --prefer-dist --no-progress ${{ matrix.php >= 8 && '--ignore-platform-req=php' || '' }}

- name: Execute Unit Tests
run: vendor/bin/phpunit
31 changes: 31 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
phpmd-2.10.1 (2021/05/11)
========================

- Implemented #885: Allowing 2.0 version of the composer/xdebug-handler

phpmd-2.10.0 (2021/04/26)
========================

- Added #879: Documentation for Junit export with third party
- Added #836: Provide option to allow reference to a class in the root namespace without an import
- Added #856: Adds checkstyle compatible renderer, suitable for cs2pr or reviewdog
- Added #858 in #865: Add SARIF renderer.
- Added #873 and #876: Added option to baseline existing violations
- Added #861: Docs for GitHub renderer
- Added #868 In #869: Option to ignore globally-namespaced classes from MissingImport
- Added #834 : Add "tool" property to main "pmd" tag in XML report
- Fixed #673 in #782: Ignore dynamic class name from missing imports
- Fixed #577 in #844: Recognize compact variables with double quotes
- Fixed #818 in #822: Fix passing-by-reference detection
- Fixed #826 in #827: Consider foreach exception only for direct children
- Fixed #851 in #852: Fix multiple underscores in method name when allow-underscore-test is allowed
- Fixed #846 in #847: Catch DevelopmentCodeFragment with fully qualified functions
- Fixed #829 in #835: Fatal error while analyzing anonymous class
- Fixed #816 in #818: Fixed undefined index referring
- Changed #786: Add convenience method AbstractNode::findChildrenOfTypeVariable()
- Changed documentation: #874 #849 #724
- Changed #514 in #872: Change exit code on processing errors
- Changed: Internal code improvement #839 #875 #838 #862 #788 #830
- Changed #848 #864: Use GitHub actions
- Deprecated: getIgnorePattern and setIgnorePattern on PHPMD\PHPMD see #772

phpmd-2.9.1 (2020/09/23)
========================

Expand Down
5 changes: 3 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The PHPMD project welcomes your contribution. There are several ways to help out
if you have found a bug or have an idea for a feature
* Write test cases for open bug issues
* Write patches for open bug/feature issues
* Participate on the PHPMD IRC Channel
* Participate on the PHPMD Gitter Channel

There are a few guidelines that we need contributors to follow, so that we have a
chance of keeping on top of things.
Expand All @@ -22,6 +22,7 @@ Issues
* Make sure it does not already exist.
* Clearly describe the issue including steps to reproduce, when it is a bug.
* Make sure you note the PHPMD version you use.
* Use one of the issue templates.

Coding Standard
---------------
Expand All @@ -44,4 +45,4 @@ Additional Resources
* [Existing issues](https://github.com/phpmd/phpmd/issues/)
* [General GitHub documentation](https://help.github.com/)
* [GitHub pull request documentation](https://help.github.com/articles/creating-a-pull-request/)
* [PHPMD IRC Channel on freenode.org](http://webchat.freenode.net/?channels=phpmd)
* [PHPMD Gitter Channel](https://gitter.im/phpmd/community)
13 changes: 11 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,12 @@ Command line options
- ``--ignore-violations-on-exit`` - will exit with a zero code, even if any
violations are found.

- ``--generate-baseline`` - will generate a phpmd.baseline.xml for existing violations
- ``--generate-baseline`` - will generate a ``phpmd.baseline.xml`` for existing violations
next to the ruleset definition file.

- ``--update-baseline`` - will remove all violations from an existing ``phpmd.baseline.xml``
that no longer exist. New violations will _not_ be added.

- ``--baseline-file`` - the filepath to a custom baseline xml file. The filepath
of all baselined files must be relative to this file location.

Expand Down Expand Up @@ -205,13 +208,15 @@ At the moment PHPMD comes with the following renderers:
- *json*, formats JSON report.
- *ansi*, a command line friendly format.
- *github*, a format that GitHub Actions understands.
- *sarif*, the Static Analysis Results Interchange Format.
- *checkstyle*, language and tool agnostic XML format

Baseline
--------

For existing projects a violation baseline can be generated. All violations in this baseline will be ignored in further inspections.

The recommended approach would be a ``phpmd.xml`` in the root of the project. To generate the phpmd.baseline.xml next to it::
The recommended approach would be a ``phpmd.xml`` in the root of the project. To generate the ``phpmd.baseline.xml`` next to it::

~ $ phpmd /path/to/source text phpmd.xml --generate-baseline

Expand All @@ -223,6 +228,10 @@ By default PHPMD will look next to ``phpmd.xml`` for ``phpmd.baseline.xml``. To

~ $ phpmd /path/to/source text phpmd.xml --baseline-file /path/to/source/phpmd.baseline.xml

To clean up an existing baseline file and *only remove* no longer existing violations::

~ $ phpmd /path/to/source text phpmd.xml --update-baseline

PHPMD for enterprise
--------------------

Expand Down
2 changes: 1 addition & 1 deletion build.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
project.dir =
project.uri = phpmd.org
project.name = phpmd
project.version = 2.9.1
project.version = 2.10.1
project.stability = stable

# Disable pear support. This cannot be removed as long as setup tool is used
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
"minimum-stability": "stable",
"require": {
"php": ">=5.3.9",
"pdepend/pdepend": "^2.8.0",
"pdepend/pdepend": "^2.9.1",
"ext-xml": "*",
"composer/xdebug-handler": "^1.0"
"composer/xdebug-handler": "^1.0 || ^2.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8.36 || ^5.7.27",
"squizlabs/php_codesniffer": "^2.0",
"mikey179/vfsstream": "^1.6.4",
"mikey179/vfsstream": "^1.6.8",
"gregwar/rst": "^1.0",
"ext-simplexml": "*",
"ext-json": "*",
Expand Down
17 changes: 15 additions & 2 deletions src/main/php/PHPMD/AbstractNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

namespace PHPMD;

use BadMethodCallException;
use PDepend\Source\AST\AbstractASTArtifact;
use PDepend\Source\AST\ASTVariable;
use PHPMD\Node\ASTNode;

/**
Expand Down Expand Up @@ -55,14 +57,14 @@ public function __construct($node)
* @param string $name
* @param array $args
* @return mixed
* @throws \BadMethodCallException When the underlying PDepend node
* @throws BadMethodCallException When the underlying PDepend node
* does not contain a method named <b>$name</b>.
*/
public function __call($name, array $args)
{
$node = $this->getNode();
if (!method_exists($node, $name)) {
throw new \BadMethodCallException(
throw new BadMethodCallException(
sprintf('Invalid method %s() called.', $name)
);
}
Expand Down Expand Up @@ -138,6 +140,17 @@ public function findChildrenOfType($type)
return $nodes;
}

/**
* Searches recursive for all children of this node that are of variable.
*
* @return ASTVariable[]
* @todo Cover by a test.
*/
public function findChildrenOfTypeVariable()
{
return $this->findChildrenOfType('Variable');
}

/**
* Tests if this node represents the the given type.
*
Expand Down
12 changes: 4 additions & 8 deletions src/main/php/PHPMD/AbstractRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,14 +387,10 @@ protected function addViolation(
array $args = array(),
$metric = null
) {
$search = array();
$replace = array();
foreach ($args as $index => $value) {
$search[] = '{' . $index . '}';
$replace[] = $value;
}

$message = str_replace($search, $replace, $this->message);
$message = array(
'message' => $this->message,
'args' => $args,
);

$ruleViolation = new RuleViolation($this, $node, $message, $metric);
$this->report->addRuleViolation($ruleViolation);
Expand Down
21 changes: 21 additions & 0 deletions src/main/php/PHPMD/Baseline/BaselineMode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace PHPMD\Baseline;

class BaselineMode
{
/**
* Do not generate or update any baseline file
*/
const NONE = 'none';

/**
* Generate a baseline file for _all_ current violations
*/
const GENERATE = 'generate';

/**
* Remove any non existing violations from the baseline file. Do not baseline any new violations.
*/
const UPDATE = 'update';
}
47 changes: 47 additions & 0 deletions src/main/php/PHPMD/Baseline/BaselineValidator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace PHPMD\Baseline;

use PHPMD\RuleViolation;

class BaselineValidator
{
/** @var string */
private $baselineMode;

/** @var BaselineSet */
private $baselineSet;

/**
* @param string $baselineMode
*/
public function __construct(BaselineSet $baselineSet, $baselineMode)
{
$this->baselineMode = $baselineMode;
$this->baselineSet = $baselineSet;
}

/**
* @return bool
*/
public function isBaselined(RuleViolation $violation)
{
$contains = $this->baselineSet->contains(
get_class($violation->getRule()),
$violation->getFileName(),
$violation->getMethodName()
);

// regular baseline: violations is baselined if it is in the BaselineSet
if ($this->baselineMode === BaselineMode::NONE) {
return $contains;
}

// update baseline: violation _can_ be baselined if it was already in the BaselineSet
if ($this->baselineMode === BaselineMode::UPDATE) {
return $contains === false;
}

return false;
}
}
9 changes: 2 additions & 7 deletions src/main/php/PHPMD/PHPMD.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

namespace PHPMD;

use PHPMD\Baseline\BaselineSet;

/**
* This is the main facade of the PHP PMD application
*/
Expand Down Expand Up @@ -216,24 +214,21 @@ public function setOptions(array $options)
* @param string $ruleSets
* @param \PHPMD\AbstractRenderer[] $renderers
* @param \PHPMD\RuleSetFactory $ruleSetFactory
* @param \PHPMD\Baseline\BaselineSet|null $baseline
* @param \PHPMD\Report $report
* @return void
*/
public function processFiles(
$inputPath,
$ruleSets,
array $renderers,
RuleSetFactory $ruleSetFactory,
BaselineSet $baseline = null
Report $report
) {

// Merge parsed excludes
$this->addIgnorePatterns($ruleSetFactory->getIgnorePattern($ruleSets));

$this->input = $inputPath;

$report = new Report($baseline);

$factory = new ParserFactory();
$parser = $factory->create($this);

Expand Down
4 changes: 4 additions & 0 deletions src/main/php/PHPMD/Renderer/AnsiRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ private function writeViolationsReport(Report $report)
$previousFile = null;
foreach ($report->getRuleViolations() as $violation) {
if ($violation->getFileName() !== $previousFile) {
if ($previousFile !== null) {
$this->getWriter()->write(PHP_EOL);
}

$this->writeViolationFileHeader($violation);
}

Expand Down

0 comments on commit 7f87839

Please sign in to comment.