ircmaxell/tuli 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ircmaxell/tuli

Composer 安装命令:

composer require ircmaxell/tuli

包简介

A Static Analyzer for PHP

README 文档

README

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.

ircmaxell/tuli 适用场景与选型建议

ircmaxell/tuli 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 351 次下载、GitHub Stars 达 169, 最近一次更新时间为 2015 年 07 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 ircmaxell/tuli 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 ircmaxell/tuli 我们能提供哪些服务?
定制开发 / 二次开发

基于 ircmaxell/tuli 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 351
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 169
  • 点击次数: 23
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 169
  • Watchers: 9
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: BSD
  • 更新时间: 2015-07-13