Skip to content

Commit

Permalink
Code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomzx committed May 8, 2016
1 parent 0e1c322 commit f905199
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 79 deletions.
4 changes: 0 additions & 4 deletions src/PHPSemVerChecker/Comparator/Implementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ public static function isSame(array $statementsA, array $statementsB)
$dumpA = $nodeDumper->dump($statementsA);
$dumpB = $nodeDumper->dump($statementsB);

// var_dump($dumpA === $dumpB);
// var_dump($statementsA == $statementsB);
// echo '-----'.PHP_EOL;

return $dumpA === $dumpB;
}
}
73 changes: 0 additions & 73 deletions src/PHPSemVerChecker/Comparator/Signature.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,77 +64,4 @@ public static function analyze(array $parametersA, array $parametersB)

return $changes;
}

/**
* @param array $paramsA
* @param array $paramsB
* @return string|bool
*/
public static function requiredParametersChanges(array $paramsA, array $paramsB)
{
$iterations = min(count($paramsA), count($paramsB));
// Verify that all params default value match (either they're both null => parameter is required, or both
// set to the same required value)
for ($i = 0; $i < $iterations; ++$i) {
if ($paramsA[$i]->default !== $paramsB[$i]->default) {
return $paramsB[$i]->default ? 'removed' : 'added';
}
}

// Only one of these will return its remaining values, the other returning an empty array
$toCheck = array_slice($paramsA, $iterations) + array_slice($paramsB, $iterations);
$operation = count($paramsA) < count($paramsB) ? 'added' : 'removed';
// If any additional argument does not have a default value, the signature has changed
foreach ($toCheck as $param) {
if ($param->default === null) {
return $operation;
}
}
return false;
}

/**
* @param array $paramsA
* @param array $paramsB
* @return bool
*/
public static function isSameTypehints(array $paramsA, array $paramsB)
{
$iterations = min(count($paramsA), count($paramsB));
for ($i = 0; $i < $iterations; ++$i) {
// TODO: Allow for contravariance <[email protected]>
if ( ! Type::isSame($paramsA[$i]->type, $paramsB[$i]->type)) {
return false;
}
}
// Only one of these will return its remaining values, the other returning an empty array
$toCheck = array_slice($paramsA, $iterations) + array_slice($paramsB, $iterations);
// If any additional argument does not have a default value, the signature has changed
foreach ($toCheck as $param) {
if ($param->default === null) {
return false;
}
}
return true;
}

/**
* @param array $paramsA
* @param array $paramsB
* @return bool
*/
public static function isSameVariables(array $paramsA, array $paramsB)
{
if (count($paramsA) !== count($paramsB)) {
return false;
}

$iterations = min(count($paramsA), count($paramsB));
for ($i = 0; $i < $iterations; ++$i) {
if ($paramsA[$i]->name != $paramsB[$i]->name) {
return false;
}
}
return true;
}
}
4 changes: 2 additions & 2 deletions src/PHPSemVerChecker/Operation/ClassMethodOperationDelta.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ abstract class ClassMethodOperationDelta extends Operation {
*/
protected $fileBefore;
/**
* @var Stmt
* @var \PhpParser\Node\Stmt
*/
protected $contextBefore;
/**
Expand All @@ -32,7 +32,7 @@ abstract class ClassMethodOperationDelta extends Operation {
*/
protected $fileAfter;
/**
* @var Stmt
* @var \PhpParser\Node\Stmt
*/
protected $contextAfter;
/**
Expand Down

0 comments on commit f905199

Please sign in to comment.