Skip to content

Commit fbdb940

Browse files
committed
Make TraitRenamedCaseOnly extend Delta
1 parent a15c6b7 commit fbdb940

File tree

3 files changed

+69
-47
lines changed

3 files changed

+69
-47
lines changed

src/PHPSemVerChecker/Analyzer/TraitAnalyzer.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,25 @@ public function analyze(Registry $registryBefore, Registry $registryAfter)
5858

5959
foreach ($toVerify as $key) {
6060
$fileBefore = $filesBeforeKeyed[$key];
61-
/** @var \PhpParser\Node\Stmt\Class_ $traitBefore */
6261
$traitBefore = $traitsBeforeKeyed[$key];
6362
$fileAfter = $filesAfterKeyed[$key];
64-
/** @var \PhpParser\Node\Stmt\Class_ $traitBefore */
6563
$traitAfter = $traitsAfterKeyed[$key];
6664

6765
// Leave non-strict comparison here
6866
if ($traitBefore != $traitAfter) {
6967

7068
// Check for name case change.
7169
// If we entered this section then the normalized names (lowercase) were equal.
72-
if($traitBefore->name !== $traitAfter->name) {
73-
$report->add($this->context, new TraitRenamedCaseOnly($fileAfter, $traitAfter));
70+
if ($traitBefore->name !== $traitAfter->name) {
71+
$report->add(
72+
$this->context,
73+
new TraitRenamedCaseOnly(
74+
$fileBefore,
75+
$traitBefore,
76+
$fileAfter,
77+
$traitAfter
78+
)
79+
);
7480
}
7581

7682
$analyzers = [
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
namespace PHPSemVerChecker\Operation;
4+
5+
use PhpParser\Node\Stmt\Trait_;
6+
use PHPSemVerChecker\Node\Statement\Trait_ as PTrait;
7+
8+
class TraitOperationDelta extends Operation
9+
{
10+
/**
11+
* @var string
12+
*/
13+
protected $fileBefore;
14+
/**
15+
* @var \PhpParser\Node\Stmt\Trait_
16+
*/
17+
protected $traitBefore;
18+
/**
19+
* @var string
20+
*/
21+
protected $fileAfter;
22+
/**
23+
* @var \PhpParser\Node\Stmt\Trait_
24+
*/
25+
protected $traitAfter;
26+
27+
public function __construct($fileBefore, Trait_ $traitBefore, $fileAfter, Trait_ $traitAfter)
28+
{
29+
$this->fileBefore = $fileBefore;
30+
$this->traitBefore = $traitBefore;
31+
$this->fileAfter = $fileAfter;
32+
$this->traitAfter = $traitAfter;
33+
}
34+
35+
/**
36+
* @return string
37+
*/
38+
public function getLocation()
39+
{
40+
return $this->fileAfter;
41+
}
42+
43+
/**
44+
* @return int
45+
*/
46+
public function getLine()
47+
{
48+
return $this->traitAfter->getLine();
49+
}
50+
51+
/**
52+
* @return string
53+
*/
54+
public function getTarget()
55+
{
56+
return PTrait::getFullyQualifiedName($this->traitAfter);
57+
}
58+
}

src/PHPSemVerChecker/Operation/TraitRenamedCaseOnly.php

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use PhpParser\Node\Stmt\Trait_;
66
use PHPSemVerChecker\Node\Statement\Trait_ as PTrait;
77

8-
class TraitRenamedCaseOnly extends Operation {
8+
class TraitRenamedCaseOnly extends TraitOperationDelta {
99
/**
1010
* @var string
1111
*/
@@ -14,46 +14,4 @@ class TraitRenamedCaseOnly extends Operation {
1414
* @var string
1515
*/
1616
protected $reason = 'Trait was renamed (case only).';
17-
/**
18-
* @var string
19-
*/
20-
protected $fileAfter;
21-
/**
22-
* @var \PhpParser\Node\Stmt\Trait_
23-
*/
24-
protected $traitAfter;
25-
26-
/**
27-
* @param string $fileAfter
28-
* @param \PhpParser\Node\Stmt\Trait_ $traitAfter
29-
*/
30-
public function __construct($fileAfter, Trait_ $traitAfter)
31-
{
32-
$this->fileAfter = $fileAfter;
33-
$this->traitAfter = $traitAfter;
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->traitAfter->getLine();
50-
}
51-
52-
/**
53-
* @return string
54-
*/
55-
public function getTarget()
56-
{
57-
return PTrait::getFullyQualifiedName($this->traitAfter);
58-
}
5917
}

0 commit comments

Comments
 (0)