A static analysis engine

Related tags

Frameworks Tuli
Overview

Build Status

A static analysis engine...

Usage:

bin/tuli analyze file1 file2 path

Installation

Install it as a composer dependency!!!

$ composer require ircmaxell/tuli dev-master

Then simply execute vendor/bin/tuli as normal

Or check it out into its own project. Then composer install the dependencies:

$ composer install

Then simply bin/tuli to execute.

Example:

code.php:

<?php

$a = 1.0;
$b = 2;

$c = foo($a, $b);

$d = foo($b, $c);

function foo(int $a, int $b): int {
    if ($a > $b) {
        return $a + $b + 0.5;
    }
}

Then, in shell:

$ bin/tuli analyze code.php
Analyzing code.php
Determining Variable Types
Round 1 (15 unresolved variables out of 20)
.
Detecting Type Conversion Issues
Type mismatch on foo() argument 0, found float expecting int code.php:6
Type mismatch on foo() return value, found float expecting int code.php:12
Default return found for non-null type int code.php:10
Done

The three errors it found are:

  • Type mismatch on foo() argument 0, found float expecting int code.php:6

    Meaning that at code.php on line 6, you're passing a float to the first argument when it declared an integer

  • Type mismatch on foo() return value, found float expecting int code.php:12

    The value that's being returned on line 12 is a float, but it was declared as an integer in the function signature.

  • Default return found for non-null type int code.php:10

    There's a default return statement (not supplied) for a typed function

That's it!

Currently Supported Rules:

  • Function Argument Types

    It will check all typed function arguments and determine if all calls to that function match the type.

  • Function Return Types

    If the function's return value is typed, it will determine if the function actually returns that type.

  • Method Argument Types

    It will check all calls to a method for every valid typehint permutation to determine if there's a possible mismatch.

Todo:

  • A lot

Another example:

<?php

class A {
    public function foo(int $a) : int {
        return $a;
    }
}

class B extends A {
    public function foo(float $a) : float {
        return $a;
    }
}

class C extends B {
    public function foo(int $a) : int {
        return $a;
    }
}

function foo(A $a) : int {
    return $a->foo(1.0);
}

Running:

$ bin/tuli analyze code.php
Analyzing code.php

Determining Variable Types
Round 1 (5 unresolved variables out of 7)

Round 2 (3 unresolved variables out of 7)

Detecting Type Conversion Issues
Detecting Function Argument Errors
Detecting Function Return Errors
Type mismatch on foo() return value, found float expecting int code.php:22
Detecting Method Argument Errors
Type mismatch on A->foo() argument 0, found float expecting int code.php:22
Type mismatch on C->foo() argument 0, found float expecting int code.php:22
Done

Again, it found 3 errors:

  • Type mismatch on foo() return value, found float expecting int code.php:22

    It looked at all possible A::foo() method definitions (A::foo, B::foo, C::foo), and it detmermined that the general return type is float (since type widening allows int to be passed to float, but not the other way around). Therefore, returning ->foo() directly can result in a type error.

  • Type mismatch on A->foo() argument 0, found float expecting int code.php:22

  • Type mismatch on C->foo() argument 0, found float expecting int code.php:22

    We know that if you use type A or C, you're trying to pass a float to something that declares an integer.

