Skip to content

Commit 7944fd1

Browse files
committed
Generalize unary operations on classes, interfaces, properties and traits.
1 parent 1aabf1e commit 7944fd1

15 files changed

+224
-398
lines changed

src/PHPSemVerChecker/Operation/ClassAdded.php

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
namespace PHPSemVerChecker\Operation;
44

5-
use PhpParser\Node\Stmt\Class_;
6-
use PHPSemVerChecker\Node\Statement\Class_ as PClass;
7-
8-
class ClassAdded extends Operation {
5+
class ClassAdded extends ClassOperationUnary {
96
/**
107
* @var string
118
*/
@@ -14,46 +11,4 @@ class ClassAdded extends Operation {
1411
* @var string
1512
*/
1613
protected $reason = 'Class was added.';
17-
/**
18-
* @var string
19-
*/
20-
protected $fileAfter;
21-
/**
22-
* @var \PhpParser\Node\Stmt\Class_
23-
*/
24-
protected $classAfter;
25-
26-
/**
27-
* @param string $fileAfter
28-
* @param \PhpParser\Node\Stmt\Class_ $classAfter
29-
*/
30-
public function __construct($fileAfter, Class_ $classAfter)
31-
{
32-
$this->fileAfter = $fileAfter;
33-
$this->classAfter = $classAfter;
34-
}
35-
36-
/**
37-
* @return string
38-
*/
39-
public function getLocation()
40-
{
41-
return $this->fileAfter;
42-
}
43-
44-
/**
45-
* @return int
46-
*/
47-
public function getLine()
48-
{
49-
return $this->classAfter->getLine();
50-
}
51-
52-
/**
53-
* @return string
54-
*/
55-
public function getTarget()
56-
{
57-
return PClass::getFullyQualifiedName($this->classAfter);
58-
}
5914
}

src/PHPSemVerChecker/Operation/ClassMethodRemoved.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
namespace PHPSemVerChecker\Operation;
44

5-
use PhpParser\Node\Stmt;
6-
use PhpParser\Node\Stmt\ClassMethod;
7-
use PHPSemVerChecker\Node\Statement\ClassMethod as PClassMethod;
8-
95
class ClassMethodRemoved extends ClassMethodOperationUnary {
106
/**
117
* @var array
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace PHPSemVerChecker\Operation;
4+
5+
use PhpParser\Node\Stmt\Class_;
6+
use PHPSemVerChecker\Node\Statement\Class_ as PClass;
7+
8+
class ClassOperationUnary extends Operation
9+
{
10+
/**
11+
* @var string
12+
*/
13+
protected $file;
14+
/**
15+
* @var \PhpParser\Node\Stmt\Class_
16+
*/
17+
protected $class;
18+
19+
/**
20+
* @param string $file
21+
* @param \PhpParser\Node\Stmt\Class_ $class
22+
*/
23+
public function __construct($file, Class_ $class)
24+
{
25+
$this->file = $file;
26+
$this->class = $class;
27+
}
28+
29+
/**
30+
* @return string
31+
*/
32+
public function getLocation()
33+
{
34+
return $this->file;
35+
}
36+
37+
/**
38+
* @return int
39+
*/
40+
public function getLine()
41+
{
42+
return $this->class->getLine();
43+
}
44+
45+
/**
46+
* @return string
47+
*/
48+
public function getTarget()
49+
{
50+
return PClass::getFullyQualifiedName($this->class);
51+
}
52+
}

src/PHPSemVerChecker/Operation/ClassRemoved.php

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
namespace PHPSemVerChecker\Operation;
44

5-
use PhpParser\Node\Stmt\Class_;
6-
use PHPSemVerChecker\Node\Statement\Class_ as PClass;
7-
8-
class ClassRemoved extends Operation {
5+
class ClassRemoved extends ClassOperationUnary {
96
/**
107
* @var string
118
*/
@@ -14,46 +11,4 @@ class ClassRemoved extends Operation {
1411
* @var string
1512
*/
1613
protected $reason = 'Class was removed.';
17-
/**
18-
* @var string
19-
*/
20-
protected $fileBefore;
21-
/**
22-
* @var \PhpParser\Node\Stmt\Class_
23-
*/
24-
protected $classBefore;
25-
26-
/**
27-
* @param string $fileBefore
28-
* @param \PhpParser\Node\Stmt\Class_ $classBefore
29-
*/
30-
public function __construct($fileBefore, Class_ $classBefore)
31-
{
32-
$this->fileBefore = $fileBefore;
33-
$this->classBefore = $classBefore;
34-
}
35-
36-
/**
37-
* @return string
38-
*/
39-
public function getLocation()
40-
{
41-
return $this->fileBefore;
42-
}
43-
44-
/**
45-
* @return int
46-
*/
47-
public function getLine()
48-
{
49-
return $this->classBefore->getLine();
50-
}
51-
52-
/**
53-
* @return string
54-
*/
55-
public function getTarget()
56-
{
57-
return PClass::getFullyQualifiedName($this->classBefore);
58-
}
5914
}

src/PHPSemVerChecker/Operation/FunctionImplementationChanged.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
namespace PHPSemVerChecker\Operation;
44

5-
use PhpParser\Node\Stmt\Function_;
6-
use PHPSemVerChecker\Node\Statement\Function_ as PFunction;
7-
85
class FunctionImplementationChanged extends FunctionOperationDelta {
96
/**
107
* @var string

src/PHPSemVerChecker/Operation/FunctionParameterRemoved.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
namespace PHPSemVerChecker\Operation;
44

5-
use PhpParser\Node\Stmt\Function_;
6-
use PHPSemVerChecker\Node\Statement\Function_ as PFunction;
7-
85
class FunctionParameterRemoved extends FunctionOperationUnary
96
{
107
/**

src/PHPSemVerChecker/Operation/InterfaceAdded.php

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
namespace PHPSemVerChecker\Operation;
44

5-
use PhpParser\Node\Stmt\Interface_;
6-
use PHPSemVerChecker\Node\Statement\Interface_ as PInterface;
7-
8-
class InterfaceAdded extends Operation {
5+
class InterfaceAdded extends InterfaceOperationUnary {
96
/**
107
* @var string
118
*/
@@ -14,46 +11,4 @@ class InterfaceAdded extends Operation {
1411
* @var string
1512
*/
1613
protected $reason = 'Interface was added.';
17-
/**
18-
* @var string
19-
*/
20-
protected $fileAfter;
21-
/**
22-
* @var \PhpParser\Node\Stmt\Interface_
23-
*/
24-
protected $interfaceAfter;
25-
26-
/**
27-
* @param string $fileAfter
28-
* @param \PhpParser\Node\Stmt\Interface_ $interfaceAfter
29-
*/
30-
public function __construct($fileAfter, Interface_ $interfaceAfter)
31-
{
32-
$this->fileAfter = $fileAfter;
33-
$this->interfaceAfter = $interfaceAfter;
34-
}
35-
36-
/**
37-
* @return string
38-
*/
39-
public function getLocation()
40-
{
41-
return $this->fileAfter;
42-
}
43-
44-
/**
45-
* @return int
46-
*/
47-
public function getLine()
48-
{
49-
return $this->interfaceAfter->getLine();
50-
}
51-
52-
/**
53-
* @return string
54-
*/
55-
public function getTarget()
56-
{
57-
return PInterface::getFullyQualifiedName($this->interfaceAfter);
58-
}
5914
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace PHPSemVerChecker\Operation;
4+
5+
use PhpParser\Node\Stmt\Interface_;
6+
use PHPSemVerChecker\Node\Statement\Interface_ as PInterface;
7+
8+
class InterfaceOperationUnary extends Operation {
9+
/**
10+
* @var string
11+
*/
12+
protected $file;
13+
/**
14+
* @var \PhpParser\Node\Stmt\Interface_
15+
*/
16+
protected $interface;
17+
18+
/**
19+
* @param string $fileAfter
20+
* @param \PhpParser\Node\Stmt\Interface_ $interface
21+
*/
22+
public function __construct($fileAfter, Interface_ $interface)
23+
{
24+
$this->file = $fileAfter;
25+
$this->interface = $interface;
26+
}
27+
28+
/**
29+
* @return string
30+
*/
31+
public function getLocation()
32+
{
33+
return $this->file;
34+
}
35+
36+
/**
37+
* @return int
38+
*/
39+
public function getLine()
40+
{
41+
return $this->interface->getLine();
42+
}
43+
44+
/**
45+
* @return string
46+
*/
47+
public function getTarget()
48+
{
49+
return PInterface::getFullyQualifiedName($this->interface);
50+
}
51+
}

src/PHPSemVerChecker/Operation/InterfaceRemoved.php

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
namespace PHPSemVerChecker\Operation;
44

5-
use PhpParser\Node\Stmt\Interface_;
6-
use PHPSemVerChecker\Node\Statement\Interface_ as PInterface;
7-
8-
class InterfaceRemoved extends Operation {
5+
class InterfaceRemoved extends InterfaceOperationUnary {
96
/**
107
* @var string
118
*/
@@ -14,46 +11,4 @@ class InterfaceRemoved extends Operation {
1411
* @var string
1512
*/
1613
protected $reason = 'Interface was removed.';
17-
/**
18-
* @var string
19-
*/
20-
protected $fileBefore;
21-
/**
22-
* @var \PhpParser\Node\Stmt\Interface_
23-
*/
24-
protected $interfaceBefore;
25-
26-
/**
27-
* @param string $fileBefore
28-
* @param \PhpParser\Node\Stmt\Interface_ $interfaceBefore
29-
*/
30-
public function __construct($fileBefore, Interface_ $interfaceBefore)
31-
{
32-
$this->fileBefore = $fileBefore;
33-
$this->interfaceBefore = $interfaceBefore;
34-
}
35-
36-
/**
37-
* @return string
38-
*/
39-
public function getLocation()
40-
{
41-
return $this->fileBefore;
42-
}
43-
44-
/**
45-
* @return int
46-
*/
47-
public function getLine()
48-
{
49-
return $this->interfaceBefore->getLine();
50-
}
51-
52-
/**
53-
* @return string
54-
*/
55-
public function getTarget()
56-
{
57-
return PInterface::getFullyQualifiedName($this->interfaceBefore);
58-
}
5914
}

0 commit comments

Comments
 (0)