find-type-issues

检测 PHP 代码中的类型问题。发现隐式类型转换、比较中的混合类型、不安全的类型转换及返回值类型不匹配等问题。

仓库最近推送
GitHub Stars
109
Forks
26
Issues / PRs
1

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "find-type-issues":https://skillpi.com/zh/skills/deepskill-ac761ea4a483d480ad84b6d3805aca76dfe5f019207d168f2611536855d06049。安装前核对上游来源和版本:https://github.com/dykyi-roman/awesome-claude-code。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

检测 PHP 代码中的类型问题。发现隐式类型转换、比较中的混合类型、不安全的类型转换及返回值类型不匹配等问题。

0 下载

介绍来源: third_party · dykyi-roman · 0.0.1 参考来源

SkillPi 解读

能完成的任务
翻译待完成,请参阅来源文档。
输入和输出
减记
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: find-type-issues
description: Detects type issues in PHP code. Finds implicit type coercion, mixed types in comparisons, unsafe casting, type mismatches in returns.

Type Issue Detection

Analyze PHP code for type safety issues.

Detection Patterns

1. Implicit Type Coercion

// BUG: String to int coercion
$count = '10abc'; // PHP converts to 10
$total = $count + 5; // 15, not error

// BUG: Array comparison
$a = [1, 2, 3];
$b = '1,2,3';
if ($a == $b) { } // Unexpected comparison

// BUG: Boolean context
if ($string) { } // '0' is falsy, but non-empty

2. Loose Comparison Issues

// BUG: == instead of ===
if ($status == 0) { } // null, '', '0' and false all pass;
                      // 'active' == 0 is FALSE since PHP 8

// BUG: in_array without strict
if (in_array($value, $array)) { } // Type coercion
// FIXED: in_array($value, $array, true)

// BUG: array_search
$key = array_search($value, $array); // Returns false or key
if ($key) { } // Key 0 is falsy!

3. Unsafe Type Casting

// BUG: Casting truncates
$float = 10.9;
$int = (int) $float; // 10, not 11

// BUG: String to array casting
$array = (array) $object; // May include private properties

// BUG: Object casting
$stdClass = (object) $array; // Loses type information

4. Mixed Type Parameters

// BUG: Function accepts anything
function process($data) { // No type hint
    return $data['key']; // Assumes array
}

// BUG: Union type issues
function handle(string|int $id): void {
    echo strlen($id); // Fails if int
}

5. Return Type Mismatches

// BUG: Inconsistent return types
function getValue(): int {
    if ($condition) {
        return '42'; // String, not int
    }
    return 0;
}

// BUG: Nullable inconsistency
function find(): User { // Not nullable
    if (!$found) {
        return null; // Type error
    }
}

6. Array Type Issues

// BUG: Assuming array structure
/** @param array $data */
function process(array $data): void {
    foreach ($data['items'] as $item) { // 'items' may not exist
        echo $item['name']; // 'name' may not exist
    }
}

// BUG: Mixed array types
$mixed = [1, 'two', new User()]; // Hard to type

7. Numeric String Issues

// NOT a bug: two numeric strings are compared NUMERICALLY
$a = '10';
$b = '9';
if ($a > $b) { } // true — '10' and '9' are numeric strings, so 10 > 9

// REAL BUG: one side is not a numeric string → string comparison
$version = '10';
if ($version > 'v9') { } // false — falls back to byte-wise comparison

// REAL BUG: version-like strings never compare numerically
if ('1.10' > '1.9') { } // false — '1.10' as a number is 1.1

// FIXED: compare with an explicit, intended semantics
if ((int) $a > (int) $b) { }          // numeric intent
if (version_compare('1.10', '1.9', '>')) { } // version intent

8. JSON Type Issues

// BUG: Assuming JSON structure
$data = json_decode($json, true);
$name = $data['user']['name']; // May not exist

// BUG: JSON encoding failures
$result = json_encode($data); // May return false

9. DateTime Type Issues

// BUG: String date comparison
if ($date > '2024-01-01') { } // String comparison

// BUG: DateTime vs DateTimeImmutable
function setDate(DateTime $date): void { }
$immutable = new DateTimeImmutable();
$this->setDate($immutable); // Type error

Grep Patterns

# Loose comparison with 0
Grep: "==\s*0[^.]|0\s*==" --glob "**/*.php"

# in_array without strict
Grep: "in_array\([^,]+,[^,]+\)" --glob "**/*.php"

# Casting with (int) or (string)
Grep: "\(int\)\s*\$|\(string\)\s*\$|\(array\)\s*\$" --glob "**/*.php"

# Mixed parameter types
Grep: "function\s+\w+\(\$\w+[,)]" --glob "**/*.php"

Severity Classification

Pattern Severity
Loose comparison with sensitive data 🔴 Critical
Return type mismatch 🟠 Major
Missing strict in_array 🟠 Major
Untyped parameters 🟡 Minor
Implicit coercion 🟡 Minor

Best Practices

Use Strict Types

declare(strict_types=1);

Use Strict Comparison

if ($status === 0) { }
if (in_array($value, $array, true)) { }

Type Hints Everywhere

function process(array $items): int
{
    return count($items);
}

Use instanceof

if ($object instanceof User) {
    $object->getName();
}

Output Format

### Type Issue: [Description]

**Severity:** 🔴/🟠/🟡
**Location:** `file.php:line`
**Type:** [Coercion|Loose Comparison|Unsafe Cast|...]

**Issue:**
[Description of the type safety problem]

**Code:**
```php
// Problematic code

Fix:

// Type-safe version

当前收录版本

0.0.1

核对来源版本 ↗

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值85/100

亮点

  • 提供 PHP 代码类型问题检测能力,覆盖隐式类型转换、松散比较、不安全类型转换、返回值类型不匹配等常见问题
  • 具有明确的实用价值,适用于 PHP 开发者日常代码质量保障
触发精准95/100

亮点

  • description 明确描述了功能,并列举了具体问题类型,触发词精准完整,边界清晰
结构规范90/100

亮点

  • 文档结构清晰,包含 Detection Patterns、Grep Patterns、Severity Classification、Best Practices、Output Format 等章节
  • 步骤划分明确,有多个端到端代码示例,frontmatter 完整
执行可靠88/100

亮点

  • 提供了具体的检测模式、grep 模式、严重性分类和最佳实践,逻辑完整
  • 工具来源(grep)明确,参数正确,覆盖了主要异常场景,并提供了修复建议
证据可验 (前四项均值)90/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。