Skip to content

Commit 6e7e092

Browse files
committed
Extracted getTarget duplicate code to new classes.
1 parent ef5795e commit 6e7e092

26 files changed

+137
-96
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace PHPSemVerChecker\Node\Statement;
4+
5+
use PhpParser\Node\Stmt;
6+
use PhpParser\Node\Stmt\ClassMethod as BaseClassMethod;
7+
8+
class ClassMethod {
9+
public static function getFullyQualifiedName(Stmt $context, BaseClassMethod $classMethod)
10+
{
11+
$fqcn = $context->name;
12+
if ($context->namespacedName) {
13+
$fqcn = $context->namespacedName->toString();
14+
}
15+
return $fqcn . '::' . $classMethod->name;
16+
}
17+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace PHPSemVerChecker\Node\Statement;
4+
5+
use PhpParser\Node\Stmt\Class_ as BaseClass;
6+
7+
class Class_ {
8+
public static function getFullyQualifiedName(BaseClass $class)
9+
{
10+
if ($class->namespacedName) {
11+
return $class->namespacedName->toString();
12+
}
13+
return $class->name;
14+
}
15+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace PHPSemVerChecker\Node\Statement;
4+
5+
use PhpParser\Node\Stmt\Function_ as BaseFunction;
6+
7+
class Function_ {
8+
public static function getFullyQualifiedName(BaseFunction $function)
9+
{
10+
$fqfn = '';
11+
if ($function->namespacedName) {
12+
$fqfn = $function->namespacedName->toString() . '::';
13+
}
14+
return $fqfn . $function->name;
15+
}
16+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace PHPSemVerChecker\Node\Statement;
4+
5+
use PhpParser\Node\Stmt\Interface_ as BaseInterface;
6+
7+
class Interface_ {
8+
public static function getFullyQualifiedName(BaseInterface $interface)
9+
{
10+
if ($interface->namespacedName) {
11+
return $interface->namespacedName->toString();
12+
}
13+
return $interface->name;
14+
}
15+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace PHPSemVerChecker\Node\Statement;
4+
5+
use PhpParser\Node\Stmt;
6+
use PhpParser\Node\Stmt\Property as BaseProperty;
7+
8+
class Property {
9+
public static function getFullyQualifiedName(Stmt $context, BaseProperty $property)
10+
{
11+
$fqcn = $context->name;
12+
if ($context->namespacedName) {
13+
$fqcn = $context->namespacedName->toString();
14+
}
15+
return $fqcn . '::$' . $property->props[0]->name;
16+
}
17+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace PHPSemVerChecker\Node\Statement;
4+
5+
use PhpParser\Node\Stmt\Trait_ as BaseTrait;
6+
7+
class Trait_ {
8+
public static function getFullyQualifiedName(BaseTrait $trait)
9+
{
10+
if ($trait->namespacedName) {
11+
return $trait->namespacedName->toString();
12+
}
13+
return $trait->name;
14+
}
15+
}

src/PHPSemVerChecker/Operation/ClassAdded.php

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

55
use PhpParser\Node\Stmt\Class_;
6+
use PHPSemVerChecker\Node\Statement\Class_ as PClass;
67
use PHPSemVerChecker\SemanticVersioning\Level;
78

89
class ClassAdded extends Operation {
@@ -58,10 +59,6 @@ public function getLine()
5859
*/
5960
public function getTarget()
6061
{
61-
$fqcn = $this->classAfter->name;
62-
if ($this->classAfter->namespacedName) {
63-
$fqcn = $this->classAfter->namespacedName->toString();
64-
}
65-
return $fqcn;
62+
return PClass::getFullyQualifiedName($this->classAfter);
6663
}
6764
}

src/PHPSemVerChecker/Operation/ClassMethodAdded.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PhpParser\Node\Stmt;
66
use PhpParser\Node\Stmt\ClassMethod;
7+
use PHPSemVerChecker\Node\Statement\ClassMethod as PClassMethod;
78
use PHPSemVerChecker\SemanticVersioning\Level;
89

910
class ClassMethodAdded extends ClassMethodOperation {
@@ -76,10 +77,6 @@ public function getLine()
7677
*/
7778
public function getTarget()
7879
{
79-
$fqcn = $this->contextAfter->name;
80-
if ($this->contextAfter->namespacedName) {
81-
$fqcn = $this->contextAfter->namespacedName->toString();
82-
}
83-
return $fqcn . '::' . $this->classMethodAfter->name;
80+
return PClassMethod::getFullyQualifiedName($this->contextAfter, $this->classMethodAfter);
8481
}
8582
}

src/PHPSemVerChecker/Operation/ClassMethodImplementationChanged.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PhpParser\Node\Stmt;
66
use PhpParser\Node\Stmt\ClassMethod;
7+
use PHPSemVerChecker\Node\Statement\ClassMethod as PClassMethod;
78
use PHPSemVerChecker\SemanticVersioning\Level;
89

910
class ClassMethodImplementationChanged extends ClassMethodOperation {
@@ -98,10 +99,6 @@ public function getLine()
9899
*/
99100
public function getTarget()
100101
{
101-
$fqcn = $this->contextAfter->name;
102-
if ($this->contextAfter->namespacedName) {
103-
$fqcn = $this->contextAfter->namespacedName->toString();
104-
}
105-
return $fqcn . '::' . $this->classMethodBefore->name;
102+
return PClassMethod::getFullyQualifiedName($this->contextAfter, $this->classMethodAfter);
106103
}
107104
}

src/PHPSemVerChecker/Operation/ClassMethodParameterChanged.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PhpParser\Node\Stmt;
66
use PhpParser\Node\Stmt\ClassMethod;
7+
use PHPSemVerChecker\Node\Statement\ClassMethod as PClassMethod;
78
use PHPSemVerChecker\SemanticVersioning\Level;
89

910
class ClassMethodParameterChanged extends ClassMethodOperation {
@@ -100,10 +101,6 @@ public function getLine()
100101
*/
101102
public function getTarget()
102103
{
103-
$fqcn = $this->contextAfter->name;
104-
if ($this->contextAfter->namespacedName) {
105-
$fqcn = $this->contextAfter->namespacedName->toString();
106-
}
107-
return $fqcn . '::' . $this->classMethodBefore->name;
104+
return PClassMethod::getFullyQualifiedName($this->contextAfter, $this->classMethodAfter);
108105
}
109106
}

0 commit comments

Comments
 (0)