Comments
  • Composer should not raise warnings.

    Composer should not raise warnings.

    MacBook-Pro-van-Tim:iRail-work tim$ sudo composer require ircmaxell/tuli dev-master ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) Your requirements could not be resolved to an installable set of packages.

    Problem 1 - The requested package ircmaxell/tuli could not be found in any version, there may be a typo in the package name.

    Potential causes:

    • A typo in the package name
    • The package is not available in a stable-enough version according to your minimum-stability setting see https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion for more details.

    Read https://getcomposer.org/doc/articles/troubleshooting.md for further common problems.

    Installation failed, reverting ./composer.json to its original content. MacBook-Pro-van-Tim:iRail-work tim$

    opened by Tjoosten 5
  • Look for autoload.php further up in the tree.

    Look for autoload.php further up in the tree.

    In an application that uses Tuli as a dependency the bin file would be located at /my-app/vendor/ircmaxell/tuli/bin/tuli, and by only going two steps up in the tree it would stop looking for the autoloader at /my-app/vendor/ircmaxell/vendor/autoload.php.

    opened by jyggen 3
  • Error involving PHPTypes

    Error involving PHPTypes

    I was just trying out Tuli, and as it was analyzing, it stopped with this error message: PHP Catchable fatal error: Argument 2 passed to PHPTypes\State::findTypedBlock() must be an instance of PHPCfg\Block, null given, called inircmaxell/php-types/lib/PHPTypes/State.php on line 207and defined in ircmaxell/php-types/lib/PHPTypes/State.php on line 212

    Any idea why $block would be null in that call?

    opened by garrettw 0
  • Tuli doesn't work with php 7.1

    Tuli doesn't work with php 7.1

    Tuli doesn't work with php 7.1

    It does not recognise that CONTs can be now public/private Syntax error, unexpected T_CONST, expecting T_FUNCTION on line 19

    or not recognzse '?' null returns eg: private function getContactField(int $id, int $type, string $field): ?string give us error: Syntax error, unexpected '?' on line 434

    opened by nospor 0
  • logic exception should never happen

    logic exception should never happen

    I cloned this git repo. Ran composer install for the dependencies. Then I ran bin/tuli analyze /path/to/project and this happened:

    Could not find parent league\event\event
    Could not find parent exception
    Determining Variable Types
    PHP Notice:  Trying to get property of non-object in /root/Tuli/vendor/ircmaxell/php-types/lib/PHPTypes/TypeReconstructor.php on line 31
    
      [LogicException]
      Should never happen
    
    analyze [-x|--exclude EXCLUDE] [--] <files> (<files>)...
    
    opened by geeknik 0
  • Unknown type declaration found: *

    Unknown type declaration found: *

    Analyzing ../api/lib/Colourbox/Search/SearchRequestParameterMappings/RequestParameterMapper.php
    
    
    
      [RuntimeException]
      Unknown type declaration found: *
    
    
    
    Exception trace:
     () at /var/www/cbx/Tuli/vendor/ircmaxell/php-cfg/lib/PHPCfg/AstVisitor/NameResolver.php:85
     PHPCfg\AstVisitor\NameResolver->parseTypeDecl() at /var/www/cbx/Tuli/vendor/ircmaxell/php-cfg/lib/PHPCfg/AstVisitor/NameResolver.php:53
     PHPCfg\AstVisitor\NameResolver->PHPCfg\AstVisitor\{closure}() at n/a:n/a
     preg_replace_callback() at /var/www/cbx/Tuli/vendor/ircmaxell/php-cfg/lib/PHPCfg/AstVisitor/NameResolver.php:56
     PHPCfg\AstVisitor\NameResolver->enterNode() at /var/www/cbx/Tuli/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:120
     PhpParser\NodeTraverser->traverseArray() at /var/www/cbx/Tuli/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:84
     PhpParser\NodeTraverser->traverseNode() at /var/www/cbx/Tuli/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:129
     PhpParser\NodeTraverser->traverseArray() at /var/www/cbx/Tuli/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:84
     PhpParser\NodeTraverser->traverseNode() at /var/www/cbx/Tuli/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:129
     PhpParser\NodeTraverser->traverseArray() at /var/www/cbx/Tuli/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:64
     PhpParser\NodeTraverser->traverse() at /var/www/cbx/Tuli/vendor/ircmaxell/php-cfg/lib/PHPCfg/Parser.php:60
     PHPCfg\Parser->parse() at /var/www/cbx/Tuli/lib/Tuli/Command.php:107
     Tuli\Command->getGraphsFromFiles() at /var/www/cbx/Tuli/lib/Tuli/Command.php:59
     Tuli\Command->execute() at /var/www/cbx/Tuli/lib/Tuli/Command/Analyze.php:32
     Tuli\Command\Analyze->execute() at /var/www/cbx/Tuli/vendor/symfony/console/Command/Command.php:259
     Symfony\Component\Console\Command\Command->run() at /var/www/cbx/Tuli/vendor/symfony/console/Application.php:878
     Symfony\Component\Console\Application->doRunCommand() at /var/www/cbx/Tuli/vendor/symfony/console/Application.php:195
     Symfony\Component\Console\Application->doRun() at /var/www/cbx/Tuli/vendor/symfony/console/Application.php:126
     Symfony\Component\Console\Application->run() at /var/www/cbx/Tuli/vendor/cilex/cilex/src/Cilex/Application.php:66
     Cilex\Application->run() at /var/www/cbx/Tuli/bin/tuli:26
    
    
    analyze [-x|--exclude EXCLUDE] [--] <files> (<files>)...
    
    opened by moffe42 0
  • Fatal error related to assignment by reference

    Fatal error related to assignment by reference

    $ ./vendor/bin/tuli analyze classes/Utils/ArrayUtil.php
    Analyzing classes/Utils/ArrayUtil.php
    PHP Catchable fatal error:  Argument 1 passed to PHPCfg\Parser::parseExpr_AssignRef() must be an instance of PhpParser\Node\Expr\Assign, instance of PhpParser\Node\Expr\AssignRef given, called in /home/andreas/dev/php/autarky-framework/vendor/ircmaxell/php-cfg/lib/PHPCfg/Parser.php on line 656 and defined in /home/andreas/dev/php/autarky-framework/vendor/ircmaxell/php-cfg/lib/PHPCfg/Parser.php on line 707
    PHP Stack trace:
    PHP   1. {main}() /home/andreas/dev/php/autarky-framework/vendor/ircmaxell/tuli/bin/tuli:0
    PHP   2. Cilex\Application->run() /home/andreas/dev/php/autarky-framework/vendor/ircmaxell/tuli/bin/tuli:26
    PHP   3. Symfony\Component\Console\Application->run() /home/andreas/dev/php/autarky-framework/vendor/cilex/cilex/src/Cilex/Application.php:66
    PHP   4. Symfony\Component\Console\Application->doRun() /home/andreas/dev/php/autarky-framework/vendor/symfony/console/Application.php:123
    PHP   5. Symfony\Component\Console\Application->doRunCommand() /home/andreas/dev/php/autarky-framework/vendor/symfony/console/Application.php:192
    PHP   6. Symfony\Component\Console\Command\Command->run() /home/andreas/dev/php/autarky-framework/vendor/symfony/console/Application.php:841
    PHP   7. Tuli\Command\Analyze->execute() /home/andreas/dev/php/autarky-framework/vendor/symfony/console/Command/Command.php:259
    PHP   8. Tuli\Command->execute() /home/andreas/dev/php/autarky-framework/vendor/ircmaxell/tuli/lib/Tuli/Command/Analyze.php:32
    PHP   9. Tuli\Command->getGraphsFromFiles() /home/andreas/dev/php/autarky-framework/vendor/ircmaxell/tuli/lib/Tuli/Command.php:59
    PHP  10. PHPCfg\Parser->parse() /home/andreas/dev/php/autarky-framework/vendor/ircmaxell/tuli/lib/Tuli/Command.php:107
    PHP  11. PHPCfg\Parser->parseNodes() /home/andreas/dev/php/autarky-framework/vendor/ircmaxell/php-cfg/lib/PHPCfg/Parser.php:62
    PHP  12. PHPCfg\Parser->parseNode() /home/andreas/dev/php/autarky-framework/vendor/ircmaxell/php-cfg/lib/PHPCfg/Parser.php:86
    PHP  13. PHPCfg\Parser->parseStmt_Namespace() /home/andreas/dev/php/autarky-framework/vendor/ircmaxell/php-cfg/lib/PHPCfg/Parser.php:100
    PHP  14. PHPCfg\Parser->parseNodes() /home/andreas/dev/php/autarky-framework/vendor/ircmaxell/php-cfg/lib/PHPCfg/Parser.php:382
    PHP  15. PHPCfg\Parser->parseNode() /home/andreas/dev/php/autarky-framework/vendor/ircmaxell/php-cfg/lib/PHPCfg/Parser.php:86
    PHP  16. PHPCfg\Parser->parseStmt_Class() /home/andreas/dev/php/autarky-framework/vendor/ircmaxell/php-cfg/lib/PHPCfg/Parser.php:100
    PHP  17. PHPCfg\Parser->parseNodes() /home/andreas/dev/php/autarky-framework/vendor/ircmaxell/php-cfg/lib/PHPCfg/Parser.php:115
    PHP  18. PHPCfg\Parser->parseNode() /home/andreas/dev/php/autarky-framework/vendor/ircmaxell/php-cfg/lib/PHPCfg/Parser.php:86
    PHP  19. PHPCfg\Parser->parseStmt_ClassMethod() /home/andreas/dev/php/autarky-framework/vendor/ircmaxell/php-cfg/lib/PHPCfg/Parser.php:100
    PHP  20. PHPCfg\Parser->parseNodes() /home/andreas/dev/php/autarky-framework/vendor/ircmaxell/php-cfg/lib/PHPCfg/Parser.php:144
    PHP  21. PHPCfg\Parser->parseNode() /home/andreas/dev/php/autarky-framework/vendor/ircmaxell/php-cfg/lib/PHPCfg/Parser.php:86
    PHP  22. PHPCfg\Parser->parseStmt_Foreach() /home/andreas/dev/php/autarky-framework/vendor/ircmaxell/php-cfg/lib/PHPCfg/Parser.php:100
    PHP  23. PHPCfg\Parser->parseNodes() /home/andreas/dev/php/autarky-framework/vendor/ircmaxell/php-cfg/lib/PHPCfg/Parser.php:260
    PHP  24. PHPCfg\Parser->parseNode() /home/andreas/dev/php/autarky-framework/vendor/ircmaxell/php-cfg/lib/PHPCfg/Parser.php:86
    PHP  25. PHPCfg\Parser->parseExprNode() /home/andreas/dev/php/autarky-framework/vendor/ircmaxell/php-cfg/lib/PHPCfg/Parser.php:95
    PHP  26. PHPCfg\Parser->parseExpr_AssignRef() /home/andreas/dev/php/autarky-framework/vendor/ircmaxell/php-cfg/lib/PHPCfg/Parser.php:656
    

    ArrayUtil.php source code

    opened by anlutro 1
  • How it work under big project?

    How it work under big project?

    Hi I have web app under symfony framework

    In this project I want to analyze my sources in src folder. And I don't want analyze any vendor files. How I can do it with tule?

    Now then I run:

    bin/tuli analyze ./src
    

    It show me:

     Could not find parent symfony\component\httpkernel\bundle\bundle
    

    And if I run it with some vendor it also fail with errors.

    opened by nonlux 0
