Skip to content

Commit be94b0e

Browse files
committed
[Class, Interface, Trait] method changes are now part of their respective context output table.
Removed any output related to methods as they are outputted in their respective context table. Moved generated semantic versioning level from being given to the operation to the operation itself knowing what level it represents. [#4][#7] Added support for different visibility of methods. Extracted a new (Function/ClassMethod)ParameterNameChanged operation.
1 parent 1577092 commit be94b0e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+673
-380
lines changed

docs/Ruleset.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ V001 | MAJOR | Function removed
88
V002 | MAJOR | Function parameter changed
99
V003 | MINOR | Function added
1010
V004 | PATCH | Function implementation changed
11+
V067 | PATCH | Function parameter name changed
1112

1213
# Classes
1314

@@ -40,6 +41,9 @@ V028 | PATCH | *Class private method added*
4041
V029 | PATCH | *Class private method removed*
4142
V030 | PATCH | *Final class protected method added*
4243
V031 | PATCH | *Class private method parameter changed*
44+
V060 | PATCH | Class public method parameter name changed
45+
V061 | PATCH | Class protected method parameter name changed
46+
V062 | PATCH | Class private method parameter name changed
4347

4448
# Interface
4549

@@ -50,6 +54,7 @@ V033 | MAJOR | Interface removed
5054
V034 | MAJOR | Interface method added
5155
V035 | MAJOR | Interface method removed
5256
V036 | MAJOR | Interface method parameter changed
57+
V063 | PATCH | Interface method parameter name changed
5358

5459
# Trait
5560

@@ -77,4 +82,9 @@ V055 | PATCH | *Trait private property added*
7782
V056 | PATCH | *Trait private property removed*
7883
V057 | PATCH | *Trait private method added*
7984
V058 | PATCH | *Trait private method removed*
80-
V059 | PATCH | *Trait private method parameter changed*
85+
V059 | PATCH | *Trait private method parameter changed*
86+
V064 | PATCH | Trait public method parameter name changed
87+
V065 | PATCH | Trait protected method parameter name changed
88+
V066 | PATCH | Trait private method parameter name changed
89+
90+
Method visibility changed

src/PHPSemVerChecker/Analyzer/ClassAnalyzer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function analyze(Registry $registryBefore, Registry $registryAfter)
2727
$classBefore = $registryBefore->data['class'][$key];
2828

2929
$data = new ClassRemoved($fileBefore, $classBefore);
30-
$report->addClass($data, Level::MAJOR);
30+
$report->addClass($data);
3131
}
3232

3333
foreach ($toVerify as $key) {
@@ -51,7 +51,7 @@ public function analyze(Registry $registryBefore, Registry $registryAfter)
5151
$classAfter = $registryAfter->data['class'][$key];
5252

5353
$data = new ClassAdded($fileAfter, $classAfter);
54-
$report->addClass($data, Level::MINOR);
54+
$report->addClass($data);
5555
}
5656

5757
return $report;

src/PHPSemVerChecker/Analyzer/ClassMethodAnalyzer.php

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
use PHPSemVerChecker\Operation\ClassMethodAdded;
1010
use PHPSemVerChecker\Operation\ClassMethodImplementationChanged;
1111
use PHPSemVerChecker\Operation\ClassMethodParameterChanged;
12+
use PHPSemVerChecker\Operation\ClassMethodParameterNameChanged;
1213
use PHPSemVerChecker\Operation\ClassMethodRemoved;
13-
use PHPSemVerChecker\Operation\Unknown;
1414
use PHPSemVerChecker\Report\Report;
1515
use PHPSemVerChecker\SemanticVersioning\Level;
1616

@@ -49,14 +49,6 @@ public function analyze(Stmt $contextBefore, Stmt $contextAfter)
4949
$methodsAfterKeyed[$method->name] = $method;
5050
}
5151

52-
$methodsBeforeKeyed = array_filter($methodsBeforeKeyed, function (ClassMethod $method) {
53-
return $method->isPublic();
54-
});
55-
56-
$methodsAfterKeyed = array_filter($methodsAfterKeyed, function (ClassMethod $method) {
57-
return $method->isPublic();
58-
});
59-
6052
$methodNamesBefore = array_keys($methodsBeforeKeyed);
6153
$methodNamesAfter = array_keys($methodsAfterKeyed);
6254
$methodsAdded = array_diff($methodNamesAfter, $methodNamesBefore);
@@ -69,7 +61,7 @@ public function analyze(Stmt $contextBefore, Stmt $contextAfter)
6961
foreach ($methodsRemoved as $method) {
7062
$methodBefore = $methodsBeforeKeyed[$method];
7163
$data = new ClassMethodRemoved($this->context, $this->fileBefore, $contextBefore, $methodBefore);
72-
$report->addClassMethod($data, Level::MAJOR);
64+
$report->add($this->context, $data);
7365
}
7466

