diff --git a/src/PHPSemVerChecker/Analyzer/ClassAnalyzer.php b/src/PHPSemVerChecker/Analyzer/ClassAnalyzer.php index e21d0c0..7c5a0fe 100644 --- a/src/PHPSemVerChecker/Analyzer/ClassAnalyzer.php +++ b/src/PHPSemVerChecker/Analyzer/ClassAnalyzer.php @@ -67,7 +67,7 @@ public function analyze(Registry $registryBefore, Registry $registryAfter) if ($classBefore != $classAfter) { // Check for case change of class name. // If we entered this section then the normalized names (lowercase) were equal. - if ($classBefore->name !== $classAfter->name) { + if ($classBefore->name->toString() !== $classAfter->name->toString()) { $report->add( $this->context, new ClassCaseChanged( diff --git a/src/PHPSemVerChecker/Analyzer/ClassMethodAnalyzer.php b/src/PHPSemVerChecker/Analyzer/ClassMethodAnalyzer.php index 86a766d..f1f8973 100644 --- a/src/PHPSemVerChecker/Analyzer/ClassMethodAnalyzer.php +++ b/src/PHPSemVerChecker/Analyzer/ClassMethodAnalyzer.php @@ -18,6 +18,9 @@ use PHPSemVerChecker\Operation\ClassMethodParameterTypingAdded; use PHPSemVerChecker\Operation\ClassMethodParameterTypingRemoved; use PHPSemVerChecker\Operation\ClassMethodRemoved; +use PHPSemVerChecker\Operation\ClassMethodReturnTypeAdded; +use PHPSemVerChecker\Operation\ClassMethodReturnTypeChanged; +use PHPSemVerChecker\Operation\ClassMethodReturnTypeRemoved; use PHPSemVerChecker\Report\Report; class ClassMethodAnalyzer @@ -109,6 +112,31 @@ public function analyze(Stmt $contextBefore, Stmt $contextAfter) ); } + if ($methodBefore->returnType !== $methodAfter->returnType) { + $class = null; + if ($methodBefore->returnType !== null && $methodAfter->returnType === null) { + $class = ClassMethodReturnTypeAdded::class; + } elseif ($methodAfter->returnType !== null && $methodBefore->returnType === null) { + $class = ClassMethodReturnTypeRemoved::class; + } elseif (strcasecmp($methodAfter->returnType->name, $methodBefore->returnType->name) !== 0) { + $class = ClassMethodReturnTypeChanged::class; + } + if ($class) { + $report->add( + $this->context, + new $class( + $this->context, + $this->fileBefore, + $contextAfter, + $methodBefore, + $this->fileAfter, + $contextAfter, + $methodAfter + ) + ); + } + } + $signatureResult = Signature::analyze($methodBefore->getParams(), $methodAfter->getParams()); $changes = [ diff --git a/src/PHPSemVerChecker/Analyzer/FunctionAnalyzer.php b/src/PHPSemVerChecker/Analyzer/FunctionAnalyzer.php index 3d8fc60..0712dbb 100644 --- a/src/PHPSemVerChecker/Analyzer/FunctionAnalyzer.php +++ b/src/PHPSemVerChecker/Analyzer/FunctionAnalyzer.php @@ -18,6 +18,9 @@ use PHPSemVerChecker\Operation\FunctionParameterTypingAdded; use PHPSemVerChecker\Operation\FunctionParameterTypingRemoved; use PHPSemVerChecker\Operation\FunctionRemoved; +use PHPSemVerChecker\Operation\FunctionReturnTypeAdded; +use PHPSemVerChecker\Operation\FunctionReturnTypeChanged; +use PHPSemVerChecker\Operation\FunctionReturnTypeRemoved; use PHPSemVerChecker\Registry\Registry; use PHPSemVerChecker\Report\Report; @@ -89,6 +92,30 @@ public function analyze(Registry $registryBefore, Registry $registryAfter) ); } + if ($functionBefore->returnType !== $functionAfter->returnType) { + print_r($functionBefore->returnType); + print_r($functionAfter->returnType); + $class = null; + if ($functionBefore->returnType !== null && $functionAfter->returnType === null) { + $class = FunctionReturnTypeAdded::class; + } elseif ($functionAfter->returnType !== null && $functionBefore->returnType === null) { + $class = FunctionReturnTypeRemoved::class; + } elseif (strcasecmp($functionAfter->returnType->name, $functionBefore->returnType->name) !== 0) { + $class = FunctionReturnTypeChanged::class; + } + if ($class) { + $report->add( + $this->context, + new $class( + $fileBefore, + $functionBefore, + $fileAfter, + $functionAfter + ) + ); + } + } + $signatureResult = Signature::analyze($functionBefore->getParams(), $functionAfter->getParams()); $changes = [ diff --git a/src/PHPSemVerChecker/Analyzer/InterfaceAnalyzer.php b/src/PHPSemVerChecker/Analyzer/InterfaceAnalyzer.php index a83248b..e7e68c2 100644 --- a/src/PHPSemVerChecker/Analyzer/InterfaceAnalyzer.php +++ b/src/PHPSemVerChecker/Analyzer/InterfaceAnalyzer.php @@ -67,7 +67,7 @@ public function analyze(Registry $registryBefore, Registry $registryAfter) if ($interfaceBefore != $interfaceAfter) { // Check if the name of the interface has changed case. // If we entered this section then the normalized names (lowercase) were equal. - if ($interfaceBefore->name !== $interfaceAfter->name) { + if ($interfaceBefore->name->toString() !== $interfaceAfter->name->toString()) { $report->add( 'interface', new InterfaceCaseChanged( diff --git a/src/PHPSemVerChecker/Analyzer/TraitAnalyzer.php b/src/PHPSemVerChecker/Analyzer/TraitAnalyzer.php index b81e53d..6f54a31 100644 --- a/src/PHPSemVerChecker/Analyzer/TraitAnalyzer.php +++ b/src/PHPSemVerChecker/Analyzer/TraitAnalyzer.php @@ -65,7 +65,7 @@ public function analyze(Registry $registryBefore, Registry $registryAfter) if ($traitBefore != $traitAfter) { // Check for name case change. // If we entered this section then the normalized names (lowercase) were equal. - if ($traitBefore->name !== $traitAfter->name) { + if ($traitBefore->name->toString() !== $traitAfter->name->toString()) { $report->add( $this->context, new TraitCaseChanged( diff --git a/src/PHPSemVerChecker/Configuration/LevelMapping.php b/src/PHPSemVerChecker/Configuration/LevelMapping.php index 5bd98ad..b8572f1 100644 --- a/src/PHPSemVerChecker/Configuration/LevelMapping.php +++ b/src/PHPSemVerChecker/Configuration/LevelMapping.php @@ -135,6 +135,18 @@ class LevelMapping 'V158' => Level::PATCH, 'V159' => Level::PATCH, 'V160' => Level::PATCH, + 'V161' => Level::PATCH, + 'V162' => Level::PATCH, + 'V163' => Level::PATCH, + 'V164' => Level::PATCH, + 'V165' => Level::PATCH, + 'V166' => Level::PATCH, + 'V167' => Level::PATCH, + 'V168' => Level::PATCH, + 'V169' => Level::PATCH, + 'V170' => Level::PATCH, + 'V171' => Level::PATCH, + 'V172' => Level::PATCH, ]; /** diff --git a/src/PHPSemVerChecker/Operation/ClassMethodReturnTypeAdded.php b/src/PHPSemVerChecker/Operation/ClassMethodReturnTypeAdded.php new file mode 100644 index 0000000..e4b45de --- /dev/null +++ b/src/PHPSemVerChecker/Operation/ClassMethodReturnTypeAdded.php @@ -0,0 +1,19 @@ + ['V161'], + 'interface' => ['V162'], + 'trait' => ['V163'], + ]; + /** + * @var string + */ + protected $reason = 'Method return type was added.'; +} diff --git a/src/PHPSemVerChecker/Operation/ClassMethodReturnTypeChanged.php b/src/PHPSemVerChecker/Operation/ClassMethodReturnTypeChanged.php new file mode 100644 index 0000000..57d1800 --- /dev/null +++ b/src/PHPSemVerChecker/Operation/ClassMethodReturnTypeChanged.php @@ -0,0 +1,19 @@ + ['V167'], + 'interface' => ['V168'], + 'trait' => ['V169'], + ]; + /** + * @var string + */ + protected $reason = 'Method return type was changed.'; +} diff --git a/src/PHPSemVerChecker/Operation/ClassMethodReturnTypeRemoved.php b/src/PHPSemVerChecker/Operation/ClassMethodReturnTypeRemoved.php new file mode 100644 index 0000000..e321cdc --- /dev/null +++ b/src/PHPSemVerChecker/Operation/ClassMethodReturnTypeRemoved.php @@ -0,0 +1,19 @@ + ['V164'], + 'interface' => ['V165'], + 'trait' => ['V166'], + ]; + /** + * @var string + */ + protected $reason = 'Method return type was removed.'; +} diff --git a/src/PHPSemVerChecker/Operation/FunctionReturnTypeAdded.php b/src/PHPSemVerChecker/Operation/FunctionReturnTypeAdded.php new file mode 100644 index 0000000..767555e --- /dev/null +++ b/src/PHPSemVerChecker/Operation/FunctionReturnTypeAdded.php @@ -0,0 +1,15 @@ +