Skip to content

Commit bd90707

Browse files
committed
[#14] Separate the target (what) from the location (where)
Added a new column to the output, named Target. This change makes it easy to quickly see what class/method/function are affected.
1 parent 7e87015 commit bd90707

15 files changed

+198
-52
lines changed

src/PHPSemVerChecker/Console/Command/CompareCommand.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace PHPSemVerChecker\Console\Command;
44

55
use File_Iterator_Facade;
6-
use PHPSemVerChecker\Registry\Registry;
76
use PHPSemVerChecker\Reporter\Reporter;
87
use PHPSemVerChecker\Scanner\Scanner;
98
use Symfony\Component\Console\Command\Command;

src/PHPSemVerChecker/Operation/ClassAdded.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,19 @@ public function __construct($fileAfter, Class_ $classAfter)
3232
* @return string
3333
*/
3434
public function getLocation()
35+
{
36+
return $this->fileAfter . '#' . $this->classAfter->getLine();
37+
}
38+
39+
/**
40+
* @return string
41+
*/
42+
public function getTarget()
3543
{
3644
$fqcn = $this->classAfter->name;
3745
if ($this->classAfter->namespacedName) {
3846
$fqcn = $this->classAfter->namespacedName->toString();
3947
}
40-
return $this->fileAfter . '#' . $this->classAfter->getLine() . ' ' . $fqcn;
48+
return $fqcn;
4149
}
4250
}

src/PHPSemVerChecker/Operation/ClassMethodAdded.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,19 @@ public function __construct($fileAfter, Class_ $classAfter, ClassMethod $classMe
3939
* @return string
4040
*/
4141
public function getLocation()
42+
{
43+
return $this->fileAfter . '#' . $this->classMethod->getLine();
44+
}
45+
46+
/**
47+
* @return string
48+
*/
49+
public function getTarget()
4250
{
4351
$fqcn = $this->classAfter->name;
4452
if ($this->classAfter->namespacedName) {
4553
$fqcn = $this->classAfter->namespacedName->toString();
4654
}
47-
return $this->fileAfter . '#' . $this->classMethod->getLine() . ' ' . $fqcn . '::' . $this->classMethod->name;
55+
return $fqcn . '::' . $this->classMethod->name;
4856
}
4957
}

src/PHPSemVerChecker/Operation/ClassMethodImplementationChanged.php

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PHPSemVerChecker\Operation;
44

5+
use PhpParser\Node\Stmt\Class_;
56
use PhpParser\Node\Stmt\ClassMethod;
67