7567
foreach ($methodsToVerify as $method) {
@@ -82,24 +74,26 @@ public function analyze(Stmt $contextBefore, Stmt $contextAfter)
8274
if ($methodBefore != $methodAfter) {
8375
$paramsBefore = $methodBefore->params;
8476
$paramsAfter = $methodAfter->params;
85-
// Signature
8677

78+
// Signature
79+
$signatureChanged = false;
8780
if ( ! Signature::isSameTypehints($paramsBefore, $paramsAfter)) {
8881
$data = new ClassMethodParameterChanged($this->context, $this->fileBefore, $contextBefore, $methodBefore, $this->fileAfter, $contextAfter, $methodAfter);
89-
$report->addClassMethod($data, Level::MAJOR);
82+
$report->add($this->context, $data);
83+
$signatureChanged = true;
9084
}
9185

92-
if ( ! Signature::isSameVariables($paramsBefore, $paramsAfter)) {
93-
$data = new ClassMethodParameterChanged($this->context, $this->fileBefore, $contextBefore, $methodBefore, $this->fileAfter, $contextAfter, $methodAfter);
94-
$report->addClassMethod($data, Level::PATCH);
86+
if ( ! $signatureChanged && ! Signature::isSameVariables($paramsBefore, $paramsAfter)) {
87+
$data = new ClassMethodParameterNameChanged($this->context, $this->fileBefore, $contextBefore, $methodBefore, $this->fileAfter, $contextAfter, $methodAfter);
88+
$report->add($this->context, $data);
9589
}
9690

9791
// Different length (considering params with defaults)
9892

9993
// Difference in source code
10094
if ($methodBefore->stmts != $methodAfter->stmts) {
10195
$data = new ClassMethodImplementationChanged($this->context, $this->fileBefore, $contextBefore, $methodBefore, $this->fileAfter, $contextAfter, $methodAfter);
102-
$report->addClassMethod($data, Level::PATCH);
96+
$report->add($this->context, $data);
10397
}
10498
}
10599
}
@@ -108,7 +102,7 @@ public function analyze(Stmt $contextBefore, Stmt $contextAfter)
108102
foreach ($methodsAdded as $method) {
109103
$methodAfter = $methodsAfterKeyed[$method];
110104
$data = new ClassMethodAdded($this->context, $this->fileAfter, $contextAfter, $methodAfter);
111-
$report->addClassMethod($data, Level::MINOR);
105+
$report->add($this->context, $data);
112106
}
113107

114108
return $report;

src/PHPSemVerChecker/Analyzer/FunctionAnalyzer.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use PHPSemVerChecker\Operation\FunctionAdded;
77
use PHPSemVerChecker\Operation\FunctionImplementationChanged;
88
use PHPSemVerChecker\Operation\FunctionParameterChanged;
9+
use PHPSemVerChecker\Operation\FunctionParameterNameChanged;
910
use PHPSemVerChecker\Operation\FunctionRemoved;
1011
use PHPSemVerChecker\Operation\Unknown;
1112
use PHPSemVerChecker\Registry\Registry;
@@ -36,7 +37,7 @@ public function analyze(Registry $registryBefore, Registry $registryAfter)
3637
$functionBefore = $registryBefore->data['function'][$key];
3738

3839
$data = new FunctionRemoved($fileBefore, $functionBefore);
39-
$report->addFunction($data, Level::MAJOR);
40+
$report->addFunction($data);
4041
}
4142

