diff -Nru phpcpd-3.0.1/ChangeLog.md phpcpd-4.0.0/ChangeLog.md --- phpcpd-3.0.1/ChangeLog.md 2017-11-16 08:49:28.000000000 +0000 +++ phpcpd-4.0.0/ChangeLog.md 2018-02-02 09:59:58.000000000 +0000 @@ -2,6 +2,12 @@ All notable changes in PHPCPD are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles. +## [4.0.0] - 2018-01-02 + +### Removed + +* PHPCPD is no longer supported on PHP 5.6 and PHP 7.0 + ## [3.0.1] - 2017-11-16 ### Fixed @@ -24,5 +30,7 @@ * PHPCPD is no longer supported on PHP 5.3, PHP 5.4, and PHP 5.5 +[4.0.0]: https://github.com/sebastianbergmann/phpcpd/compare/3.0.1...4.0.0 +[3.0.1]: https://github.com/sebastianbergmann/phpcpd/compare/3.0.0...3.0.1 [3.0.0]: https://github.com/sebastianbergmann/phpcpd/compare/2.0...3.0.0 diff -Nru phpcpd-3.0.1/composer.json phpcpd-4.0.0/composer.json --- phpcpd-3.0.1/composer.json 2017-11-16 08:49:28.000000000 +0000 +++ phpcpd-4.0.0/composer.json 2018-02-02 09:59:58.000000000 +0000 @@ -15,18 +15,18 @@ }, "config": { "platform": { - "php": "5.6.0" + "php": "7.1.0" }, "optimize-autoloader": true, "sort-packages": true }, "prefer-stable": true, "require": { - "php": "^5.6|^7.0", + "php": "^7.1", "sebastian/finder-facade": "^1.1", "sebastian/version": "^1.0|^2.0", "symfony/console": "^2.7|^3.0|^4.0", - "phpunit/php-timer": "^1.0.6" + "phpunit/php-timer": "^2.0" }, "autoload": { "classmap": [ @@ -38,7 +38,7 @@ ], "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-master": "4.0-dev" } } } diff -Nru phpcpd-3.0.1/debian/autoload.php.tpl phpcpd-4.0.0/debian/autoload.php.tpl --- phpcpd-3.0.1/debian/autoload.php.tpl 2017-11-18 18:16:46.000000000 +0000 +++ phpcpd-4.0.0/debian/autoload.php.tpl 2018-03-05 18:42:08.000000000 +0000 @@ -3,7 +3,7 @@ require_once 'SebastianBergmann/FinderFacade/autoload.php'; require_once 'SebastianBergmann/Version/autoload.php'; require_once 'Symfony/Component/Console/autoload.php'; -require_once 'PHP/Timer/Autoload.php'; +require_once 'SebastianBergmann/Timer/autoload.php'; spl_autoload_register( function ($class) diff -Nru phpcpd-3.0.1/debian/changelog phpcpd-4.0.0/debian/changelog --- phpcpd-3.0.1/debian/changelog 2017-11-18 18:21:19.000000000 +0000 +++ phpcpd-4.0.0/debian/changelog 2018-07-12 05:49:45.000000000 +0000 @@ -1,3 +1,35 @@ +phpcpd (4.0.0-2build4) cosmic; urgency=medium + + * Rebuild against new phpunit7 bootstrapped stack. + + -- Gianfranco Costamagna Thu, 12 Jul 2018 07:49:45 +0200 + +phpcpd (4.0.0-2build3) cosmic; urgency=medium + + * Rebuild against new phpunit7 bootstrap. + + -- Gianfranco Costamagna Thu, 12 Jul 2018 00:01:15 +0200 + +phpcpd (4.0.0-2) unstable; urgency=medium + + * Upload to unstable, with the rest of the latest PHPUnit stack, + including php-timer (>= 2) + + -- David Prévot Thu, 29 Mar 2018 11:17:14 -1000 + +phpcpd (4.0.0-1) experimental; urgency=medium + + * Upload to experimental since the package depends on recent php-timer + currently available in experimental + + [ David Prévot ] + * Update copyright (years) + * Build-Depend on php-timer (>= 2) + * Move project repository to salsa.d.o + * Update Standards-Version to 4.1.3 + + -- David Prévot Mon, 05 Mar 2018 08:43:37 -1000 + phpcpd (3.0.1-1) unstable; urgency=medium * Upload to unstable since the php-symfony-console versioned dependency has diff -Nru phpcpd-3.0.1/debian/control phpcpd-4.0.0/debian/control --- phpcpd-3.0.1/debian/control 2017-11-18 18:16:46.000000000 +0000 +++ phpcpd-4.0.0/debian/control 2018-03-05 18:42:08.000000000 +0000 @@ -9,15 +9,15 @@ help2man, php-finder-facade, php-symfony-console, - php-timer, + php-timer (>= 2), phpab, phpunit, phpunit-version, pkg-php-tools (>= 1.7~) -Standards-Version: 4.1.1 +Standards-Version: 4.1.3 Homepage: https://github.com/sebastianbergmann/phpcpd -Vcs-Git: git://anonscm.debian.org/pkg-php/phpcpd.git -Vcs-Browser: http://anonscm.debian.org/gitweb/?p=pkg-php/phpcpd.git +Vcs-Git: https://salsa.debian.org/php-team/pear/phpcpd.git +Vcs-Browser: https://salsa.debian.org/php-team/pear/phpcpd Package: phpcpd Architecture: all diff -Nru phpcpd-3.0.1/debian/copyright phpcpd-4.0.0/debian/copyright --- phpcpd-3.0.1/debian/copyright 2017-08-04 15:57:15.000000000 +0000 +++ phpcpd-4.0.0/debian/copyright 2018-03-05 18:42:08.000000000 +0000 @@ -4,7 +4,7 @@ Source: https://github.com/sebastianbergmann/phpcpd Files: * -Copyright: 2009-2017, Sebastian Bergmann +Copyright: 2009-2018, Sebastian Bergmann License: BSD-3-clause Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions diff -Nru phpcpd-3.0.1/LICENSE phpcpd-4.0.0/LICENSE --- phpcpd-3.0.1/LICENSE 2017-11-16 08:49:28.000000000 +0000 +++ phpcpd-4.0.0/LICENSE 2018-02-02 09:59:58.000000000 +0000 @@ -1,6 +1,6 @@ phpcpd -Copyright (c) 2009-2017, Sebastian Bergmann . +Copyright (c) 2009-2018, Sebastian Bergmann . All rights reserved. Redistribution and use in source and binary forms, with or without diff -Nru phpcpd-3.0.1/.php_cs phpcpd-4.0.0/.php_cs --- phpcpd-3.0.1/.php_cs 2017-11-16 08:49:28.000000000 +0000 +++ phpcpd-4.0.0/.php_cs 1970-01-01 00:00:00.000000000 +0000 @@ -1,86 +0,0 @@ - - -For the full copyright and license information, please view the LICENSE -file that was distributed with this source code. -EOF; - -return PhpCsFixer\Config::create() - ->setRiskyAllowed(true) - ->setRules( - [ - 'array_syntax' => ['syntax' => 'short'], - 'binary_operator_spaces' => [ - 'align_double_arrow' => true, - 'align_equals' => true - ], - 'blank_line_after_namespace' => true, - 'blank_line_before_statement' => [ - 'statements' => [ - 'break', - 'continue', - 'return', - 'throw', - 'try', - ], - ], - 'braces' => true, - 'cast_spaces' => true, - 'concat_space' => ['spacing' => 'one'], - 'elseif' => true, - 'encoding' => true, - 'full_opening_tag' => true, - 'function_declaration' => true, - 'header_comment' => ['header' => $header, 'separate' => 'none'], - 'indentation_type' => true, - 'line_ending' => true, - 'lowercase_constants' => true, - 'lowercase_keywords' => true, - 'method_argument_space' => true, - 'native_function_invocation' => true, - 'no_alias_functions' => true, - 'no_blank_lines_after_class_opening' => true, - 'no_blank_lines_after_phpdoc' => true, - 'no_closing_tag' => true, - 'no_empty_phpdoc' => true, - 'no_empty_statement' => true, - 'no_extra_consecutive_blank_lines' => true, - 'no_leading_namespace_whitespace' => true, - 'no_singleline_whitespace_before_semicolons' => true, - 'no_spaces_after_function_name' => true, - 'no_spaces_inside_parenthesis' => true, - 'no_trailing_comma_in_list_call' => true, - 'no_trailing_whitespace' => true, - 'no_unused_imports' => true, - 'no_whitespace_in_blank_line' => true, - 'phpdoc_align' => true, - 'phpdoc_indent' => true, - 'phpdoc_no_access' => true, - 'phpdoc_no_empty_return' => true, - 'phpdoc_no_package' => true, - 'phpdoc_scalar' => true, - 'phpdoc_separation' => true, - 'phpdoc_to_comment' => true, - 'phpdoc_trim' => true, - 'phpdoc_types' => true, - 'phpdoc_var_without_name' => true, - 'self_accessor' => true, - 'simplified_null_return' => true, - 'single_blank_line_at_eof' => true, - 'single_import_per_statement' => true, - 'single_line_after_imports' => true, - 'single_quote' => true, - 'ternary_operator_spaces' => true, - 'trim_array_spaces' => true, - 'visibility_required' => true, - ] - ) - ->setFinder( - PhpCsFixer\Finder::create() - ->files() - ->in(__DIR__ . '/src') - ->name('*.php') - ); diff -Nru phpcpd-3.0.1/.php_cs.dist phpcpd-4.0.0/.php_cs.dist --- phpcpd-3.0.1/.php_cs.dist 1970-01-01 00:00:00.000000000 +0000 +++ phpcpd-4.0.0/.php_cs.dist 2018-02-02 09:59:58.000000000 +0000 @@ -0,0 +1,148 @@ + + +For the full copyright and license information, please view the LICENSE +file that was distributed with this source code. +EOF; + +return PhpCsFixer\Config::create() + ->setRiskyAllowed(true) + ->setRules( + [ + 'array_syntax' => ['syntax' => 'short'], + 'binary_operator_spaces' => [ + 'align_double_arrow' => true, + 'align_equals' => true + ], + 'blank_line_after_namespace' => true, + 'blank_line_before_statement' => [ + 'statements' => [ + 'break', + 'continue', + 'return', + 'throw', + 'try', + ], + ], + 'braces' => true, + 'cast_spaces' => true, + 'class_attributes_separation' => ['elements' => ['method']], + 'compact_nullable_typehint' => true, + 'concat_space' => ['spacing' => 'one'], + 'declare_equal_normalize' => ['space' => 'none'], + 'dir_constant' => true, + 'elseif' => true, + 'encoding' => true, + 'full_opening_tag' => true, + 'function_declaration' => true, + 'header_comment' => ['header' => $header, 'separate' => 'none'], + 'indentation_type' => true, + 'line_ending' => true, + 'list_syntax' => ['syntax' => 'short'], + 'lowercase_cast' => true, + 'lowercase_constants' => true, + 'lowercase_keywords' => true, + 'magic_constant_casing' => true, + 'method_argument_space' => ['ensure_fully_multiline' => true], + 'modernize_types_casting' => true, + 'native_function_casing' => true, + 'native_function_invocation' => true, + 'no_alias_functions' => true, + 'no_blank_lines_after_class_opening' => true, + 'no_blank_lines_after_phpdoc' => true, + 'no_closing_tag' => true, + 'no_empty_comment' => true, + 'no_empty_phpdoc' => true, + 'no_empty_statement' => true, + 'no_extra_consecutive_blank_lines' => true, + 'no_homoglyph_names' => true, + 'no_leading_import_slash' => true, + 'no_leading_namespace_whitespace' => true, + 'no_mixed_echo_print' => ['use' => 'print'], + 'no_null_property_initialization' => true, + 'no_short_bool_cast' => true, + 'no_short_echo_tag' => true, + 'no_singleline_whitespace_before_semicolons' => true, + 'no_spaces_after_function_name' => true, + 'no_spaces_inside_parenthesis' => true, + 'no_superfluous_elseif' => true, + 'no_trailing_comma_in_list_call' => true, + 'no_trailing_comma_in_singleline_array' => true, + 'no_trailing_whitespace' => true, + 'no_trailing_whitespace_in_comment' => true, + 'no_unneeded_control_parentheses' => true, + 'no_unneeded_curly_braces' => true, + 'no_unneeded_final_method' => true, + 'no_unreachable_default_argument_value' => true, + 'no_unused_imports' => true, + 'no_useless_else' => true, + 'no_whitespace_before_comma_in_array' => true, + 'no_whitespace_in_blank_line' => true, + 'non_printable_character' => true, + 'normalize_index_brace' => true, + 'object_operator_without_whitespace' => true, + 'ordered_class_elements' => [ + 'order' => [ + 'use_trait', + 'constant_public', + 'constant_protected', + 'constant_private', + 'property_public', + 'property_protected', + 'property_private', + 'construct', + 'destruct', + 'magic', + 'phpunit', + 'method_public', + 'method_protected', + 'method_private', + ], + ], + 'ordered_imports' => true, + 'phpdoc_add_missing_param_annotation' => true, + 'phpdoc_align' => true, + 'phpdoc_annotation_without_dot' => true, + 'phpdoc_indent' => true, + 'phpdoc_no_access' => true, + 'phpdoc_no_empty_return' => true, + 'phpdoc_no_package' => true, + 'phpdoc_order' => true, + 'phpdoc_return_self_reference' => true, + 'phpdoc_scalar' => true, + 'phpdoc_separation' => true, + 'phpdoc_single_line_var_spacing' => true, + 'phpdoc_to_comment' => true, + 'phpdoc_trim' => true, + 'phpdoc_types' => true, + 'phpdoc_types_order' => true, + 'phpdoc_var_without_name' => true, + 'pow_to_exponentiation' => true, + 'protected_to_private' => true, + 'return_type_declaration' => ['space_before' => 'none'], + 'self_accessor' => true, + 'short_scalar_cast' => true, + 'simplified_null_return' => true, + 'single_blank_line_at_eof' => true, + 'single_import_per_statement' => true, + 'single_line_after_imports' => true, + 'single_quote' => true, + 'standardize_not_equals' => true, + 'ternary_to_null_coalescing' => true, + 'trim_array_spaces' => true, + 'unary_operator_spaces' => true, + 'visibility_required' => true, + 'void_return' => true, + 'whitespace_after_comma_in_array' => true, + ] + ) + ->setFinder( + PhpCsFixer\Finder::create() + ->files() + ->in(__DIR__ . '/src') + ->in(__DIR__ . '/tests') + ->name('*.php') + ); diff -Nru phpcpd-3.0.1/README.md phpcpd-4.0.0/README.md --- phpcpd-3.0.1/README.md 2017-11-16 08:49:28.000000000 +0000 +++ phpcpd-4.0.0/README.md 2018-02-02 09:59:58.000000000 +0000 @@ -1,5 +1,5 @@ [![Latest Stable Version](https://img.shields.io/packagist/v/sebastian/phpcpd.svg?style=flat-square)](https://packagist.org/packages/sebastian/phpcpd) -[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%205.6-8892BF.svg?style=flat-square)](https://php.net/) +[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.1-8892BF.svg?style=flat-square)](https://php.net/) [![Build Status](https://img.shields.io/travis/sebastianbergmann/phpcpd/master.svg?style=flat-square)](https://travis-ci.org/sebastianbergmann/phpcpd) # PHP Copy/Paste Detector (PHPCPD) @@ -12,39 +12,47 @@ The easiest way to obtain PHPCPD is to download a [PHP Archive (PHAR)](http://php.net/phar) that has all required dependencies of PHPCPD bundled in a single file: - $ wget https://phar.phpunit.de/phpcpd.phar - $ chmod +x phpcpd.phar - $ mv phpcpd.phar /usr/local/bin/phpcpd +``` +$ wget https://phar.phpunit.de/phpcpd.phar +$ chmod +x phpcpd.phar +$ mv phpcpd.phar /usr/local/bin/phpcpd +``` You can also immediately use the PHAR after you have downloaded it, of course: - $ wget https://phar.phpunit.de/phpcpd.phar - $ php phpcpd.phar +``` +$ wget https://phar.phpunit.de/phpcpd.phar +$ php phpcpd.phar +``` ### Composer You can add this tool as a local, per-project, development-time dependency to your project using [Composer](https://getcomposer.org/): - $ composer require --dev sebastian/phpcpd +``` +$ composer require --dev sebastian/phpcpd +``` You can then invoke it using the `vendor/bin/phpcpd` executable. ## Usage Example - $ phpcpd wordpress-4.7.1 - phpcpd 3.0.0 by Sebastian Bergmann. +``` +$ phpcpd wordpress-4.7.1 +phpcpd 4.0.0 by Sebastian Bergmann. + +Found 59 clones with 2548 duplicated lines in 39 files: + + - /home/sb/wordpress-4.7.1/wp-admin/includes/class-ftp-pure.php:99-114 + /home/sb/wordpress-4.7.1/wp-admin/includes/class-ftp-sockets.php:119-134 + . + . + . + - /home/sb/wordpress-4.7.1/wp-includes/class-wp-customize-manager.php:277-329 + /home/sb/wordpress-4.7.1/wp-includes/class-wp-customize-control.php:652-704 - Found 59 clones with 2548 duplicated lines in 39 files: +0.77% duplicated lines out of 332387 total lines of code. - - /home/sb/wordpress-4.7.1/wp-admin/includes/class-ftp-pure.php:99-114 - /home/sb/wordpress-4.7.1/wp-admin/includes/class-ftp-sockets.php:119-134 - . - . - . - - /home/sb/wordpress-4.7.1/wp-includes/class-wp-customize-manager.php:277-329 - /home/sb/wordpress-4.7.1/wp-includes/class-wp-customize-control.php:652-704 - - 0.77% duplicated lines out of 332387 total lines of code. - - Time: 2.91 seconds, Memory: 232.00MB +Time: 2.91 seconds, Memory: 232.00MB +``` diff -Nru phpcpd-3.0.1/src/CLI/Application.php phpcpd-4.0.0/src/CLI/Application.php --- phpcpd-3.0.1/src/CLI/Application.php 2017-11-16 08:49:28.000000000 +0000 +++ phpcpd-4.0.0/src/CLI/Application.php 2018-02-02 09:59:58.000000000 +0000 @@ -12,42 +12,17 @@ use SebastianBergmann\Version; use Symfony\Component\Console\Application as AbstractApplication; +use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Input\ArrayInput; -class Application extends AbstractApplication +final class Application extends AbstractApplication { public function __construct() { - $version = new Version('3.0.1', \dirname(\dirname(__DIR__))); - parent::__construct('phpcpd', $version->getVersion()); - } - - /** - * Gets the name of the command based on input. - * - * @param InputInterface $input The input interface - * - * @return string The command name - */ - protected function getCommandName(InputInterface $input) - { - return 'phpcpd'; - } - - /** - * Gets the default commands that should always be available. - * - * @return array An array of default Command instances - */ - protected function getDefaultCommands() - { - $defaultCommands = parent::getDefaultCommands(); + $version = new Version('4.0.0', \dirname(\dirname(__DIR__))); - $defaultCommands[] = new Command; - - return $defaultCommands; + parent::__construct('phpcpd', $version->getVersion()); } /** @@ -95,7 +70,33 @@ parent::doRun($input, $output); } - private function disableXdebug() + /** + * Gets the name of the command based on input. + * + * @param InputInterface $input The input interface + * + * @return string The command name + */ + protected function getCommandName(InputInterface $input) + { + return 'phpcpd'; + } + + /** + * Gets the default commands that should always be available. + * + * @return array An array of default Command instances + */ + protected function getDefaultCommands() + { + $defaultCommands = parent::getDefaultCommands(); + + $defaultCommands[] = new Command; + + return $defaultCommands; + } + + private function disableXdebug(): void { if (!\extension_loaded('xdebug')) { return; diff -Nru phpcpd-3.0.1/src/CLI/Command.php phpcpd-4.0.0/src/CLI/Command.php --- phpcpd-3.0.1/src/CLI/Command.php 2017-11-16 08:49:28.000000000 +0000 +++ phpcpd-4.0.0/src/CLI/Command.php 2018-02-02 09:59:58.000000000 +0000 @@ -10,24 +10,25 @@ namespace SebastianBergmann\PHPCPD\CLI; +use SebastianBergmann\FinderFacade\FinderFacade; use SebastianBergmann\PHPCPD\Detector\Detector; use SebastianBergmann\PHPCPD\Detector\Strategy\DefaultStrategy; use SebastianBergmann\PHPCPD\Log\PMD; use SebastianBergmann\PHPCPD\Log\Text; -use SebastianBergmann\FinderFacade\FinderFacade; +use SebastianBergmann\Timer\Timer; use Symfony\Component\Console\Command\Command as AbstractCommand; +use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Helper\ProgressBar; -class Command extends AbstractCommand +final class Command extends AbstractCommand { /** * Configures the current command. */ - protected function configure() + protected function configure(): void { $this->setName('phpcpd') ->setDefinition( @@ -163,7 +164,7 @@ } if (!$quiet) { - print \PHP_Timer::resourceUsage() . "\n"; + print Timer::resourceUsage() . "\n"; } if (\count($clones) > 0) { diff -Nru phpcpd-3.0.1/src/CodeCloneFile.php phpcpd-4.0.0/src/CodeCloneFile.php --- phpcpd-3.0.1/src/CodeCloneFile.php 2017-11-16 08:49:28.000000000 +0000 +++ phpcpd-4.0.0/src/CodeCloneFile.php 2018-02-02 09:59:58.000000000 +0000 @@ -9,7 +9,7 @@ */ namespace SebastianBergmann\PHPCPD; -class CodeCloneFile +final class CodeCloneFile { /** * @var string @@ -26,37 +26,24 @@ */ private $startLine; - /** - * @param string $name - * @param int $startLine - */ - public function __construct($name, $startLine) + public function __construct(string $name, int $startLine) { $this->name = $name; $this->startLine = $startLine; $this->id = $this->name . ':' . $this->startLine; } - /** - * @return string - */ - public function getId() + public function getId(): string { return $this->id; } - /** - * @return string - */ - public function getName() + public function getName(): string { return $this->name; } - /** - * @return int - */ - public function getStartLine() + public function getStartLine(): int { return $this->startLine; } diff -Nru phpcpd-3.0.1/src/CodeCloneMap.php phpcpd-4.0.0/src/CodeCloneMap.php --- phpcpd-3.0.1/src/CodeCloneMap.php 2017-11-16 08:49:28.000000000 +0000 +++ phpcpd-4.0.0/src/CodeCloneMap.php 2018-02-02 09:59:58.000000000 +0000 @@ -10,30 +10,30 @@ namespace SebastianBergmann\PHPCPD; -class CodeCloneMap implements \Countable, \Iterator +final class CodeCloneMap implements \Countable, \Iterator { /** - * @var CodeClone[] The clones in the clone map + * @var CodeClone[] */ private $clones = []; /** - * @var CodeClone[] The clones in the clone map, stored by ID + * @var CodeClone[] */ private $clonesById = []; /** - * @var int Current position while iterating the clone map + * @var int */ private $position = 0; /** - * @var int Number of duplicate lines in the clone map + * @var int */ private $numberOfDuplicatedLines = 0; /** - * @var int Number of lines analyzed + * @var int */ private $numLines = 0; @@ -42,12 +42,7 @@ */ private $filesWithClones = []; - /** - * Adds a clone to the map. - * - * @param CodeClone $clone - */ - public function addClone(CodeClone $clone) + public function addClone(CodeClone $clone): void { $id = $clone->getId(); @@ -72,21 +67,14 @@ } /** - * Returns the clones stored in this map. - * * @return CodeClone[] */ - public function getClones() + public function getClones(): array { return $this->clones; } - /** - * Returns the percentage of duplicated code lines in the project. - * - * @return string - */ - public function getPercentage() + public function getPercentage(): string { if ($this->numLines > 0) { $percent = ($this->numberOfDuplicatedLines / $this->numLines) * 100; @@ -97,92 +85,52 @@ return \sprintf('%01.2F%%', $percent); } - /** - * Returns the number of lines analyzed. - * - * @return int - */ - public function getNumLines() + public function getNumLines(): int { return $this->numLines; } - /** - * Sets the number of physical source code lines in the project. - * - * @param int $numLines - */ - public function setNumLines($numLines) + public function setNumLines(int $numLines): void { $this->numLines = $numLines; } - /** - * Returns the number of clones stored in this map. - */ - public function count() + public function count(): int { return \count($this->clones); } - /** - * @return int - */ - public function getNumberOfFilesWithClones() + public function getNumberOfFilesWithClones(): int { return \count($this->filesWithClones); } - /** - * @return int - */ - public function getNumberOfDuplicatedLines() + public function getNumberOfDuplicatedLines(): int { return $this->numberOfDuplicatedLines; } - /** - * Rewinds the Iterator to the first element. - */ - public function rewind() + public function rewind(): void { $this->position = 0; } - /** - * Checks if there is a current element after calls to rewind() or next(). - * - * @return bool - */ - public function valid() + public function valid(): bool { return $this->position < \count($this->clones); } - /** - * Returns the key of the current element. - * - * @return int - */ - public function key() + public function key(): int { return $this->position; } - /** - * Returns the current element. - * - * @return CodeClone - */ - public function current() + public function current(): CodeClone { return $this->clones[$this->position]; } - /** - * Moves forward to next element. - */ - public function next() + public function next(): void { $this->position++; } diff -Nru phpcpd-3.0.1/src/CodeClone.php phpcpd-4.0.0/src/CodeClone.php --- phpcpd-3.0.1/src/CodeClone.php 2017-11-16 08:49:28.000000000 +0000 +++ phpcpd-4.0.0/src/CodeClone.php 2018-02-02 09:59:58.000000000 +0000 @@ -10,7 +10,7 @@ namespace SebastianBergmann\PHPCPD; -class CodeClone +final class CodeClone { /** * @var int Size of the clone (lines) @@ -37,15 +37,7 @@ */ private $lines = ''; - /** - * Constructor. - * - * @param CodeCloneFile $fileA - * @param CodeCloneFile $fileB - * @param int $size - * @param int $tokens - */ - public function __construct(CodeCloneFile $fileA, CodeCloneFile $fileB, $size, $tokens) + public function __construct(CodeCloneFile $fileA, CodeCloneFile $fileB, int $size, int $tokens) { $this->addFile($fileA); $this->addFile($fileB); @@ -55,12 +47,7 @@ $this->id = \md5($this->getLines()); } - /** - * Add file with clone - * - * @param CodeCloneFile $file - */ - public function addFile(CodeCloneFile $file) + public function addFile(CodeCloneFile $file): void { $id = $file->getId(); @@ -70,23 +57,14 @@ } /** - * Get files with clone - * * @return CodeCloneFile[] */ - public function getFiles() + public function getFiles(): array { return $this->files; } - /** - * Returns the lines of the clone. - * - * @param string $indent - * - * @return string The lines of the clone - */ - public function getLines($indent = '') + public function getLines($indent = ''): string { if (empty($this->lines)) { $file = \current($this->files); @@ -109,26 +87,17 @@ return $this->lines; } - /** - * @return string - */ - public function getId() + public function getId(): string { return $this->id; } - /** - * @return int - */ - public function getSize() + public function getSize(): int { return $this->size; } - /** - * @return int - */ - public function getTokens() + public function getTokens(): int { return $this->tokens; } diff -Nru phpcpd-3.0.1/src/Detector/Detector.php phpcpd-4.0.0/src/Detector/Detector.php --- phpcpd-3.0.1/src/Detector/Detector.php 2017-11-16 08:49:28.000000000 +0000 +++ phpcpd-4.0.0/src/Detector/Detector.php 2018-02-02 09:59:58.000000000 +0000 @@ -10,43 +10,29 @@ namespace SebastianBergmann\PHPCPD\Detector; -use SebastianBergmann\PHPCPD\Detector\Strategy\AbstractStrategy; use SebastianBergmann\PHPCPD\CodeCloneMap; +use SebastianBergmann\PHPCPD\Detector\Strategy\AbstractStrategy; use Symfony\Component\Console\Helper\ProgressBar; -class Detector +final class Detector { /** * @var \SebastianBergmann\PHPCPD\Detector\Strategy\AbstractStrategy */ - protected $strategy; + private $strategy; /** * @var \Symfony\Component\Console\Helper\ProgressBar */ - protected $progressBar; + private $progressBar; - /** - * @param AbstractStrategy $strategy - * @param ProgressBar|null $progressBar - */ public function __construct(AbstractStrategy $strategy, ProgressBar $progressBar = null) { $this->strategy = $strategy; $this->progressBar = $progressBar; } - /** - * Copy & Paste Detection (CPD). - * - * @param \Iterator|array $files List of files to process - * @param int $minLines Minimum number of identical lines - * @param int $minTokens Minimum number of identical tokens - * @param bool $fuzzy - * - * @return CodeCloneMap Map of exact clones found in the list of files - */ - public function copyPasteDetection($files, $minLines = 5, $minTokens = 70, $fuzzy = false) + public function copyPasteDetection(iterable $files, int $minLines = 5, int $minTokens = 70, bool $fuzzy = false): CodeCloneMap { $result = new CodeCloneMap; diff -Nru phpcpd-3.0.1/src/Detector/Strategy/Abstract.php phpcpd-4.0.0/src/Detector/Strategy/Abstract.php --- phpcpd-3.0.1/src/Detector/Strategy/Abstract.php 2017-11-16 08:49:28.000000000 +0000 +++ phpcpd-4.0.0/src/Detector/Strategy/Abstract.php 1970-01-01 00:00:00.000000000 +0000 @@ -1,47 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace SebastianBergmann\PHPCPD\Detector\Strategy; - -use SebastianBergmann\PHPCPD\CodeCloneMap; - -abstract class AbstractStrategy -{ - /** - * @var int[] List of tokens to ignore - */ - protected $tokensIgnoreList = [ - T_INLINE_HTML => true, - T_COMMENT => true, - T_DOC_COMMENT => true, - T_OPEN_TAG => true, - T_OPEN_TAG_WITH_ECHO => true, - T_CLOSE_TAG => true, - T_WHITESPACE => true, - T_USE => true, - T_NS_SEPARATOR => true - ]; - - /** - * @var string[] - */ - protected $hashes = []; - - /** - * Copy & Paste Detection (CPD). - * - * @param string $file - * @param int $minLines - * @param int $minTokens - * @param CodeCloneMap $result - * @param bool $fuzzy - */ - abstract public function processFile($file, $minLines, $minTokens, CodeCloneMap $result, $fuzzy = false); -} diff -Nru phpcpd-3.0.1/src/Detector/Strategy/AbstractStrategy.php phpcpd-4.0.0/src/Detector/Strategy/AbstractStrategy.php --- phpcpd-3.0.1/src/Detector/Strategy/AbstractStrategy.php 1970-01-01 00:00:00.000000000 +0000 +++ phpcpd-4.0.0/src/Detector/Strategy/AbstractStrategy.php 2018-02-02 09:59:58.000000000 +0000 @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace SebastianBergmann\PHPCPD\Detector\Strategy; + +use SebastianBergmann\PHPCPD\CodeCloneMap; + +abstract class AbstractStrategy +{ + /** + * @var int[] + */ + protected $tokensIgnoreList = [ + T_INLINE_HTML => true, + T_COMMENT => true, + T_DOC_COMMENT => true, + T_OPEN_TAG => true, + T_OPEN_TAG_WITH_ECHO => true, + T_CLOSE_TAG => true, + T_WHITESPACE => true, + T_USE => true, + T_NS_SEPARATOR => true + ]; + + /** + * @var string[] + */ + protected $hashes = []; + + abstract public function processFile(string $file, int $minLines, int $minTokens, CodeCloneMap $result, bool $fuzzy = false): void; +} diff -Nru phpcpd-3.0.1/src/Detector/Strategy/Default.php phpcpd-4.0.0/src/Detector/Strategy/Default.php --- phpcpd-3.0.1/src/Detector/Strategy/Default.php 2017-11-16 08:49:28.000000000 +0000 +++ phpcpd-4.0.0/src/Detector/Strategy/Default.php 1970-01-01 00:00:00.000000000 +0000 @@ -1,157 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace SebastianBergmann\PHPCPD\Detector\Strategy; - -use SebastianBergmann\PHPCPD\CodeClone; -use SebastianBergmann\PHPCPD\CodeCloneFile; -use SebastianBergmann\PHPCPD\CodeCloneMap; - -class DefaultStrategy extends AbstractStrategy -{ - /** - * Copy & Paste Detection (CPD). - * - * @param string $file - * @param int $minLines - * @param int $minTokens - * @param CodeCloneMap $result - * @param bool $fuzzy - */ - public function processFile($file, $minLines, $minTokens, CodeCloneMap $result, $fuzzy = false) - { - $buffer = \file_get_contents($file); - $currentTokenPositions = []; - $currentTokenRealPositions = []; - $currentSignature = ''; - $tokens = \token_get_all($buffer); - $tokenNr = 0; - $lastTokenLine = 0; - - $result->setNumLines( - $result->getNumLines() + \substr_count($buffer, "\n") - ); - - unset($buffer); - - foreach (\array_keys($tokens) as $key) { - $token = $tokens[$key]; - - if (\is_array($token)) { - if (!isset($this->tokensIgnoreList[$token[0]])) { - if ($tokenNr == 0) { - $currentTokenPositions[$tokenNr] = $token[2] - $lastTokenLine; - } else { - $currentTokenPositions[$tokenNr] = $currentTokenPositions[$tokenNr - 1] + - $token[2] - $lastTokenLine; - } - - $currentTokenRealPositions[$tokenNr++] = $token[2]; - - if ($fuzzy && $token[0] == T_VARIABLE) { - $token[1] = 'variable'; - } - - $currentSignature .= \chr($token[0] & 255) . - \pack('N*', \crc32($token[1])); - } - - $lastTokenLine = $token[2]; - } - } - - $count = \count($currentTokenPositions); - $firstLine = 0; - $firstRealLine = 0; - $found = false; - $tokenNr = 0; - - while ($tokenNr <= $count - $minTokens) { - $line = $currentTokenPositions[$tokenNr]; - $realLine = $currentTokenRealPositions[$tokenNr]; - - $hash = \substr( - \md5( - \substr( - $currentSignature, - $tokenNr * 5, - $minTokens * 5 - ), - true - ), - 0, - 8 - ); - - if (isset($this->hashes[$hash])) { - $found = true; - - if ($firstLine === 0) { - $firstLine = $line; - $firstRealLine = $realLine; - $firstHash = $hash; - $firstToken = $tokenNr; - } - } else { - if ($found) { - $fileA = $this->hashes[$firstHash][0]; - $firstLineA = $this->hashes[$firstHash][1]; - $lastToken = ($tokenNr - 1) + $minTokens - 1; - $lastLine = $currentTokenPositions[$lastToken]; - $lastRealLine = $currentTokenRealPositions[$lastToken]; - $numLines = $lastLine + 1 - $firstLine; - $realNumLines = $lastRealLine + 1 - $firstRealLine; - - if ($numLines >= $minLines && - ($fileA != $file || - $firstLineA != $firstRealLine)) { - $result->addClone( - new CodeClone( - new CodeCloneFile($fileA, $firstLineA), - new CodeCloneFile($file, $firstRealLine), - $realNumLines, - $lastToken + 1 - $firstToken - ) - ); - } - - $found = false; - $firstLine = 0; - } - - $this->hashes[$hash] = [$file, $realLine]; - } - - $tokenNr++; - } - - if ($found) { - $fileA = $this->hashes[$firstHash][0]; - $firstLineA = $this->hashes[$firstHash][1]; - $lastToken = ($tokenNr - 1) + $minTokens - 1; - $lastLine = $currentTokenPositions[$lastToken]; - $lastRealLine = $currentTokenRealPositions[$lastToken]; - $numLines = $lastLine + 1 - $firstLine; - $realNumLines = $lastRealLine + 1 - $firstRealLine; - - if ($numLines >= $minLines && - ($fileA != $file || $firstLineA != $firstRealLine)) { - $result->addClone( - new CodeClone( - new CodeCloneFile($fileA, $firstLineA), - new CodeCloneFile($file, $firstRealLine), - $realNumLines, - $lastToken + 1 - $firstToken - ) - ); - } - } - } -} diff -Nru phpcpd-3.0.1/src/Detector/Strategy/DefaultStrategy.php phpcpd-4.0.0/src/Detector/Strategy/DefaultStrategy.php --- phpcpd-3.0.1/src/Detector/Strategy/DefaultStrategy.php 1970-01-01 00:00:00.000000000 +0000 +++ phpcpd-4.0.0/src/Detector/Strategy/DefaultStrategy.php 2018-02-02 09:59:58.000000000 +0000 @@ -0,0 +1,148 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace SebastianBergmann\PHPCPD\Detector\Strategy; + +use SebastianBergmann\PHPCPD\CodeClone; +use SebastianBergmann\PHPCPD\CodeCloneFile; +use SebastianBergmann\PHPCPD\CodeCloneMap; + +class DefaultStrategy extends AbstractStrategy +{ + public function processFile(string $file, int $minLines, int $minTokens, CodeCloneMap $result, bool $fuzzy = false): void + { + $buffer = \file_get_contents($file); + $currentTokenPositions = []; + $currentTokenRealPositions = []; + $currentSignature = ''; + $tokens = \token_get_all($buffer); + $tokenNr = 0; + $lastTokenLine = 0; + + $result->setNumLines( + $result->getNumLines() + \substr_count($buffer, "\n") + ); + + unset($buffer); + + foreach (\array_keys($tokens) as $key) { + $token = $tokens[$key]; + + if (\is_array($token)) { + if (!isset($this->tokensIgnoreList[$token[0]])) { + if ($tokenNr === 0) { + $currentTokenPositions[$tokenNr] = $token[2] - $lastTokenLine; + } else { + $currentTokenPositions[$tokenNr] = $currentTokenPositions[$tokenNr - 1] + + $token[2] - $lastTokenLine; + } + + $currentTokenRealPositions[$tokenNr++] = $token[2]; + + if ($fuzzy && $token[0] === T_VARIABLE) { + $token[1] = 'variable'; + } + + $currentSignature .= \chr($token[0] & 255) . + \pack('N*', \crc32($token[1])); + } + + $lastTokenLine = $token[2]; + } + } + + $count = \count($currentTokenPositions); + $firstLine = 0; + $firstRealLine = 0; + $found = false; + $tokenNr = 0; + + while ($tokenNr <= $count - $minTokens) { + $line = $currentTokenPositions[$tokenNr]; + $realLine = $currentTokenRealPositions[$tokenNr]; + + $hash = \substr( + \md5( + \substr( + $currentSignature, + $tokenNr * 5, + $minTokens * 5 + ), + true + ), + 0, + 8 + ); + + if (isset($this->hashes[$hash])) { + $found = true; + + if ($firstLine === 0) { + $firstLine = $line; + $firstRealLine = $realLine; + $firstHash = $hash; + $firstToken = $tokenNr; + } + } else { + if ($found) { + $fileA = $this->hashes[$firstHash][0]; + $firstLineA = $this->hashes[$firstHash][1]; + $lastToken = ($tokenNr - 1) + $minTokens - 1; + $lastLine = $currentTokenPositions[$lastToken]; + $lastRealLine = $currentTokenRealPositions[$lastToken]; + $numLines = $lastLine + 1 - $firstLine; + $realNumLines = $lastRealLine + 1 - $firstRealLine; + + if ($numLines >= $minLines && + ($fileA !== $file || + $firstLineA !== $firstRealLine)) { + $result->addClone( + new CodeClone( + new CodeCloneFile($fileA, $firstLineA), + new CodeCloneFile($file, $firstRealLine), + $realNumLines, + $lastToken + 1 - $firstToken + ) + ); + } + + $found = false; + $firstLine = 0; + } + + $this->hashes[$hash] = [$file, $realLine]; + } + + $tokenNr++; + } + + if ($found) { + $fileA = $this->hashes[$firstHash][0]; + $firstLineA = $this->hashes[$firstHash][1]; + $lastToken = ($tokenNr - 1) + $minTokens - 1; + $lastLine = $currentTokenPositions[$lastToken]; + $lastRealLine = $currentTokenRealPositions[$lastToken]; + $numLines = $lastLine + 1 - $firstLine; + $realNumLines = $lastRealLine + 1 - $firstRealLine; + + if ($numLines >= $minLines && + ($fileA !== $file || $firstLineA !== $firstRealLine)) { + $result->addClone( + new CodeClone( + new CodeCloneFile($fileA, $firstLineA), + new CodeCloneFile($file, $firstRealLine), + $realNumLines, + $lastToken + 1 - $firstToken + ) + ); + } + } + } +} diff -Nru phpcpd-3.0.1/src/Log/AbstractXmlLogger.php phpcpd-4.0.0/src/Log/AbstractXmlLogger.php --- phpcpd-3.0.1/src/Log/AbstractXmlLogger.php 2017-11-16 08:49:28.000000000 +0000 +++ phpcpd-4.0.0/src/Log/AbstractXmlLogger.php 2018-02-02 09:59:58.000000000 +0000 @@ -14,6 +14,9 @@ abstract class AbstractXmlLogger { + /** + * @var \DOMDocument + */ protected $document; /** @@ -30,9 +33,16 @@ } /** + * Processes a list of clones. + * + * @param CodeCloneMap $clones + */ + abstract public function processClones(CodeCloneMap $clones); + + /** * Writes the XML document to the file. */ - protected function flush() + protected function flush(): void { \file_put_contents($this->filename, $this->document->saveXML()); } @@ -115,11 +125,4 @@ return \htmlspecialchars($string, ENT_COMPAT, 'UTF-8'); } - - /** - * Processes a list of clones. - * - * @param CodeCloneMap $clones - */ - abstract public function processClones(CodeCloneMap $clones); } diff -Nru phpcpd-3.0.1/src/Log/PMD.php phpcpd-4.0.0/src/Log/PMD.php --- phpcpd-3.0.1/src/Log/PMD.php 2017-11-16 08:49:28.000000000 +0000 +++ phpcpd-4.0.0/src/Log/PMD.php 2018-02-02 09:59:58.000000000 +0000 @@ -12,14 +12,14 @@ use SebastianBergmann\PHPCPD\CodeCloneMap; -class PMD extends AbstractXmlLogger +final class PMD extends AbstractXmlLogger { /** * Processes a list of clones. * * @param CodeCloneMap $clones */ - public function processClones(CodeCloneMap $clones) + public function processClones(CodeCloneMap $clones): void { $cpd = $this->document->createElement('pmd-cpd'); $this->document->appendChild($cpd); diff -Nru phpcpd-3.0.1/src/Log/Text.php phpcpd-4.0.0/src/Log/Text.php --- phpcpd-3.0.1/src/Log/Text.php 2017-11-16 08:49:28.000000000 +0000 +++ phpcpd-4.0.0/src/Log/Text.php 2018-02-02 09:59:58.000000000 +0000 @@ -13,7 +13,7 @@ use SebastianBergmann\PHPCPD\CodeCloneMap; use Symfony\Component\Console\Output\OutputInterface; -class Text +final class Text { /** * Prints a result set from Detector::copyPasteDetection(). @@ -21,7 +21,7 @@ * @param OutputInterface $output * @param CodeCloneMap $clones */ - public function printResult(OutputInterface $output, CodeCloneMap $clones) + public function printResult(OutputInterface $output, CodeCloneMap $clones): void { $verbose = $output->getVerbosity() > OutputInterface::VERBOSITY_NORMAL; diff -Nru phpcpd-3.0.1/tests/DetectorTest.php phpcpd-4.0.0/tests/DetectorTest.php --- phpcpd-3.0.1/tests/DetectorTest.php 2017-11-16 08:49:28.000000000 +0000 +++ phpcpd-4.0.0/tests/DetectorTest.php 2018-02-02 09:59:58.000000000 +0000 @@ -8,10 +8,10 @@ * file that was distributed with this source code. */ -if (!defined('TEST_FILES_PATH')) { - define( +if (!\defined('TEST_FILES_PATH')) { + \define( 'TEST_FILES_PATH', - dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR + __DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR ); } @@ -23,8 +23,10 @@ * @covers SebastianBergmann\PHPCPD\Detector\Detector::copyPasteDetection * @covers SebastianBergmann\PHPCPD\CodeClone::getLines * @dataProvider strategyProvider + * + * @param mixed $strategy */ - public function testDetectingSimpleClonesWorks($strategy) + public function testDetectingSimpleClonesWorks($strategy): void { $detector = new SebastianBergmann\PHPCPD\Detector\Detector(new $strategy); @@ -34,12 +36,12 @@ $clones = $clones->getClones(); $files = $clones[0]->getFiles(); - $file = current($files); + $file = \current($files); $this->assertEquals(TEST_FILES_PATH . 'Math.php', $file->getName()); $this->assertEquals(75, $file->getStartLine()); - $file = next($files); + $file = \next($files); $this->assertEquals(TEST_FILES_PATH . 'Math.php', $file->getName()); $this->assertEquals(139, $file->getStartLine()); @@ -114,8 +116,10 @@ /** * @covers SebastianBergmann\PHPCPD\Detector\Detector::copyPasteDetection * @dataProvider strategyProvider + * + * @param mixed $strategy */ - public function testDetectingExactDuplicateFilesWorks($strategy) + public function testDetectingExactDuplicateFilesWorks($strategy): void { $detector = new SebastianBergmann\PHPCPD\Detector\Detector(new $strategy); @@ -126,13 +130,13 @@ $clones = $clones->getClones(); $files = $clones[0]->getFiles(); - $file = current($files); + $file = \current($files); $this->assertCount(1, $clones); $this->assertEquals(TEST_FILES_PATH . 'a.php', $file->getName()); $this->assertEquals(4, $file->getStartLine()); - $file = next($files); + $file = \next($files); $this->assertEquals(TEST_FILES_PATH . 'b.php', $file->getName()); $this->assertEquals(4, $file->getStartLine()); @@ -143,8 +147,10 @@ /** * @covers SebastianBergmann\PHPCPD\Detector\Detector::copyPasteDetection * @dataProvider strategyProvider + * + * @param mixed $strategy */ - public function testDetectingClonesInMoreThanTwoFiles($strategy) + public function testDetectingClonesInMoreThanTwoFiles($strategy): void { $detector = new SebastianBergmann\PHPCPD\Detector\Detector(new $strategy); @@ -160,20 +166,20 @@ $clones = $clones->getClones(); $files = $clones[0]->getFiles(); - sort($files); + \sort($files); - $file = current($files); + $file = \current($files); $this->assertCount(1, $clones); $this->assertEquals(TEST_FILES_PATH . 'a.php', $file->getName()); $this->assertEquals(4, $file->getStartLine()); - $file = next($files); + $file = \next($files); $this->assertEquals(TEST_FILES_PATH . 'b.php', $file->getName()); $this->assertEquals(4, $file->getStartLine()); - $file = next($files); + $file = \next($files); $this->assertEquals(TEST_FILES_PATH . 'c.php', $file->getName()); $this->assertEquals(4, $file->getStartLine()); @@ -182,8 +188,10 @@ /** * @covers SebastianBergmann\PHPCPD\Detector\Detector::copyPasteDetection * @dataProvider strategyProvider + * + * @param mixed $strategy */ - public function testClonesAreIgnoredIfTheySpanLessTokensThanMinTokens($strategy) + public function testClonesAreIgnoredIfTheySpanLessTokensThanMinTokens($strategy): void { $detector = new SebastianBergmann\PHPCPD\Detector\Detector(new $strategy); @@ -202,8 +210,10 @@ /** * @covers SebastianBergmann\PHPCPD\Detector\Detector::copyPasteDetection * @dataProvider strategyProvider + * + * @param mixed $strategy */ - public function testClonesAreIgnoredIfTheySpanLessLinesThanMinLines($strategy) + public function testClonesAreIgnoredIfTheySpanLessLinesThanMinLines($strategy): void { $detector = new SebastianBergmann\PHPCPD\Detector\Detector(new $strategy); @@ -222,8 +232,10 @@ /** * @covers SebastianBergmann\PHPCPD\Detector\Detector::copyPasteDetection * @dataProvider strategyProvider + * + * @param mixed $strategy */ - public function testFuzzyClonesAreFound($strategy) + public function testFuzzyClonesAreFound($strategy): void { $detector = new SebastianBergmann\PHPCPD\Detector\Detector(new $strategy); @@ -245,8 +257,10 @@ /** * @covers SebastianBergmann\PHPCPD\Detector\Detector::copyPasteDetection * @dataProvider strategyProvider + * + * @param mixed $strategy */ - public function testStripComments($strategy) + public function testStripComments($strategy): void { $detector = new SebastianBergmann\PHPCPD\Detector\Detector(new $strategy); $clones = $detector->copyPasteDetection( diff -Nru phpcpd-3.0.1/tests/Log/PMDTest.php phpcpd-4.0.0/tests/Log/PMDTest.php --- phpcpd-3.0.1/tests/Log/PMDTest.php 2017-11-16 08:49:28.000000000 +0000 +++ phpcpd-4.0.0/tests/Log/PMDTest.php 2018-02-02 09:59:58.000000000 +0000 @@ -1,9 +1,17 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +use PHPUnit\Framework\TestCase; use SebastianBergmann\PHPCPD\CodeClone; use SebastianBergmann\PHPCPD\CodeCloneFile; use SebastianBergmann\PHPCPD\CodeCloneMap; use SebastianBergmann\PHPCPD\Log\PMD; -use PHPUnit\Framework\TestCase; class PHPCPD_Log_PMDTest extends TestCase { @@ -18,46 +26,46 @@ /** @var \SebastianBergmann\PHPCPD\Log\PMD */ private $pmdLogger; - protected function setUp() + protected function setUp(): void { $this->testFile1 = __DIR__ . '/_files/with_ascii_escape.php'; $this->testFile2 = __DIR__ . '/_files/with_ascii_escape2.php'; - $this->pmdLogFile = tempnam(sys_get_temp_dir(), 'pmd'); + $this->pmdLogFile = \tempnam(\sys_get_temp_dir(), 'pmd'); - $this->expectedPmdLogFile = tempnam(sys_get_temp_dir(), 'pmd'); - $expectedPmdLogTemplate = __DIR__ . '/_files/pmd_expected.xml'; - $expectedPmdLogContents = strtr( - file_get_contents($expectedPmdLogTemplate), - array( + $this->expectedPmdLogFile = \tempnam(\sys_get_temp_dir(), 'pmd'); + $expectedPmdLogTemplate = __DIR__ . '/_files/pmd_expected.xml'; + $expectedPmdLogContents = \strtr( + \file_get_contents($expectedPmdLogTemplate), + [ '%file1%' => $this->testFile1, '%file2%' => $this->testFile2 - ) + ] ); - file_put_contents($this->expectedPmdLogFile, $expectedPmdLogContents); + \file_put_contents($this->expectedPmdLogFile, $expectedPmdLogContents); $this->pmdLogger = new PMD($this->pmdLogFile); } - protected function tearDown() + protected function tearDown(): void { - if (file_exists($this->pmdLogFile)) { - unlink($this->pmdLogFile); + if (\file_exists($this->pmdLogFile)) { + \unlink($this->pmdLogFile); } - if (file_exists($this->expectedPmdLogFile)) { - unlink($this->expectedPmdLogFile); + if (\file_exists($this->expectedPmdLogFile)) { + \unlink($this->expectedPmdLogFile); } } /** - * @covers SebastianBergmann\PHPCPD\Log\PMD - * @covers SebastianBergmann\PHPCPD\Log\AbstractXmlLogger + * @covers \SebastianBergmann\PHPCPD\Log\PMD + * @covers \SebastianBergmann\PHPCPD\Log\AbstractXmlLogger */ - public function testSubstitutesDisallowedCharacters() + public function testSubstitutesDisallowedCharacters(): void { - $file1 = new CodeCloneFile($this->testFile1, 8); - $file2 = new CodeCloneFile($this->testFile2, 8); - $clone = new CodeClone($file1, $file2, 4, 4); + $file1 = new CodeCloneFile($this->testFile1, 8); + $file2 = new CodeCloneFile($this->testFile2, 8); + $clone = new CodeClone($file1, $file2, 4, 4); $cloneMap = new CodeCloneMap(); $cloneMap->addClone($clone); diff -Nru phpcpd-3.0.1/.travis.yml phpcpd-4.0.0/.travis.yml --- phpcpd-3.0.1/.travis.yml 2017-11-16 08:49:28.000000000 +0000 +++ phpcpd-4.0.0/.travis.yml 2018-02-02 09:59:58.000000000 +0000 @@ -5,11 +5,8 @@ php: - 5.6 - 7.0 - - 7.0snapshot - 7.1 - - 7.1snapshot - 7.2 - - 7.2snapshot - master env: