Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8b6f16e

Browse files
committedAug 16, 2021
Add type declarations
1 parent f99bbf6 commit 8b6f16e

12 files changed

+53
-164
lines changed
 

‎src/CLI/Arguments.php

+13-43
Original file line numberDiff line numberDiff line change
@@ -14,67 +14,37 @@ final class Arguments
1414
/**
1515
* @psalm-var list<string>
1616
*/
17-
private $directories;
17+
private array $directories;
1818

1919
/**
2020
* @psalm-var list<string>
2121
*/
22-
private $suffixes;
22+
private array $suffixes;
2323

2424
/**
2525
* @psalm-var list<string>
2626
*/
27-
private $exclude;
27+
private array $exclude;
2828

29-
/**
30-
* @var ?string
31-
*/
32-
private $pmdCpdXmlLogfile;
29+
private ?string $pmdCpdXmlLogfile;
3330

34-
/**
35-
* @var int
36-
*/
37-
private $linesThreshold;
31+
private int $linesThreshold;
3832

39-
/**
40-
* @var int
41-
*/
42-
private $tokensThreshold;
33+
private int $tokensThreshold;
4334

44-
/**
45-
* @var bool
46-
*/
47-
private $fuzzy;
35+
private bool $fuzzy;
4836

49-
/**
50-
* @var bool
51-
*/
52-
private $verbose;
37+
private bool $verbose;
5338

54-
/**
55-
* @var bool
56-
*/
57-
private $help;
39+
private bool $help;
5840

59-
/**
60-
* @var bool
61-
*/
62-
private $version;
41+
private bool $version;
6342

64-
/**
65-
* @var ?string
66-
*/
67-
private $algorithm;
43+
private ?string $algorithm;
6844

69-
/**
70-
* @var int
71-
*/
72-
private $editDistance;
45+
private int $editDistance;
7346

74-
/**
75-
* @var int
76-
*/
77-
private $headEquality;
47+
private int $headEquality;
7848