4243
foreach ($toVerify as $key) {
@@ -54,13 +55,13 @@ public function analyze(Registry $registryBefore, Registry $registryAfter)
5455

5556
if ( ! Signature::isSameTypehints($paramsBefore, $paramsAfter)) {
5657
$data = new FunctionParameterChanged($fileBefore, $functionBefore, $fileAfter, $functionAfter);
57-
$report->addFunction($data, Level::MAJOR);
58+
$report->addFunction($data);
5859
continue;
5960
}
6061

6162
if ( ! Signature::isSameVariables($paramsBefore, $paramsAfter)) {
62-
$data = new FunctionParameterChanged($fileBefore, $functionBefore, $fileAfter, $functionAfter);
63-
$report->addFunction($data, Level::PATCH);
63+
$data = new FunctionParameterNameChanged($fileBefore, $functionBefore, $fileAfter, $functionAfter);
64+
$report->addFunction($data);
6465
continue;
6566
}
6667

@@ -69,7 +70,7 @@ public function analyze(Registry $registryBefore, Registry $registryAfter)
6970
// Difference in source code
7071
if ($functionBefore->stmts != $functionAfter->stmts) {
7172
$data = new FunctionImplementationChanged($fileBefore, $functionBefore, $fileAfter, $functionAfter);
72-
$report->addFunction($data, Level::PATCH);
73+
$report->addFunction($data);
7374
continue;
7475
}
7576

@@ -84,7 +85,7 @@ public function analyze(Registry $registryBefore, Registry $registryAfter)
8485
$functionAfter = $registryAfter->data['function'][$key];
8586

8687
$data = new FunctionAdded($fileAfter, $functionAfter);
87-
$report->addFunction($data, Level::MINOR);
88+
$report->addFunction($data);
8889
}
8990

9091
return $report;

src/PHPSemVerChecker/Analyzer/InterfaceAnalyzer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function analyze(Registry $registryBefore, Registry $registryAfter)
2727
$interfaceBefore = $registryBefore->data['interface'][$key];
2828

2929
$data = new InterfaceRemoved($fileBefore, $interfaceBefore);
30-
$report->addInterface($data, Level::MAJOR);
30+
$report->addInterface($data);
3131
}
3232

3333
foreach ($toVerify as $key) {
@@ -51,7 +51,7 @@ public function analyze(Registry $registryBefore, Registry $registryAfter)
5151
$interfaceAfter = $registryAfter->data['interface'][$key];
5252

5353
$data = new InterfaceAdded($fileAfter, $interfaceAfter);
54-
$report->addInterface($data, Level::MAJOR);
54+
$report->addInterface($data);
5555
}
5656

5757
return $report;

src/PHPSemVerChecker/Analyzer/TraitAnalyzer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function analyze(Registry $registryBefore, Registry $registryAfter)
2727
$traitBefore = $registryBefore->data['trait'][$key];
2828

2929
$data = new TraitRemoved($fileBefore, $traitBefore);
30-
$report->addTrait($data, Level::MAJOR);
30+
$report->addTrait($data);
3131
}
3232

3333
foreach ($toVerify as $key) {
@@ -51,7 +51,7 @@ public function analyze(Registry $registryBefore, Registry $registryAfter)
5151
$traitAfter = $registryAfter->data['trait'][$key];
5252

5353
$data = new TraitAdded($fileAfter, $traitAfter);
54-
$report->addTrait($data, Level::MINOR);
54+
$report->addTrait($data);
5555
}
5656

5757
return $report;

src/PHPSemVerChecker/Operation/ClassAdded.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33
namespace PHPSemVerChecker\Operation;
44

55
use PhpParser\Node\Stmt\Class_;
6+
use PHPSemVerChecker\SemanticVersioning\Level;
67

