llaville / php-compatinfo

Library that find out the minimum version and the extensions required for a piece of code to run
https://llaville.github.io/php-compatinfo/7.1/
Other
372 stars 20 forks source link

Find undeclared elements #165

Closed llaville closed 9 years ago

llaville commented 9 years ago

Yesterday, in evening, I've created locally a patch in compatibility analyser to show by a U mark what elements ( class / interface / trait / user function ) are undeclared.

I've reborn an old request #137 from past !

With new API 4.0 I obtains better results with few code modified. Commit will follow soon.

It let me look also that there are some other issues I need to fix, because it gave some false positive.

Here are two examples, what it will look like :

Example 1

<?php
namespace Foo;

use Doctrine\Common\Cache\Cache;
use DateTime;

class Bar extends DateTime {
    function __construct (Cache $c) {
    }
    function foo (\Foo\Foo $foo) {
    }
}

var_dump(DateTime::ATOM);
$a = new \PDO();
$b = new \Console_Table();
$c = new \SebastianBergmann\Version("1.2");

Output :

Data Source Analysed

Directories                                          1
Files                                                1

Extensions Analysis

    Extension Matches REF      EXT min/Max PHP min/Max
    Core              Core     4.0.0       4.0.0
    PDO               PDO      5.1.0       5.1.0
    standard          standard 4.0.0       4.0.0
    Total [3]                              5.1.0

Namespaces Analysis

    Namespace Matches REF  EXT min/Max PHP min/Max
    +global           Core             4.0.0
    Foo               user             5.3.0
    Total [2]                          5.3.0

No interface found

No trait found

Classes Analysis

    Class                       Matches REF  EXT min/Max PHP min/Max
  U Console_Table               1       user             4.0.0
    DateTime                    1       date 5.2.0       5.2.0
  U Doctrine\Common\Cache\Cache 1       user             5.3.0
    Foo\Bar                             user             5.3.0
  U Foo\Foo                     1       user             5.3.0
    PDO                         1       PDO  5.1.0       5.1.0
  U SebastianBergmann\Version   1       user             5.3.0
    Total [7]                                            5.3.0

Functions Analysis

    Function  Matches REF      EXT min/Max PHP min/Max
    var_dump  1       standard 4.0.0       4.0.0
    Total [1]                              4.0.0

No constant found

No condition found

Requires PHP 5.3.0 (min)

Example 2: PHPUnit 4.5

