find-type-issues

Detects type issues in PHP code. Finds implicit type coercion, mixed types in comparisons, unsafe casting, type mismatches in returns.

59 stars

Best use case

find-type-issues is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Detects type issues in PHP code. Finds implicit type coercion, mixed types in comparisons, unsafe casting, type mismatches in returns.

Teams using find-type-issues should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/find-type-issues/SKILL.md --create-dirs "https://raw.githubusercontent.com/dykyi-roman/awesome-claude-code/main/skills/find-type-issues/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/find-type-issues/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How find-type-issues Compares

Feature / Agentfind-type-issuesStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Detects type issues in PHP code. Finds implicit type coercion, mixed types in comparisons, unsafe casting, type mismatches in returns.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Type Issue Detection

Analyze PHP code for type safety issues.

## Detection Patterns

### 1. Implicit Type Coercion

```php
// 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

```php
// BUG: == instead of ===
if ($status == 0) { } // 'active' == 0 is true!

// 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

```php
// 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

```php
// 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

```php
// 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

```php
// 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

```php
// BUG: Numeric string comparison
$a = '10';
$b = '9';
if ($a > $b) { } // String comparison: '1' < '9', so false!

// FIXED:
if ((int) $a > (int) $b) { }
```

### 8. JSON Type Issues

```php
// 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

```php
// 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

```bash
# 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

```php
declare(strict_types=1);
```

### Use Strict Comparison

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

### Type Hints Everywhere

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

### Use instanceof

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

## Output Format

```markdown
### 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:**
```php
// Type-safe version
```
```

Related Skills

find-resource-leaks

59
from dykyi-roman/awesome-claude-code

Detects resource leaks in PHP code. Finds unclosed file handles, database connections not released, streams not freed, missing finally blocks, temporary files not cleaned.

find-race-conditions

59
from dykyi-roman/awesome-claude-code

Detects race conditions in PHP code. Finds shared mutable state, check-then-act patterns, TOCTOU vulnerabilities, concurrent modification issues.

find-null-pointer-issues

59
from dykyi-roman/awesome-claude-code

Detects null pointer issues in PHP code. Finds property/method access on null, missing null checks, nullable returns without handling, optional chaining gaps.

find-logic-errors

59
from dykyi-roman/awesome-claude-code

Detects logic errors in PHP code. Finds incorrect conditions, wrong operators, missing switch cases, inverted logic, short-circuit evaluation issues.

find-infinite-loops

59
from dykyi-roman/awesome-claude-code

Detects infinite loop risks in PHP code. Finds missing break conditions, incorrect loop variables, unbounded recursion, circular references.

find-exception-issues

59
from dykyi-roman/awesome-claude-code

Detects exception handling issues in PHP code. Finds swallowed exceptions, generic catches, missing exception handling, re-throwing without context, exception in finally.

find-boundary-issues

59
from dykyi-roman/awesome-claude-code

Detects boundary issues in PHP code. Finds array index out of bounds, empty collection access, off-by-one errors, integer overflow, string length issues.

create-prototype

59
from dykyi-roman/awesome-claude-code

Generates Prototype pattern implementations for PHP 8.4. Creates deep/shallow copy, clone customization, prototype registries, and immutable object duplication.

check-type-juggling

59
from dykyi-roman/awesome-claude-code

Detects PHP type juggling vulnerabilities. Identifies loose comparison with user input, in_array without strict mode, switch statement type coercion, and hash comparison bypasses.

bug-root-cause-finder

59
from dykyi-roman/awesome-claude-code

Root cause analysis methods for PHP bugs. Provides 5 Whys technique, fault tree analysis, git bisect guidance, and stack trace parsing.

yii-knowledge

59
from dykyi-roman/awesome-claude-code

Yii framework knowledge base. Provides Yii3 modular architecture, DDD integration, PSR-7/PSR-15 compliance, persistence, DI, security (RBAC, auth), event system (PSR-14), queue/jobs, infrastructure components (cache, rate limiter, HTTP client), testing, and antipatterns for Yii PHP projects.

troubleshooting-template

59
from dykyi-roman/awesome-claude-code

Generates troubleshooting guides and FAQ sections for PHP projects. Creates problem-solution documentation.