Roave / BackwardCompatibilityCheck

:ab: Tool to compare two revisions of a class API to check for BC breaks
MIT License
568 stars 59 forks source link

Compare to uncommitted changes #246

Open sebastianbergmann opened 4 years ago

sebastianbergmann commented 4 years ago

It is confusing, at least to me, that this tool does not compare to the current state of the working copy and ignores uncommitted changes.

$ git status                                                                                           
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
    modified:   src/Token/Stream.php
    modified:   src/Token/Stream/CachingFactory.php

no changes added to commit (use "git add" and/or "git commit -a")
$ git diff
diff --git a/src/Token/Stream.php b/src/Token/Stream.php
index 513fc79..167bb36 100644
--- a/src/Token/Stream.php
+++ b/src/Token/Stream.php
@@ -290,7 +290,7 @@ public function getLinesOfCode()
         return $this->linesOfCode;
     }

-    public function rewind(): void
+    public function rewind()/*: void*/
     {
         $this->position = 0;
     }
@@ -319,7 +319,7 @@ public function current()
         return $this->tokens[$this->position];
     }

-    public function next(): void
+    public function next()/*: void*/
     {
         $this->position++;
     }
@@ -356,7 +356,7 @@ public function offsetGet($offset)
     /**
      * @param int $offset
      */
-    public function offsetSet($offset, $value): void
+    public function offsetSet($offset, $value)/*: void*/
     {
         $this->tokens[$offset] = $value;
     }
@@ -366,7 +366,7 @@ public function offsetSet($offset, $value): void
      *
      * @throws OutOfBoundsException
      */
-    public function offsetUnset($offset): void
+    public function offsetUnset($offset)/*: void*/
     {
         if (!$this->offsetExists($offset)) {
             throw new OutOfBoundsException(
@@ -387,7 +387,7 @@ public function offsetUnset($offset): void
      *
      * @throws OutOfBoundsException
      */
-    public function seek($position): void
+    public function seek($position)/*: void*/
     {
         $this->position = $position;

@@ -407,7 +407,7 @@ public function seek($position): void
      *
      * @param string $sourceCode
      */
-    protected function scan($sourceCode): void
+    protected function scan($sourceCode)/*: void*/
     {
         $id        = 0;
         $line      = 1;
@@ -468,7 +468,7 @@ protected function scan($sourceCode): void
                                       $this->linesOfCode['cloc'];
     }

-    protected function parse(): void
+    protected function parse()/*: void*/
     {
         $this->interfaces = [];
         $this->classes    = [];
diff --git a/src/Token/Stream/CachingFactory.php b/src/Token/Stream/CachingFactory.php
index b81f978..2c8d0e0 100644
--- a/src/Token/Stream/CachingFactory.php
+++ b/src/Token/Stream/CachingFactory.php
@@ -34,7 +34,7 @@ public static function get($filename)
     /**
      * @param string $filename
      */
-    public static function clear($filename = null): void
+    public static function clear($filename = null)/*: void*/
     {
         if (\is_string($filename)) {
             unset(self::$cache[$filename]);
$ ./tools/roave-backward-compatibility-check --from=4.0.0
Comparing from 72273e715ebf358a8d35ebf073739764ccc1be81 to c48f2716357fba91e107ab631d1fe972fc2e21a4...
Loading composer repositories with package information
Updating dependencies
Writing lock file
Loading composer repositories with package information
Updating dependencies
Writing lock file
PHP Deprecated:  Function ReflectionType::__toString() is deprecated in phar:///usr/local/src/php-token-stream/tools/roave-backward-compatibility-check/vendor/roave/better-reflection/src/SourceLocator/SourceStubber/ReflectionSourceStubber.php on line 478
PHP Deprecated:  Function ReflectionType::__toString() is deprecated in phar:///usr/local/src/php-token-stream/tools/roave-backward-compatibility-check/vendor/roave/better-reflection/src/SourceLocator/SourceStubber/ReflectionSourceStubber.php on line 478
PHP Deprecated:  Function ReflectionType::__toString() is deprecated in phar:///usr/local/src/php-token-stream/tools/roave-backward-compatibility-check/vendor/roave/better-reflection/src/SourceLocator/SourceStubber/ReflectionSourceStubber.php on line 478
PHP Deprecated:  Function ReflectionType::__toString() is deprecated in phar:///usr/local/src/php-token-stream/tools/roave-backward-compatibility-check/vendor/roave/better-reflection/src/SourceLocator/SourceStubber/ReflectionSourceStubber.php on line 478
[BC] CHANGED: The return type of PHP_Token_Stream#scan() changed from no type to void
[BC] CHANGED: The return type of PHP_Token_Stream#scan() changed from no type to void
[BC] CHANGED: The return type of PHP_Token_Stream#parse() changed from no type to void
[BC] CHANGED: The return type of PHP_Token_Stream#rewind() changed from no type to void
[BC] CHANGED: The return type of PHP_Token_Stream#next() changed from no type to void
[BC] CHANGED: The return type of PHP_Token_Stream#offsetSet() changed from no type to void
[BC] CHANGED: The return type of PHP_Token_Stream#offsetUnset() changed from no type to void
[BC] CHANGED: The return type of PHP_Token_Stream#seek() changed from no type to void
[BC] CHANGED: The return type of PHP_Token_Stream_CachingFactory::clear() changed from no type to void
[BC] CHANGED: The return type of PHP_Token_Stream_CachingFactory::clear() changed from no type to void
$ git add .
$ git commit -m"Fix backward compatibility breaks introduced in version 4.0.1"
$ ./tools/roave-backward-compatibility-check --from=4.0.0
./tools/roave-backward-compatibility-check --from=4.0.0                                       
Comparing from 72273e715ebf358a8d35ebf073739764ccc1be81 to e61c593e9734b47ef462340c24fca8d6a57da14e...
Loading composer repositories with package information
Updating dependencies
Writing lock file
Loading composer repositories with package information
Updating dependencies
Writing lock file
PHP Deprecated:  Function ReflectionType::__toString() is deprecated in phar:///usr/local/src/php-token-stream/tools/roave-backward-compatibility-check/vendor/roave/better-reflection/src/SourceLocator/SourceStubber/ReflectionSourceStubber.php on line 478
PHP Deprecated:  Function ReflectionType::__toString() is deprecated in phar:///usr/local/src/php-token-stream/tools/roave-backward-compatibility-check/vendor/roave/better-reflection/src/SourceLocator/SourceStubber/ReflectionSourceStubber.php on line 478
PHP Deprecated:  Function ReflectionType::__toString() is deprecated in phar:///usr/local/src/php-token-stream/tools/roave-backward-compatibility-check/vendor/roave/better-reflection/src/SourceLocator/SourceStubber/ReflectionSourceStubber.php on line 478
PHP Deprecated:  Function ReflectionType::__toString() is deprecated in phar:///usr/local/src/php-token-stream/tools/roave-backward-compatibility-check/vendor/roave/better-reflection/src/SourceLocator/SourceStubber/ReflectionSourceStubber.php on line 478
No backwards-incompatible changes detected

I think it would make sense to use the current state of the working copy instead of the latest commit when --to is not used.

Ocramius commented 4 years ago

I think this makes a lot of sense: when we designed this package, a lot of focus was put into trying to keep the current repo isolated from the rest, but the --to could indeed be the current state of the project, rather than a clean copy.

Ocramius commented 2 years ago

Not going to be able to drag this into 6.0 - removing milestone for now.