78
class ClassAdded extends Operation {
89
/**
910
* @var string
1011
*/
1112
protected $code = 'V014';
13+
/**
14+
* @var int
15+
*/
16+
protected $level = Level::MINOR;
1217
/**
1318
* @var string
1419
*/

src/PHPSemVerChecker/Operation/ClassMethodAdded.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,25 @@
44

55
use PhpParser\Node\Stmt;
66
use PhpParser\Node\Stmt\ClassMethod;
7+
use PHPSemVerChecker\SemanticVersioning\Level;
78

89
class ClassMethodAdded extends ClassMethodOperation {
910
/**
1011
* @var array
1112
*/
1213
protected $code = [
13-
'class' => 'V015',
14-
'interface' => 'V034',
15-
'trait' => 'V047',
14+
'class' => ['V015', 'V016', 'V028'],
15+
'interface' => ['V034'],
16+
'trait' => ['V047', 'V048', 'V057'],
1617
];
1718
/**
18-
* @var string
19+
* @var int
1920
*/
20-
protected $context;
21+
protected $level = [
22+
'class' => [Level::MINOR, Level::MINOR, Level::MINOR],
23+
'interface' => [Level::MAJOR],
24+
'trait' => [Level::MINOR, Level::MINOR, Level::MINOR],
25+
];
2126
/**
2227
* @var string
2328
*/
@@ -33,20 +38,21 @@ class ClassMethodAdded extends ClassMethodOperation {
3338
/**
3439
* @var \PhpParser\Node\Stmt\ClassMethod
3540
*/
36-
protected $classMethod;
41+
protected $classMethodAfter;
3742

3843
/**
3944
* @param string $context
4045
* @param string $fileAfter
4146
* @param \PhpParser\Node\Stmt $contextAfter
42-
* @param \PhpParser\Node\Stmt\ClassMethod $classMethod
47+
* @param \PhpParser\Node\Stmt\ClassMethod $classMethodAfter
4348
*/
44-
public function __construct($context, $fileAfter, Stmt $contextAfter, ClassMethod $classMethod)
49+
public function __construct($context, $fileAfter, Stmt $contextAfter, ClassMethod $classMethodAfter)
4550
{
4651
$this->context = $context;
52+
$this->visibility = $this->getVisibility($classMethodAfter);
4753
$this->fileAfter = $fileAfter;
4854
$this->contextAfter = $contextAfter;
49-
$this->classMethod = $classMethod;
55+
$this->classMethodAfter = $classMethodAfter;
5056
}
5157

5258
/**
@@ -62,7 +68,7 @@ public function getLocation()
6268
*/
6369
public function getLine()
6470
{
65-
return $this->classMethod->getLine();
71+
return $this->classMethodAfter->getLine();
6672
}
6773

6874
/**
@@ -74,6 +80,6 @@ public function getTarget()
7480
if ($this->contextAfter->namespacedName) {
7581
$fqcn = $this->contextAfter->namespacedName->toString();
7682
}
77-
return $fqcn . '::' . $this->classMethod->name;
83+
return $fqcn . '::' . $this->classMethodAfter->name;
7884
}
7985
}

src/PHPSemVerChecker/Operation/ClassMethodImplementationChanged.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,25 @@
22

33
namespace PHPSemVerChecker\Operation;
44

5-
use PhpParser\Node\Stmt\Stmt;
5+
use PhpParser\Node\Stmt;
66
use PhpParser\Node\Stmt\ClassMethod;
7+
use PHPSemVerChecker\SemanticVersioning\Level;
78

89
class ClassMethodImplementationChanged extends ClassMethodOperation {
910
/**
1011
* @var array
1112
*/
1213
protected $code = [
13-
'class' => 'V023',
14-
'trait' => 'V038',
14+
'class' => ['V023', 'V024', 'V025'],
15+
'trait' => ['V052', 'V053', 'V054'],
1516
];
1617
/**
17-
* @var string
18+
* @var int
1819
*/
19-
protected $context;
20+
protected $level = [
21+
'class' => [Level::PATCH, Level::PATCH, Level::PATCH],
22+
'trait' => [Level::PATCH, Level::PATCH, Level::PATCH],
23+
];
2024
/**
2125
* @var string
2226
*/
@@ -26,7 +30,7 @@ class ClassMethodImplementationChanged extends ClassMethodOperation {
2630
*/
2731
protected $fileBefore;
2832
/**
29-
* @var \PhpParser\Node\Stmt
33+
* @var Stmt
3034
*/
3135
protected $contextBefore;
3236
/**
@@ -38,7 +42,7 @@ class ClassMethodImplementationChanged extends ClassMethodOperation {
3842
*/
3943
protected $fileAfter;
4044
/**
41-
* @var \PhpParser\Node\Stmt
45+
* @var Stmt
4246
*/
4347
protected $contextAfter;
4448
/**
@@ -55,9 +59,16 @@ class ClassMethodImplementationChanged extends ClassMethodOperation {
5559
* @param \PhpParser\Node\Stmt $contextAfter
5660
* @param \PhpParser\Node\Stmt\ClassMethod $classMethodAfter
5761
*/
58-
public function __construct($context, $fileBefore, \PhpParser\Node\Stmt $contextBefore, ClassMethod $classMethodBefore, $fileAfter, \PhpParser\Node\Stmt $contextAfter, ClassMethod $classMethodAfter)
62+
public function __construct($context,
63+
$fileBefore,
64+
Stmt $contextBefore,
65+
ClassMethod $classMethodBefore,
66+
$fileAfter,
67+
Stmt $contextAfter,
68+
ClassMethod $classMethodAfter)
5969
{
6070
$this->context = $context;
71+
$this->visibility = $this->getVisibility($classMethodAfter);
6172
$this->fileBefore = $fileBefore;
6273
$this->contextBefore = $contextBefore;
6374
$this->classMethodBefore = $classMethodBefore;

0 commit comments

Comments
 (0)