Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ircmaxell/Tuli
A static analysis engine
https://github.com/ircmaxell/Tuli
Last synced: 15 days ago
JSON representation
A static analysis engine
- Host: GitHub
- URL: https://github.com/ircmaxell/Tuli
- Owner: ircmaxell
- License: mit
- Created: 2015-07-10T23:24:25.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-10-23T17:55:59.000Z (about 9 years ago)
- Last Synced: 2024-04-14T00:47:23.261Z (7 months ago)
- Language: PHP
- Size: 480 KB
- Stars: 169
- Watchers: 11
- Forks: 7
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/ircmaxell/Tuli.svg)](https://travis-ci.org/ircmaxell/Tuli)
## 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
$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
DoneThe 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
foo(1.0);
}
```Running:
$ bin/tuli analyze code.php
Analyzing code.phpDetermining 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
DoneAgain, 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.