78
class ClassMethodImplementationChanged extends Operation {
@@ -12,31 +13,43 @@ class ClassMethodImplementationChanged extends Operation {
1213
/**
1314
* @var string
1415
*/
15-
private $fileBefore;
16+
protected $fileBefore;
17+
/**
18+
* @var \PhpParser\Node\Stmt\Class_
19+
*/
20+
protected $classBefore;
1621
/**
1722
* @var \PhpParser\Node\Stmt\ClassMethod
1823
*/
19-
private $classMethodBefore;
24+
protected $classMethodBefore;
2025
/**
2126
* @var string
2227
*/
23-
private $fileAfter;
28+
protected $fileAfter;
29+
/**
30+
* @var \PhpParser\Node\Stmt\Class_
31+
*/
32+
protected $classAfter;
2433
/**
2534
* @var \PhpParser\Node\Stmt\ClassMethod
2635
*/
27-
private $classMethodAfter;
36+
protected $classMethodAfter;
2837

2938
/**
3039
* @param string $fileBefore
40+
* @param \PhpParser\Node\Stmt\Class_ $classBefore
3141
* @param \PhpParser\Node\Stmt\ClassMethod $classMethodBefore
3242
* @param string $fileAfter
43+
* @param \PhpParser\Node\Stmt\Class_ $classAfter
3344
* @param \PhpParser\Node\Stmt\ClassMethod $classMethodAfter
3445
*/
35-
public function __construct($fileBefore, ClassMethod $classMethodBefore, $fileAfter, ClassMethod $classMethodAfter)
46+
public function __construct($fileBefore, Class_ $classBefore, ClassMethod $classMethodBefore, $fileAfter, Class_ $classAfter, ClassMethod $classMethodAfter)
3647
{
3748
$this->fileBefore = $fileBefore;
49+
$this->classBefore = $classBefore;
3850
$this->classMethodBefore = $classMethodBefore;
3951
$this->fileAfter = $fileAfter;
52+
$this->classAfter = $classAfter;
4053
$this->classMethodAfter = $classMethodAfter;
4154
}
4255

@@ -45,6 +58,18 @@ public function __construct($fileBefore, ClassMethod $classMethodBefore, $fileAf
4558
*/
4659
public function getLocation()
4760
{
48-
return $this->fileAfter . '#' . $this->classMethodAfter->getLine() . ' ' . $this->classMethodAfter->name;
61+
return $this->fileAfter . '#' . $this->classMethodAfter->getLine();
62+
}
63+
64+
/**
65+
* @return string
66+
*/
67+
public function getTarget()
68+
{
69+
$fqcn = $this->classAfter->name;
70+
if ($this->classAfter->namespacedName) {
71+
$fqcn = $this->classAfter->namespacedName->toString();
72+
}
73+
return $fqcn . '::' . $this->classMethodBefore->name;
4974
}
5075
}

src/PHPSemVerChecker/Operation/ClassMethodParameterMismatch.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PHPSemVerChecker\Operation;
44

5+
use PhpParser\Node\Stmt\Class_;
56
use PhpParser\Node\Stmt\ClassMethod;
67

78
class ClassMethodParameterMismatch extends Operation {
@@ -13,6 +14,10 @@ class ClassMethodParameterMismatch extends Operation {
1314
* @var string
1415
*/
1516
protected $fileBefore;
17+
/**
18+
* @var \PhpParser\Node\Stmt\Class_
19+
*/
20+
protected $classBefore;
1621
/**
1722
* @var \PhpParser\Node\Stmt\ClassMethod
1823
*/
@@ -21,22 +26,30 @@ class ClassMethodParameterMismatch extends Operation {
2126
* @var string
2227
*/
2328
protected $fileAfter;
29+
/**
30+
* @var \PhpParser\Node\Stmt\Class_
31+
*/
32+
protected $classAfter;
2433
/**
2534
* @var \PhpParser\Node\Stmt\ClassMethod
2635
*/
2736
protected $classMethodAfter;
2837

2938
/**
3039
* @param string $fileBefore
40+
* @param \PhpParser\Node\Stmt\Class_ $classBefore
3141
* @param \PhpParser\Node\Stmt\ClassMethod $classMethodBefore
3242
* @param string $fileAfter
43+
* @param \PhpParser\Node\Stmt\Class_ $classAfter
3344
* @param \PhpParser\Node\Stmt\ClassMethod $classMethodAfter
3445
*/
35-
public function __construct($fileBefore, ClassMethod $classMethodBefore, $fileAfter, ClassMethod $classMethodAfter)
46+
public function __construct($fileBefore, Class_ $classBefore, ClassMethod $classMethodBefore, $fileAfter, Class_ $classAfter, ClassMethod $classMethodAfter)
3647
{
3748
$this->fileBefore = $fileBefore;
49+
$this->classBefore = $classBefore;
3850
$this->classMethodBefore = $classMethodBefore;
3951
$this->fileAfter = $fileAfter;
52+
$this->classAfter = $classAfter;
4053
$this->classMethodAfter = $classMethodAfter;
4154
}
4255

@@ -45,6 +58,18 @@ public function __construct($fileBefore, ClassMethod $classMethodBefore, $fileAf
4558
*/
4659
public function getLocation()
4760
{
48-
return $this->fileAfter . '#' . $this->classMethodAfter->getLine() . ' ' . $this->classMethodAfter->name;
61+
return $this->fileAfter . '#' . $this->classMethodAfter->getLine();
62+
}
63+
64+
/**
65+
* @return string
66+
*/
67+
public function getTarget()
68+
{
69+
$fqcn = $this->classAfter->name;
70+
if ($this->classAfter->namespacedName) {
71+
$fqcn = $this->classAfter->namespacedName->toString();
72+
}
73+
return $fqcn . '::' . $this->classMethodBefore->name;
4974
}
5075
}

src/PHPSemVerChecker/Operation/ClassMethodRemoved.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,19 @@ public function __construct($fileBefore, Class_ $classBefore, ClassMethod $class
3939
* @return string
4040
*/
4141
public function getLocation()
42+
{
43+
return $this->fileBefore . '#' . $this->classMethodBefore->getLine();
44+
}
45+
46+
/**
47+
* @return string
48+
*/
49+
public function getTarget()
4250
{
4351
$fqcn = $this->classBefore->name;
4452
if ($this->classBefore->namespacedName) {
4553
$fqcn = $this->classBefore->namespacedName->toString();
4654
}
47-
return $this->fileBefore . '#' . $this->classMethodBefore->getLine() . ' ' . $fqcn . '::' . $this->classMethodBefore->name;
55+
return $fqcn . '::' . $this->classMethodBefore->name;
4856
}
4957
}

src/PHPSemVerChecker/Operation/ClassRemoved.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,19 @@ public function __construct($fileBefore, Class_ $classBefore)
3232
* @return string
3333
*/
3434
public function getLocation()
35+
{
36+
return $this->fileBefore . '#' . $this->classBefore->getLine();
37+
}
38+
39+
/**
40+
* @return string
41+
*/
42+
public function getTarget()
3543
{
3644
$fqcn = $this->classBefore->name;
3745
if ($this->classBefore->namespacedName) {
3846
$fqcn = $this->classBefore->namespacedName->toString();
3947
}
40-
return $this->fileBefore . '#' . $this->classBefore->getLine() . ' ' . $fqcn;
48+
return $fqcn;
4149
}
4250
}

src/PHPSemVerChecker/Operation/FunctionAdded.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,20 @@ public function __construct($fileAfter, Function_ $functionAfter)
3232
* @return string
3333
*/
3434
public function getLocation()
35+
{
36+
37+
return $this->fileAfter . '#' . $this->functionAfter->getLine();
38+
}
39+
40+
/**
41+
* @return string
42+
*/
43+
public function getTarget()
3544
{
3645
$fqfn = $this->functionAfter->name;
3746
if ($this->functionAfter->namespacedName) {
3847
$fqfn = $this->functionAfter->namespacedName->toString() . '::' . $this->functionAfter->name;
3948
}
40-
return $this->fileAfter . '#' . $this->functionAfter->getLine() . ' ' . $fqfn;
49+
return $fqfn;
4150
}
4251
}

src/PHPSemVerChecker/Operation/FunctionImplementationChanged.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ class FunctionImplementationChanged extends Operation {
1313
/**
1414
* @var \PhpParser\Node\Stmt\Function_
1515
*/
16-
private $functionAfter;
16+
protected $functionAfter;
1717
/**
1818
* @var string
1919
*/
20-
private $fileAfter;
20+
protected $fileAfter;
2121
/**
2222
* @var \PhpParser\Node\Stmt\Function_
2323
*/
24-
private $functionBefore;
24+
protected $functionBefore;
2525
/**
2626
* @var string
2727
*/
28-
private $fileBefore;
28+
protected $fileBefore;
2929

3030
/**
3131
* @param string $fileBefore
@@ -45,11 +45,19 @@ public function __construct($fileBefore, Function_ $functionBefore, $fileAfter,
4545
* @return string
4646
*/
4747
public function getLocation()
48+
{
49+
return $this->fileAfter . '#' . $this->functionAfter->getLine();
50+
}
51+
52+
/**
53+
* @return string
54+
*/
55+
public function getTarget()
4856
{
4957
$fqfn = $this->functionAfter->name;
5058
if ($this->functionAfter->namespacedName) {
5159
$fqfn = $this->functionAfter->namespacedName->toString() . '::' . $this->functionAfter->name;
5260
}
53-
return $this->fileAfter . '#' . $this->functionAfter->getLine() . ' ' . $fqfn;
61+
return $fqfn;
5462
}
5563
}

src/PHPSemVerChecker/Operation/FunctionParameterMismatch.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,19 @@ public function __construct($fileBefore, Function_ $functionBefore, $fileAfter,
4444
* @return string
4545
*/
4646
public function getLocation()
47+
{
48+
return $this->fileBefore . '#' . $this->functionAfter->getLine();
49+
}
50+
51+
/**
52+
* @return string
53+
*/
54+
public function getTarget()
4755
{
4856
$fqfn = $this->functionAfter->name;
4957
if ($this->functionAfter->namespacedName) {
5058
$fqfn = $this->functionAfter->namespacedName->toString() . '::' . $this->functionAfter->name;
5159
}
52-
return $this->fileBefore . '#' . $this->functionAfter->getLine() . ' ' . $fqfn;
60+
return $fqfn;
5361
}
5462
}

0 commit comments

Comments
 (0)