7949
public function __construct(array $directories, array $suffixes, array $exclude, ?string $pmdCpdXmlLogfile, int $linesThreshold, int $tokensThreshold, bool $fuzzy, bool $verbose, bool $help, bool $version, ?string $algorithm, int $editDistance, int $headEquality)
8050
{

‎src/CodeClone.php

+9-21
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,18 @@
1818

1919
final class CodeClone
2020
{
21-
/**
22-
* @var int
23-
*/
24-
private $numberOfLines;
21+
private int $numberOfLines;
2522

26-
/**
27-
* @var int
28-
*/
29-
private $numberOfTokens;
23+
private int $numberOfTokens;
3024

3125
/**
32-
* @var CodeCloneFile[]
26+
* @psalm-var array<string,CodeCloneFile>
3327
*/
34-
private $files = [];
28+
private array $files = [];
3529

36-
/**
37-
* @var string
38-
*/
39-
private $id;
30+
private string $id;
4031

41-
/**
42-
* @var string
43-
*/
44-
private $lines = '';
32+
private string $lines = '';
4533

4634
public function __construct(CodeCloneFile $fileA, CodeCloneFile $fileB, int $numberOfLines, int $numberOfTokens)
4735
{
@@ -63,22 +51,22 @@ public function add(CodeCloneFile $file): void
6351
}
6452

6553
/**
66-
* @return CodeCloneFile[]
54+
* @psalm-return array<string,CodeCloneFile>
6755
*/
6856
public function files(): array
6957
{
7058
return $this->files;
7159
}
7260

73-
public function lines($indent = ''): string
61+
public function lines(string $indent = ''): string
7462
{
7563
if (empty($this->lines)) {
7664
$file = current($this->files);
7765

7866
$this->lines = implode(
7967
'',
8068
array_map(
81-
static function ($line) use ($indent) {
69+
static function (string $line) use ($indent) {
8270
return $indent . $line;
8371
},
8472
array_slice(

‎src/CodeCloneFile.php

+3-12
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,11 @@
1111

1212
final class CodeCloneFile
1313
{
14-
/**
15-
* @var string
16-
*/
17-
private $id;
14+
private string $id;
1815

19-
/**
20-
* @var string
21-
*/
22-
private $name;
16+
private string $name;
2317

24-
/**
25-
* @var int
26-
*/
27-
private $startLine;
18+
private int $startLine;
2819

2920
public function __construct(string $name, int $startLine)
3021
{

‎src/CodeCloneMap.php

+6-18
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,20 @@ final class CodeCloneMap implements Countable, IteratorAggregate
2020
/**
2121
* @var CodeClone[]
2222
*/
23-
private $clones = [];
23+
private array $clones = [];
2424

2525
/**
2626
* @var CodeClone[]
2727
*/
28-
private $clonesById = [];
28+
private array $clonesById = [];
2929

30-
/**
31-
* @var int
32-
*/
33-
private $numberOfDuplicatedLines = 0;
30+
private int $numberOfDuplicatedLines = 0;
3431

35-
/**
36-
* @var int
37-
*/
38-
private $numberOfLines = 0;
32+
private int $numberOfLines = 0;
3933

40-
/**
41-
* @var int
42-
*/
43-
private $largestCloneSize = 0;
34+
private int $largestCloneSize = 0;
4435

45-
/**
46-
* @var array
47-
*/
48-
private $filesWithClones = [];
36+
private array $filesWithClones = [];
4937

5038
public function add(CodeClone $clone): void
5139
{

‎src/CodeCloneMapIterator.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@ final class CodeCloneMapIterator implements Iterator
1919
/**
2020
* @var CodeClone[]
2121
*/
22-
private $clones = [];
22+
private array $clones;
2323

24-
/**
25-
* @var int
26-
*/
27-
private $position = 0;
24+
private int $position = 0;
2825

2926
public function __construct(CodeCloneMap $clones)
3027
{

‎src/Detector/Detector.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414

1515
final class Detector
1616
{
17-
/**
18-
* @var AbstractStrategy
19-
*/
20-
private $strategy;
17+
private AbstractStrategy $strategy;
2118

2219
public function __construct(AbstractStrategy $strategy)
2320
{

‎src/Detector/Strategy/AbstractStrategy.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ abstract class AbstractStrategy
2525
/**
2626
* @psalm-var array<int,true>
2727
*/
28-
protected $tokensIgnoreList = [
28+
protected array $tokensIgnoreList = [
2929
T_INLINE_HTML => true,
3030
T_COMMENT => true,
3131
T_DOC_COMMENT => true,
@@ -37,7 +37,7 @@ abstract class AbstractStrategy
3737
T_NS_SEPARATOR => true,
3838
];
3939

40-
protected $config;
40+
protected StrategyConfiguration $config;
4141

4242
public function __construct(StrategyConfiguration $config)
4343
{

‎src/Detector/Strategy/DefaultStrategy.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ final class DefaultStrategy extends AbstractStrategy
4242
/**
4343
* @psalm-var array<string,array{0: string, 1: int}>
4444
*/
45-
protected $hashes = [];
45+
private array $hashes = [];
4646

4747
public function processFile(string $file, CodeCloneMap $result): void
4848
{

‎src/Detector/Strategy/StrategyConfiguration.php

+5-33
Original file line numberDiff line numberDiff line change
@@ -17,43 +17,15 @@
1717
*/
1818
final class StrategyConfiguration
1919
{
20-
/**
21-
* Minimum lines to consider.
22-
*
23-
* @var int
24-
*/
25-
private $minLines = 5;
20+
private int $minLines = 5;
2621

27-
/**
28-
* Minimum tokens to consider in a clone.
29-
*
30-
* @var int
31-
*/
32-
private $minTokens = 70;
22+
private int $minTokens = 70;
3323

34-
/**
35-
* Edit distance to consider when comparing two clones
36-
* Only available for the suffix-tree algorithm.
37-
*
38-
* @var int
39-
*/
40-
private $editDistance = 5;
24+
private int $editDistance = 5;
4125

42-
/**
43-
* Tokens that must be equal to consider a clone
44-
* Only available for the suffix-tree algorithm.
45-
*
46-
* @var int
47-
*/
48-
private $headEquality = 10;
26+
private int $headEquality = 10;
4927

50-
/**
51-
* Fuzz variable names
52-
* suffixtree always makes variables and functions fuzzy.
53-
*
54-
* @var bool
55-
*/
56-
private $fuzzy = false;
28+
private bool $fuzzy;
5729

5830
public function __construct(Arguments $arguments)
5931
{

‎src/Detector/Strategy/SuffixTreeStrategy.php

+3-6
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,11 @@
2828
final class SuffixTreeStrategy extends AbstractStrategy
2929
{
3030
/**
31-
* @var AbstractToken[]
31+
* @psalm-var list<AbstractToken>
3232
*/
33-
private $word = [];
33+
private array $word = [];
3434

35-
/**
36-
* @var ?CodeCloneMap
37-
*/
38-
private $result;
35+
private ?CodeCloneMap $result = null;
3936

4037
public function processFile(string $file, CodeCloneMap $result): void
4138
{

‎src/Log/AbstractXmlLogger.php

+3-9
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,9 @@
2121

2222
abstract class AbstractXmlLogger
2323
{
24-
/**
25-
* @var DOMDocument
26-
*/
27-
protected $document;
24+
protected DOMDocument $document;
2825

29-
/**
30-
* @var string
31-
*/
32-
private $filename;
26+
private string $filename;
3327

3428
public function __construct(string $filename)
3529
{
@@ -39,7 +33,7 @@ public function __construct(string $filename)
3933
$this->filename = $filename;
4034
}
4135

42-
abstract public function processClones(CodeCloneMap $clones);
36+
abstract public function processClones(CodeCloneMap $clones): void;
4337

4438
protected function flush(): void
4539
{

‎tests/unit/PMDTest.php

+5-10
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,15 @@
3232
*/
3333
final class PMDTest extends TestCase
3434
{
35-
/** @var string */
36-
private $testFile1;
35+
private string $testFile1;
3736

38-
/** @var @var string */
39-
private $testFile2;
37+
private string $testFile2;
4038

41-
/** @var string */
42-
private $pmdLogFile;
39+
private string|false $pmdLogFile;
4340

44-
/** @var string */
45-
private $expectedPmdLogFile;
41+
private string|false $expectedPmdLogFile;
4642

47-
/** @var \SebastianBergmann\PHPCPD\Log\PMD */
48-
private $pmdLogger;
43+
private PMD $pmdLogger;
4944

5045
protected function setUp(): void
5146
{

0 commit comments

Comments
 (0)
This repository has been archived.