Owner
Anthony Ferrara
Anthony Ferrara
Slim PHP static proxy library

#SlimStatic Slim PHP static proxy library. Contents About Usage API Customizing License About SlimStatic provides a simple static interface to various

John Stevenson 17 May 12, 2022
"Static" interface for various Slim features

SlimFacades SlimFacades is a collection of facades for Slim PHP microframework, providing simple "static" interface for various Slim features. For exa

its 74 May 12, 2022
The PPI Framework Engine

PPI Framework PPI is the PHP Interoperability Framework. It provides an equal and open platform to empower PHP developers to pick the best tools from

PPI Framework 156 Sep 9, 2020
Slim 3 skeleton working with Google App Engine include cron configuration.

Slim3 GAE Skeleton Slim 3 skeleton working with Google App Engine include cron configuration. Demo https://slim3-gae-skeleton.appspot.com/health_check

Jared Chu 2 May 10, 2018
Pug template engine adapter for Slim

Pug for Slim For details about the template engine see phug-lang.com Installation Install with Composer: composer require pug/slim Usage with Slim 3 u

Pug PHP 5 May 18, 2022
A static analysis engine

A static analysis engine... Usage: bin/tuli analyze file1 file2 path Installation Install it as a composer dependency!!! $ composer require ircmaxell

