Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/PHPSemVerChecker/Analyzer/ClassAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
28 changes: 28 additions & 0 deletions src/PHPSemVerChecker/Analyzer/ClassMethodAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = [
Expand Down
27 changes: 27 additions & 0 deletions src/PHPSemVerChecker/Analyzer/FunctionAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 = [
Expand Down
2 changes: 1 addition & 1 deletion src/PHPSemVerChecker/Analyzer/InterfaceAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/PHPSemVerChecker/Analyzer/TraitAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
12 changes: 12 additions & 0 deletions src/PHPSemVerChecker/Configuration/LevelMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];

/**
Expand Down
19 changes: 19 additions & 0 deletions src/PHPSemVerChecker/Operation/ClassMethodReturnTypeAdded.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace PHPSemVerChecker\Operation;

class ClassMethodReturnTypeAdded extends ClassMethodOperationDelta
{
/**
* @var array
*/
protected $code = [
'class' => ['V161'],
'interface' => ['V162'],
'trait' => ['V163'],
];
/**
* @var string
*/
protected $reason = 'Method return type was added.';
}
19 changes: 19 additions & 0 deletions src/PHPSemVerChecker/Operation/ClassMethodReturnTypeChanged.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace PHPSemVerChecker\Operation;

class ClassMethodReturnTypeChanged extends ClassMethodOperationDelta
{
/**
* @var array
*/
protected $code = [
'class' => ['V167'],
'interface' => ['V168'],
'trait' => ['V169'],
];
/**
* @var string
*/
protected $reason = 'Method return type was changed.';
}
19 changes: 19 additions & 0 deletions src/PHPSemVerChecker/Operation/ClassMethodReturnTypeRemoved.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace PHPSemVerChecker\Operation;

class ClassMethodReturnTypeRemoved extends ClassMethodOperationDelta
{
/**
* @var array
*/
protected $code = [
'class' => ['V164'],
'interface' => ['V165'],
'trait' => ['V166'],
];
/**
* @var string
*/
protected $reason = 'Method return type was removed.';
}
15 changes: 15 additions & 0 deletions src/PHPSemVerChecker/Operation/FunctionReturnTypeAdded.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace PHPSemVerChecker\Operation;

class FunctionReturnTypeAdded extends FunctionOperationDelta
{
/**
* @var string
*/
protected $code = 'V170';
/**
* @var string
*/
protected $reason = 'Function return type was added.';
}
15 changes: 15 additions & 0 deletions src/PHPSemVerChecker/Operation/FunctionReturnTypeChanged.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace PHPSemVerChecker\Operation;

class FunctionReturnTypeChanged extends FunctionOperationDelta
{
/**
* @var string
*/
protected $code = 'V171';
/**
* @var string
*/
protected $reason = 'Function return type was changed.';
}
15 changes: 15 additions & 0 deletions src/PHPSemVerChecker/Operation/FunctionReturnTypeRemoved.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace PHPSemVerChecker\Operation;

class FunctionReturnTypeRemoved extends FunctionOperationDelta
{
/**
* @var string
*/
protected $code = 'V172';
/**
* @var string
*/
protected $reason = 'Function return type removed.';
}