Limited Output (where I've removed false positive, that I must fix)

Data Source Analysed

Directories                                         17
Files                                              122

Classes Analysis

    Class                                                         Matches REF        EXT min/Max PHP min/Max 
    DOMDocument                                                   16      dom        5.0.0       5.0.0       
    DOMElement                                                    6       dom        5.0.0       5.0.0       
    DOMNode                                                       4       dom        5.0.0       5.0.0       
    DOMXPath                                                      1       dom        5.0.0       5.0.0       
    ErrorException                                                1       Core       5.1.0       5.1.0       
    Exception                                                     43      Core       5.1.0       5.1.0       
  U File_Iterator_Facade                                          3       user                   4.0.0       
    InvalidArgumentException                                      1       spl        5.1.0       5.1.0       
  U Iterator                                                      1       user                   4.0.0       
 CU PHPUnit_Extensions_Database_TestCase                                  user                   4.0.0       
    PHPUnit_Extensions_GroupTestSuite                                     user                   5.3.0       
    PHPUnit_Extensions_PhptTestCase                               2       user                   5.0.0       
    PHPUnit_Extensions_PhptTestSuite                                      user                   5.3.0       
    PHPUnit_Extensions_RepeatedTest                               1       user                   5.3.0       
 CU PHPUnit_Extensions_SeleniumTestCase                                   user                   4.0.0       
    PHPUnit_Extensions_TestDecorator                              1       user                   5.3.0       

    ... more 

    PHPUnit_Framework_InvalidCoversTargetException                3       user                   5.3.0       
  U PHPUnit_Framework_MockObject_Generator                        1       user                   4.0.0       
  U PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount          1       user                   4.0.0       
  U PHPUnit_Framework_MockObject_Matcher_InvokedAtIndex           1       user                   4.0.0       
  U PHPUnit_Framework_MockObject_Matcher_InvokedAtLeastCount      1       user                   4.0.0       
  U PHPUnit_Framework_MockObject_Matcher_InvokedAtLeastOnce       1       user                   4.0.0       
  U PHPUnit_Framework_MockObject_Matcher_InvokedAtMostCount       1       user                   4.0.0       
  U PHPUnit_Framework_MockObject_Matcher_InvokedCount             3       user                   4.0.0       
  U PHPUnit_Framework_MockObject_MockBuilder                      1       user                   4.0.0       
  U PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls            1       user                   4.0.0       
  U PHPUnit_Framework_MockObject_Stub_Exception                   1       user                   4.0.0       
  U PHPUnit_Framework_MockObject_Stub_Return                      1       user                   4.0.0       
  U PHPUnit_Framework_MockObject_Stub_ReturnArgument              1       user                   4.0.0       
  U PHPUnit_Framework_MockObject_Stub_ReturnCallback              1       user                   4.0.0       
  U PHPUnit_Framework_MockObject_Stub_ReturnSelf                  1       user                   4.0.0       
  U PHPUnit_Framework_MockObject_Stub_ReturnValueMap              1       user                   4.0.0       
    PHPUnit_Framework_OutputError                                 1       user                   5.3.0       

    ... more 

    PHPUnit_Util_XML                                              14      user                   5.1.0       
  U PHP_CodeCoverage                                              2       user                   4.0.0       
  U PHP_CodeCoverage_Filter                                       2       user                   4.0.0       
  U PHP_CodeCoverage_Report_Clover                                1       user                   4.0.0       
  U PHP_CodeCoverage_Report_Crap4j                                1       user                   4.0.0       
  U PHP_CodeCoverage_Report_HTML                                  1       user                   4.0.0       
  U PHP_CodeCoverage_Report_PHP                                   1       user                   4.0.0       
  U PHP_CodeCoverage_Report_Text                                  1       user                   4.0.0       
  U PHP_CodeCoverage_Report_XML                                   1       user                   4.0.0       
 CU PHP_Invoker                                                   1       user                   4.0.0       
  U PHP_Timer                                                     5       user                   4.0.0       
    Phar                                                          1       phar       1.0.0       5.2.0       
  U Prophecy\Prophet                                              1       user                   5.3.0       
    RecursiveFilterIterator                                       2       spl        5.1.0       5.1.0       
    RecursiveIterator                                             2       user                   4.0.0       
    RecursiveIteratorIterator                                     1       spl        5.1.3       5.1.3       
    ReflectionClass                                               42      Reflection 5.0.0       5.0.0       
    ReflectionFunction                                            1       Reflection 5.0.0       5.0.0       
    ReflectionMethod                                              11      Reflection 5.0.0       5.0.0       
    ReflectionObject                                              2       Reflection 5.0.0       5.0.0       
    ReflectionProperty                                            1       Reflection 5.0.0       5.0.0       
    RuntimeException                                              2       spl        5.1.0       5.1.0       
  U SebastianBergmann\Comparator\ComparisonFailure                3       user                   5.3.0       
  U SebastianBergmann\Comparator\Factory                          1       user                   5.3.0       
  U SebastianBergmann\Diff\Differ                                 1       user                   5.3.0       
  U SebastianBergmann\Environment\Console                         1       user                   5.3.0       
  U SebastianBergmann\Environment\Runtime                         3       user                   5.3.0       
  U SebastianBergmann\Exporter\Exporter                           2       user                   5.3.0       
  U SebastianBergmann\GlobalState\Blacklist                       1       user                   5.3.0       
  U SebastianBergmann\GlobalState\Restorer                        1       user                   5.3.0       
  U SebastianBergmann\GlobalState\Snapshot                        1       user                   5.3.0       
  U SebastianBergmann\Version                                     1       user                   5.3.0       
  U Symfony\Component\Yaml\Dumper                                 1       user                   5.3.0       
  U Text_Template                                                 2       user                   4.0.0       

    ... more 

    Total [178]                                                                                  5.3.3       

Conditions Analysis

    Condition                                          Matches REF      EXT min/Max PHP min/Max 
    class_exists(PHPUnit_Extensions_Database_TestCase) 1       user                 4.0.0       
    class_exists(PHPUnit_Extensions_SeleniumTestCase)  2       user                 4.0.0       
    class_exists(PHP_Invoker)                          1       user                 4.0.0       
    defined(JSON_PRETTY_PRINT)                         1       json     5.4.0       5.4.0       
    defined(LC_MESSAGES)                               1       standard 4.0.0       4.0.0       
    defined(PHPUNIT_COMPOSER_INSTALL)                  1       user                 4.0.0       
    defined(PHPUNIT_TESTSUITE)                         3       user                 4.0.0       
    defined(PHP_WINDOWS_VERSION_BUILD)                 1       Core     5.3.0       5.3.0       
    defined(__PHPUNIT_PHAR_ROOT__)                     1       user                 4.0.0       
    defined(__PHPUNIT_PHAR__)                          5       user                 4.0.0       
    extension_loaded(Xdebug)                           1       user                 4.0.0       
    extension_loaded(openssl)                          1       user                 4.0.0       
    extension_loaded(pcntl)                            1       user                 4.0.0       
    extension_loaded(tidy)                             1       user                 4.0.0       
    extension_loaded(tokenizer)                        2       user                 4.0.0       
    function_exists(mb_convert_encoding)               1       mbstring 4.0.6       4.0.6       
    function_exists(trait_exists)                      1       Core     5.4.0       5.4.0       
    Total [17]                                                                      5.4.0       

Requires PHP 5.3.3 (min)
llaville commented 9 years ago

To avoid false positive with PHPUnit source code example, I must first to fix issue #166, then I will close this one

llaville commented 9 years ago

PHPUnit 4.5 study case gave now good results without false positive.