Anthony Ferrara 171 Jan 31, 2022
PHP Static Analysis Tool - discover bugs in your code without running it!

PHPStan - PHP Static Analysis Tool PHPStan focuses on finding errors in your code without actually running it. It catches whole classes of bugs even b

PHPStan 11.6k Dec 30, 2022
Beautiful and understandable static analysis tool for PHP

PhpMetrics PhpMetrics provides metrics about PHP project and classes, with beautiful and readable HTML report. Documentation | Twitter | Contributing

PhpMetrics 2.3k Dec 22, 2022
Static code analysis to find violations in a dependency graph

PhpDependencyAnalysis PhpDependencyAnalysis is an extendable static code analysis for object-oriented PHP-Projects to generate dependency graphs from

Marco Muths 546 Dec 7, 2022
Performs advanced static analysis on PHP code

PHP Analyzer Please report bugs or feature requests via our website support system ? in bottom right or by emailing [email protected]. Contri

Continuous Inspection 443 Sep 23, 2022
A static php code analysis tool using the Graph Theory

Mondrian Ok guyz, you have a master degree in Graph Theory, you follow Law of Demeter and you live on S.O.L.I.D principles ? Let's have some Fun ! (^ω

Florent Genette 391 Nov 30, 2022
A static analysis tool for finding errors in PHP applications

