Skip to content

Commit 6d91ae4

Browse files
committed
Code cleanup.
Unused use statement removed.
1 parent 6e7e092 commit 6d91ae4

25 files changed

+59
-83
lines changed

src/PHPSemVerChecker/Analyzer/Analyzer.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
use PHPSemVerChecker\Registry\Registry;
66
use PHPSemVerChecker\Report\Report;
77

8-
class Analyzer
9-
{
8+
class Analyzer {
109
/**
1110
* Compare with a destination registry (what the new source code is like).
1211
*

src/PHPSemVerChecker/Analyzer/ClassAnalyzer.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
use PHPSemVerChecker\Operation\ClassRemoved;
77
use PHPSemVerChecker\Registry\Registry;
88
use PHPSemVerChecker\Report\Report;
9-
use PHPSemVerChecker\SemanticVersioning\Level;
109

11-
class ClassAnalyzer
12-
{
10+
class ClassAnalyzer {
1311
protected $context = 'class';
1412

1513
public function analyze(Registry $registryBefore, Registry $registryAfter)

src/PHPSemVerChecker/Analyzer/ClassMethodAnalyzer.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,21 @@
33
namespace PHPSemVerChecker\Analyzer;
44

55
use PhpParser\Node\Stmt;
6-
use PhpParser\Node\Stmt\Class_;
7-
use PhpParser\Node\Stmt\ClassMethod;
86
use PHPSemVerChecker\Comparator\Signature;
97
use PHPSemVerChecker\Operation\ClassMethodAdded;
108
use PHPSemVerChecker\Operation\ClassMethodImplementationChanged;
119
use PHPSemVerChecker\Operation\ClassMethodParameterChanged;
1210
use PHPSemVerChecker\Operation\ClassMethodParameterNameChanged;
1311
use PHPSemVerChecker\Operation\ClassMethodRemoved;
1412
use PHPSemVerChecker\Report\Report;
15-
use PHPSemVerChecker\SemanticVersioning\Level;
1613

17-
class ClassMethodAnalyzer
18-
{
14+
class ClassMethodAnalyzer {
1915
protected $context;
2016
protected $fileBefore;
2117
protected $fileAfter;
2218

2319
/**
20+
* @param string $context
2421
* @param string $fileBefore
2522
* @param string $fileAfter
2623
*/
@@ -33,7 +30,6 @@ public function __construct($context, $fileBefore = null, $fileAfter = null)
3330

3431
public function analyze(Stmt $contextBefore, Stmt $contextAfter)
3532
{
36-
// TODO: Verify that the given contexts match the context given in the constructor <[email protected]>
3733
$report = new Report();
3834

3935
$methodsBefore = $contextBefore->getMethods();

src/PHPSemVerChecker/Analyzer/FunctionAnalyzer.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
use PHPSemVerChecker\Report\Report;
1414
use PHPSemVerChecker\SemanticVersioning\Level;
1515

16-
class FunctionAnalyzer
17-
{
16+
class FunctionAnalyzer {
1817
protected $context = 'function';
1918

2019
/**
@@ -42,7 +41,6 @@ public function analyze(Registry $registryBefore, Registry $registryAfter)
4241

4342
foreach ($toVerify as $key) {
4443
$fileBefore = $registryBefore->mapping['function'][$key];
45-
/** @var Function_ $functionBefore */
4644
$functionBefore = $registryBefore->data['function'][$key];
4745
$fileAfter = $registryAfter->mapping['function'][$key];
4846
$functionAfter = $registryAfter->data['function'][$key];

src/PHPSemVerChecker/Analyzer/InterfaceAnalyzer.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
use PHPSemVerChecker\Operation\InterfaceRemoved;
77
use PHPSemVerChecker\Registry\Registry;
88
use PHPSemVerChecker\Report\Report;
9-
use PHPSemVerChecker\SemanticVersioning\Level;
109

11-
class InterfaceAnalyzer
12-
{
10+
class InterfaceAnalyzer {
1311
protected $context = 'interface';
1412

1513
public function analyze(Registry $registryBefore, Registry $registryAfter)

src/PHPSemVerChecker/Analyzer/PropertyAnalyzer.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
use PHPSemVerChecker\Operation\PropertyRemoved;
99
use PHPSemVerChecker\Report\Report;
1010

11-
class PropertyAnalyzer
12-
{
11+
class PropertyAnalyzer {
1312
/**
1413
* @var string
1514
*/

src/PHPSemVerChecker/Analyzer/TraitAnalyzer.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
use PHPSemVerChecker\Operation\TraitRemoved;
77
use PHPSemVerChecker\Registry\Registry;
88
use PHPSemVerChecker\Report\Report;
9-
use PHPSemVerChecker\SemanticVersioning\Level;
109

11-
class TraitAnalyzer
12-
{
10+
class TraitAnalyzer {
1311
protected $context = 'trait';
1412

1513
public function analyze(Registry $registryBefore, Registry $registryAfter)

src/PHPSemVerChecker/Comparator/Signature.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
namespace PHPSemVerChecker\Comparator;
44

5-
class Signature
6-
{
5+
class Signature {
76
/**
87
* @param array $paramsA
98
* @param array $paramsB
@@ -42,7 +41,7 @@ public static function isSameVariables(array $paramsA, array $paramsB)
4241

4342
$iterations = min(count($paramsA), count($paramsB));
4443
for ($i = 0; $i < $iterations; ++$i) {
45-
if ( $paramsA[$i]->name != $paramsB[$i]->name) {
44+
if ($paramsA[$i]->name != $paramsB[$i]->name) {
4645
return false;
4746
}
4847
}

src/PHPSemVerChecker/Comparator/Type.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
namespace PHPSemVerChecker\Comparator;
44

5-
class Type
6-
{
5+
class Type {
76
/**
87
* @param \PhpParser\Node\Name|string $typeA
98
* @param \PhpParser\Node\Name|string $typeB

src/PHPSemVerChecker/Console/Command/CompareCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
6363

6464
$duration = microtime(true) - $startTime;
6565
$output->writeln('');
66-
$output->writeln('Time: '.round($duration, 3).' seconds, Memory: '.round(memory_get_peak_usage() / 1024 / 1024, 3).' MB');
66+
$output->writeln('Time: ' . round($duration, 3) . ' seconds, Memory: ' . round(memory_get_peak_usage() / 1024 / 1024, 3) . ' MB');
6767
}
6868
}

src/PHPSemVerChecker/Operation/ClassMethodAdded.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ class ClassMethodAdded extends ClassMethodOperation {
1212
* @var array
1313
*/
1414
protected $code = [
15-
'class' => ['V015', 'V016', 'V028'],
15+
'class' => ['V015', 'V016', 'V028'],
1616
'interface' => ['V034'],
17-
'trait' => ['V047', 'V048', 'V057'],
17+
'trait' => ['V047', 'V048', 'V057'],
1818
];
1919
/**
2020
* @var int
2121
*/
2222
protected $level = [
23-
'class' => [Level::MAJOR, Level::MAJOR, Level::PATCH],
23+
'class' => [Level::MAJOR, Level::MAJOR, Level::PATCH],
2424
'interface' => [Level::MAJOR],
25-
'trait' => [Level::MAJOR, Level::MAJOR, Level::MAJOR],
25+
'trait' => [Level::MAJOR, Level::MAJOR, Level::MAJOR],
2626
];
2727
/**
2828
* @var string

src/PHPSemVerChecker/Operation/ClassMethodOperation.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
use PhpParser\Node\Stmt\Class_;
66
use PhpParser\Node\Stmt\ClassMethod;
77

8-
abstract class ClassMethodOperation extends Operation
9-
{
8+
abstract class ClassMethodOperation extends Operation {
109
/**
1110
* @var string
1211
*/
@@ -31,9 +30,9 @@ public function getLevel()
3130
protected function getVisibilityMapping()
3231
{
3332
return [
34-
Class_::MODIFIER_PUBLIC => 0,
33+
Class_::MODIFIER_PUBLIC => 0,
3534
Class_::MODIFIER_PROTECTED => 1,
36-
Class_::MODIFIER_PRIVATE => 2,
35+
Class_::MODIFIER_PRIVATE => 2,
3736
];
3837
}
3938

src/PHPSemVerChecker/Operation/ClassMethodParameterChanged.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ class ClassMethodParameterChanged extends ClassMethodOperation {
1212
* @var array
1313
*/
1414
protected $code = [
15-
'class' => ['V010', 'V011', 'V031'],
15+
'class' => ['V010', 'V011', 'V031'],
1616
'interface' => ['V036'],
17-
'trait' => ['V042', 'V043', 'V059'],
17+
'trait' => ['V042', 'V043', 'V059'],
1818
];
1919
/**
2020
* @var int
2121
*/
2222
protected $level = [
23-
'class' => [Level::MAJOR, Level::MAJOR, Level::PATCH],
23+
'class' => [Level::MAJOR, Level::MAJOR, Level::PATCH],
2424
'interface' => [Level::MAJOR],
25-
'trait' => [Level::MAJOR, Level::MAJOR, Level::PATCH],
25+
'trait' => [Level::MAJOR, Level::MAJOR, Level::PATCH],
2626
];
2727
/**
2828
* @var string

src/PHPSemVerChecker/Operation/ClassMethodParameterNameChanged.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ class ClassMethodParameterNameChanged extends ClassMethodOperation {
1212
* @var array
1313
*/
1414
protected $code = [
15-
'class' => ['V060', 'V061', 'V062'],
15+
'class' => ['V060', 'V061', 'V062'],
1616
'interface' => ['V063'],
17-
'trait' => ['V064', 'V065', 'V066'],
17+
'trait' => ['V064', 'V065', 'V066'],
1818
];
1919
/**
2020
* @var int
2121
*/
2222
protected $level = [
23-
'class' => [Level::PATCH, Level::PATCH, Level::PATCH],
23+
'class' => [Level::PATCH, Level::PATCH, Level::PATCH],
2424
'interface' => [Level::PATCH],
25-
'trait' => [Level::PATCH, Level::PATCH, Level::PATCH],
25+
'trait' => [Level::PATCH, Level::PATCH, Level::PATCH],
2626
];
2727
/**
2828
* @var string

src/PHPSemVerChecker/Operation/ClassMethodRemoved.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ class ClassMethodRemoved extends ClassMethodOperation {
1313
* @var array
1414
*/
1515
protected $code = [
16-
'class' => ['V006', 'V007', 'V029'],
16+
'class' => ['V006', 'V007', 'V029'],
1717
'interface' => ['V035'],
18-
'trait' => ['V038', 'V039', 'V058'],
18+
'trait' => ['V038', 'V039', 'V058'],
1919
];
2020
/**
2121
* @var int
2222
*/
2323
protected $level = [
24-
'class' => [Level::MAJOR, Level::MAJOR, Level::PATCH],
24+
'class' => [Level::MAJOR, Level::MAJOR, Level::PATCH],
2525
'interface' => [Level::MAJOR],
26-
'trait' => [Level::MAJOR, Level::MAJOR, Level::MAJOR],
26+
'trait' => [Level::MAJOR, Level::MAJOR, Level::MAJOR],
2727
];
2828
/**
2929
* @var string

src/PHPSemVerChecker/Operation/FunctionImplementationChanged.php

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace PHPSemVerChecker\Operation;
44

5-
use PhpParser\Node\Stmt\ClassMethod;
65
use PhpParser\Node\Stmt\Function_;
76
use PHPSemVerChecker\Node\Statement\Function_ as PFunction;
87
use PHPSemVerChecker\SemanticVersioning\Level;

src/PHPSemVerChecker/Operation/PropertyAdded.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace PHPSemVerChecker\Operation;
44

55
use PhpParser\Node\Stmt;
6-
use PhpParser\Node\Stmt\ClassMethod;
76
use PhpParser\Node\Stmt\Property;
87
use PHPSemVerChecker\Node\Statement\Property as PProperty;
98
use PHPSemVerChecker\SemanticVersioning\Level;
@@ -41,10 +40,10 @@ class PropertyAdded extends PropertyOperation {
4140
protected $propertyAfter;
4241

4342
/**
44-
* @param string $context
45-
* @param string $fileAfter
46-
* @param \PhpParser\Node\Stmt $contextAfter
47-
* @param \PhpParser\Node\Stmt\ClassMethod $propertyAfter
43+
* @param string $context
44+
* @param string $fileAfter
45+
* @param \PhpParser\Node\Stmt $contextAfter
46+
* @param \PhpParser\Node\Stmt\Property $propertyAfter
4847
*/
4948
public function __construct($context, $fileAfter, Stmt $contextAfter, Property $propertyAfter)
5049
{

src/PHPSemVerChecker/Operation/PropertyOperation.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
use PhpParser\Node\Stmt\Class_;
66
use PhpParser\Node\Stmt\Property;
77

8-
abstract class PropertyOperation extends Operation
9-
{
8+
abstract class PropertyOperation extends Operation {
109
/**
1110
* @var string
1211
*/
@@ -31,9 +30,9 @@ public function getLevel()
3130
protected function getVisibilityMapping()
3231
{
3332
return [
34-
Class_::MODIFIER_PUBLIC => 0,
33+
Class_::MODIFIER_PUBLIC => 0,
3534
Class_::MODIFIER_PROTECTED => 1,
36-
Class_::MODIFIER_PRIVATE => 2,
35+
Class_::MODIFIER_PRIVATE => 2,
3736
];
3837
}
3938

src/PHPSemVerChecker/Operation/PropertyRemoved.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class PropertyRemoved extends PropertyOperation {
1414
*/
1515
protected $code = [
1616
'class' => ['V008', 'V009', 'V027'],
17-
'trait' => ['V040', 'V041', 'V056'],
17+
'trait' => ['V040', 'V041', 'V056'],
1818
];
1919
/**
2020
* @var int

src/PHPSemVerChecker/Registry/Registry.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace PHPSemVerChecker\Registry;
44

55
use PhpParser\Node;
6+
use PhpParser\Node\Stmt;
67
use PhpParser\Node\Stmt\Class_;
78
use PhpParser\Node\Stmt\Function_;
89
use PhpParser\Node\Stmt\Interface_;
@@ -31,27 +32,26 @@ class Registry {
3132
public function __construct()
3233
{
3334
$contexts = [
34-
'class' => [],
35-
'function' => [],
35+
'class' => [],
36+
'function' => [],
3637
'interface' => [],
37-
'trait' => [],
38+
'trait' => [],
3839
];
3940

4041
$this->data = $contexts;
4142
$this->mapping = $contexts;
4243
}
4344

44-
// TODO: Try to reduce the amount of data moved around (we don't need statements inside methods/functions) <[email protected]>
4545
/**
46-
* @param \PhpParser\Node\Stmt\Class_ $item
46+
* @param \PhpParser\Node\Stmt\Class_ $class
4747
*/
4848
public function addClass(Class_ $class)
4949
{
5050
$this->addNode('class', $class);
5151
}
5252

5353
/**
54-
* @param \PhpParser\Node\Stmt\Function_ $item
54+
* @param \PhpParser\Node\Stmt\Function_ $function
5555
*/
5656
public function addFunction(Function_ $function)
5757
{
@@ -75,21 +75,21 @@ public function addTrait(Trait_ $trait)
7575
}
7676

7777
/**
78-
* @param string $context
79-
* @param \PhpParser\Node\Stmt $node
78+
* @param string $context
79+
* @param Stmt $node
8080
*/
81-
protected function addNode($context, Node\Stmt $node)
81+
protected function addNode($context, Stmt $node)
8282
{
8383
$fullyQualifiedName = $this->fullyQualifiedName($node);
8484
$this->data[$context][$fullyQualifiedName] = $node;
8585
$this->mapping[$context][$fullyQualifiedName] = $this->getCurrentFile();
8686
}
8787

8888
/**
89-
* @param \PhpParser\Node\Stmt $node
89+
* @param Stmt $node
9090
* @return string
9191
*/
92-
protected function fullyQualifiedName(Node\Stmt $node)
92+
protected function fullyQualifiedName(Stmt $node)
9393
{
9494
return $node->namespacedName ? $node->namespacedName->toString() : $node->name;
9595
}

0 commit comments

Comments
 (0)