Psalm Psalm is a static analysis tool for finding errors in PHP applications. Installation To get started, check out the installation guide. Live Demo

Vimeo 5k Jan 2, 2023
Deptrac is a static code analysis tool for PHP that helps you communicate, visualize and enforce architectural decisions in your projects

Deptrac is a static code analysis tool for PHP that helps you communicate, visualize and enforce architectural decisions in your projects. You can freely define your architectural layers over classes and which rules should apply to them.

QOSSMIC GmbH 2.2k Dec 30, 2022
WordPress core test suite function and class declaration stubs for static analysis by PHPStan

WordPress Core Test Suite Stubs This package provides stub declarations for the WordPress Core Test Suite functions, classes and interfaces. These stu

PHP Stubs Library 5 Dec 14, 2022
A static analysis tool for security

progpilot A static analyzer for security purposes Only PHP language is currently supported Installation Option 1: use standalone phar Download the lat

null 271 Dec 27, 2022
Docker image that provides static analysis tools for PHP

Static Analysis Tools for PHP Docker image providing static analysis tools for PHP. The list of available tools and the installer are actually managed

Jakub Zalas 1.1k Jan 1, 2023
Beautiful and understandable static analysis tool for PHP

PhpMetrics PhpMetrics provides metrics about PHP project and classes, with beautiful and readable HTML report. Documentation | Twitter | Contributing

PhpMetrics 2.3k Jan 5, 2023
The SensioLabs DeprecationDetector runs a static code analysis against your project's source code to find usages of deprecated methods, classes and interfaces

SensioLabs DeprecationDetector CAUTION: This package is abandoned and will no longer receive any updates. The SensioLabs DeprecationDetector runs a st

QOSSMIC GmbH 389 Nov 24, 2022
Static Analysis Results Baseliner

Static Analysis Results Baseliner (SARB) Why SARB Requirements Installing Using SARB Examples Further reading Why SARB? If you've tried to introduce a

Dave Liddament 151 Jan 3, 2023
A pure PHP implementation of the open Language Server Protocol. Provides static code analysis for PHP for any IDE.

A pure PHP implementation of the open Language Server Protocol. Provides static code analysis for PHP for any IDE.

Felix Becker 1.1k Jan 4, 2023