PHPackages                             laravel/surveyor - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. laravel/surveyor

ActiveLibrary[Framework](/categories/framework)

laravel/surveyor
================

Static analysis tool for Laravel applications.

v0.1.9(2mo ago)7639.0k↑18.6%18[2 issues](https://github.com/laravel/surveyor/issues)6MITPHPPHP ^8.2CI passing

Since Sep 11Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/laravel/surveyor)[ Packagist](https://packagist.org/packages/laravel/surveyor)[ Docs](https://github.com/laravel/surveyor)[ RSS](/packages/laravel-surveyor/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (24)Versions (28)Used By (6)

[![Build Status](https://github.com/laravel/surveyor/workflows/tests/badge.svg)](https://github.com/laravel/surveyor/actions)[![Total Downloads](https://camo.githubusercontent.com/5737ebff5973e331a201edd0b66fb8bb4b491b821068526dd5cd04044cf62fe6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c61726176656c2f7375727665796f72)](https://packagist.org/packages/laravel/surveyor)[![Latest Stable Version](https://camo.githubusercontent.com/9fdf69b50265f0f94c2193d20f63e8c99657fa9c09c3d04c7053093d139f62f2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c61726176656c2f7375727665796f72)](https://packagist.org/packages/laravel/surveyor)[![License](https://camo.githubusercontent.com/987eaf635bb62225243b5f45e8575c3324b0a8c4b18cf9a91775912255f22b75/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6c61726176656c2f7375727665796f72)](https://packagist.org/packages/laravel/surveyor)

Laravel Surveyor
================

[](#laravel-surveyor)

Introduction
------------

[](#introduction)

Laravel Surveyor is a powerful (mostly) static analysis tool designed to extract detailed PHP and Laravel-specific information from your code. It parses and analyzes PHP files to extract comprehensive metadata about classes, methods, properties, return types, and more — making this information available in a structured, consumable format for use by other tools and packages.

If you want high-level consumption of the results packaged in detailed DTOs, check out [Laravel Ranger](https://github.com/laravel/ranger).

Important

Surveyor is currently in Beta, the API is subject (and likely) to change prior to the v1.0.0 release. All notable changes will be documented in the [changelog](./CHANGELOG.md).

Installation
------------

[](#installation)

You may install Surveyor via Composer:

```
composer require laravel/surveyor
```

Notes
-----

[](#notes)

### Not Strictly Static Analysis

[](#not-strictly-static-analysis)

While Surveyor is *mostly* static analysis, it does attempt to inspect your models (which means a brief database connection) and also inspects your app bindings to get more detailed information in the analysis.

### Performance

[](#performance)

The performance is not where we want it to be yet, it runs slower than is ideal and uses more memory than we'd like. We're looking for active contributions in those specific areas.

Basic Usage
-----------

[](#basic-usage)

### Analyzing a File

[](#analyzing-a-file)

The primary way to use Surveyor is through the `Analyzer` class, which can analyze PHP files and extract detailed information:

```
use Laravel\Surveyor\Analyzer\Analyzer;

$analyzer = app(Analyzer::class);

// Analyze a file by path
$result = $analyzer->analyze('/path/to/your/File.php');

// Access the analyzed scope
$scope = $result->analyzed();

// Access the class result
$classResult = $result->result();
```

### Analyzing a Class

[](#analyzing-a-class)

You can also analyze a class directly by its fully qualified class name:

```
use Laravel\Surveyor\Analyzer\Analyzer;

$analyzer = app(Analyzer::class);

$result = $analyzer->analyzeClass(\App\Models\User::class);
$classResult = $result->result();
```

Working with Results
--------------------

[](#working-with-results)

### ClassResult

[](#classresult)

After analyzing a file containing a class, you'll receive a `ClassResult` object that provides access to the class's metadata:

```
use Laravel\Surveyor\Analyzer\Analyzer;

$analyzer = app(Analyzer::class);
$classResult = $analyzer->analyzeClass(App\Models\User::class)->result();

// Get class information
$name = $classResult->name();           // 'App\Models\User'
$namespace = $classResult->namespace(); // 'App\Models'
$filePath = $classResult->filePath();

// Check inheritance
$extends = $classResult->extends();      // Returns array of parent classes
$implements = $classResult->implements(); // Returns array of interfaces

// Check if class implements specific interfaces
if ($classResult->implements(JsonSerializable::class)) {
    // ...
}
```

### Methods

[](#methods)

Access information about class methods:

```
// Check if a method exists
if ($classResult->hasMethod('store')) {
    $method = $classResult->getMethod('store');

    // Get method name
    $methodName = $method->name();

    // Get return type
    $returnType = $method->returnType();

    // Get parameters
    $parameters = $method->parameters();

    // Get validation rules (if any are defined in the method)
    $rules = $method->validationRules();
}

// Get all public methods
$publicMethods = $classResult->publicMethods();
```

### Properties

[](#properties)

Access information about class properties:

```
// Check if a property exists
if ($classResult->hasProperty('email')) {
    $property = $classResult->getProperty('email');

    $name = $property->name;
    $type = $property->type;
    $visibility = $property->visibility; // 'public', 'protected', or 'private'
}

// Get all public properties
$publicProperties = $classResult->publicProperties();
```

### Constants

[](#constants)

Access class constants:

```
if ($classResult->hasConstant('STATUS_ACTIVE')) {
    $constant = $classResult->getConstant('STATUS_ACTIVE');
}
```

Type System
-----------

[](#type-system)

Surveyor includes a comprehensive type system for representing PHP types. All types implement the `Laravel\Surveyor\Types\Contracts\Type` interface.

### Available Types

[](#available-types)

TypeDescription`StringType`Represents string values`IntType`Represents integer values`FloatType`Represents floating-point values`BoolType`Represents boolean values`ArrayType`Represents array values`ArrayShapeType`Represents arrays with specific key/value types`ClassType`Represents class/object instances`UnionType`Represents union types (e.g., `string|int`)`IntersectionType`Represents intersection types`NullType`Represents null values`VoidType`Represents void return types`MixedType`Represents mixed types`CallableType`Represents callable types`NeverType`Represents never return types### Creating Types

[](#creating-types)

Use the `Type` factory class to create type instances:

```
use Laravel\Surveyor\Types\Type;

// Primitive types
$stringType = Type::string();
$intType = Type::int();
$boolType = Type::bool();
$floatType = Type::float();
$nullType = Type::null();
$voidType = Type::void();
$mixedType = Type::mixed();

// Arrays
$arrayType = Type::array([]);
$arrayShapeType = Type::arrayShape(Type::string(), Type::int());

// Union types
$unionType = Type::union(Type::string(), Type::null());

// Intersection types
$intersectionType = Type::intersection($type1, $type2);

// Convert from values
$type = Type::from('string'); // Returns StringType
$type = Type::from(42);       // Returns IntType with value
```

### Type Checking

[](#type-checking)

```
use Laravel\Surveyor\Types\Type;
use Laravel\Surveyor\Types\StringType;
use Laravel\Surveyor\Types\ClassType;

// Check if type is a specific class
if (Type::is($returnType, StringType::class)) {
    // Handle string type
}

// Check multiple types
if (Type::is($returnType, StringType::class, ClassType::class)) {
    // Handle string or class type
}

// Compare types
if (Type::isSame($type1, $type2)) {
    // Types are the same
}
```

### Type Properties

[](#type-properties)

All types support common properties:

```
// Nullability
$type->isNullable();
$type->nullable(true);  // Mark as nullable

// Optionality
$type->isOptional();
$type->optional();      // Mark as optional
$type->required();      // Mark as required

// String representation
$typeString = $type->toString();
```

Caching
-------

[](#caching)

Surveyor includes a caching system to improve performance when analyzing files repeatedly.

### Environment-Based Configuration

[](#environment-based-configuration)

Configure caching via environment variables:

```
SURVEYOR_CACHE_ENABLED=true
SURVEYOR_CACHE_DIR=/path/to/cache
```

### Programmatic Configuration

[](#programmatic-configuration)

```
use Laravel\Surveyor\Analyzer\AnalyzedCache;

// Enable disk caching
AnalyzedCache::setCacheDirectory(storage_path('surveyor-cache'));
AnalyzedCache::enable();

// Or use the convenience method
AnalyzedCache::enableDiskCache(storage_path('surveyor-cache'));

// Disable caching
AnalyzedCache::disable();

// Clear all cached data
AnalyzedCache::clear();

// Clear only in-memory cache
AnalyzedCache::clearMemory();
```

The cache automatically tracks file modification times and invalidates entries when files change. Dependencies between files are also tracked, so changes to parent classes or traits will invalidate dependent caches.

Model Analysis
--------------

[](#model-analysis)

Surveyor includes special support for analyzing Eloquent models, including automatic detection of:

- Database attributes and their types
- Model relationships
- Attribute accessors and mutators
- Cast definitions

```
use Laravel\Surveyor\Analyzer\Analyzer;
use Laravel\Surveyor\Analyzer\ModelAnalyzer;

$analyzer = app(Analyzer::class);
$result = $analyzer->analyzeClass(App\Models\User::class)->result();

// Properties will include database attributes
$emailProperty = $result->getProperty('email');

// Relationship methods are flagged
$method = $result->getMethod('posts');
if ($method->isModelRelation()) {
    // This is a relationship method
}
```

Scope Information
-----------------

[](#scope-information)

When analyzing files, Surveyor provides detailed scope information including:

### Namespace and Use Statements

[](#namespace-and-use-statements)

```
$scope = $analyzer->analyze($path)->analyzed();

// Get namespace
$namespace = $scope->namespace();

// Get resolved use statement
$fullyQualified = $scope->getUse('Request'); // 'Illuminate\Http\Request'

// Get all use statements
$uses = $scope->uses();
```

### Variable State Tracking

[](#variable-state-tracking)

Surveyor tracks variable types and states throughout method bodies:

```
$stateTracker = $scope->state();

// Access tracked variables
$variables = $stateTracker->variables();

// Access tracked properties
$properties = $stateTracker->properties();
```

Contributing
------------

[](#contributing)

Thank you for considering contributing to Surveyor! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions).

Code of Conduct
---------------

[](#code-of-conduct)

In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct).

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](https://github.com/laravel/surveyor/security/policy) on how to report security vulnerabilities.

License
-------

[](#license)

Laravel Surveyor is open-sourced software licensed under the [MIT license](LICENSE.md).

###  Health Score

55

—

FairBetter than 98% of packages

Maintenance87

Actively maintained with recent releases

Popularity47

Moderate usage in the ecosystem

Community30

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 93.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~9 days

Recently: every ~17 days

Total

10

Last Release

62d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/463230?v=4)[Taylor Otwell](/maintainers/taylorotwell)[@taylorotwell](https://github.com/taylorotwell)

---

Top Contributors

[![joetannenbaum](https://avatars.githubusercontent.com/u/2702148?v=4)](https://github.com/joetannenbaum "joetannenbaum (264 commits)")[![cosmastech](https://avatars.githubusercontent.com/u/42181698?v=4)](https://github.com/cosmastech "cosmastech (4 commits)")[![taylorotwell](https://avatars.githubusercontent.com/u/463230?v=4)](https://github.com/taylorotwell "taylorotwell (3 commits)")[![Jasonej](https://avatars.githubusercontent.com/u/43227214?v=4)](https://github.com/Jasonej "Jasonej (1 commits)")[![jornicornelese](https://avatars.githubusercontent.com/u/40827393?v=4)](https://github.com/jornicornelese "jornicornelese (1 commits)")[![apreezofficial](https://avatars.githubusercontent.com/u/193069706?v=4)](https://github.com/apreezofficial "apreezofficial (1 commits)")[![nunomaduro](https://avatars.githubusercontent.com/u/5457236?v=4)](https://github.com/nunomaduro "nunomaduro (1 commits)")[![pascalbaljet](https://avatars.githubusercontent.com/u/8403149?v=4)](https://github.com/pascalbaljet "pascalbaljet (1 commits)")[![PenguinNexus](https://avatars.githubusercontent.com/u/16801642?v=4)](https://github.com/PenguinNexus "PenguinNexus (1 commits)")[![raphaelstolt](https://avatars.githubusercontent.com/u/48225?v=4)](https://github.com/raphaelstolt "raphaelstolt (1 commits)")[![robertvansteen](https://avatars.githubusercontent.com/u/14931924?v=4)](https://github.com/robertvansteen "robertvansteen (1 commits)")[![ryangjchandler](https://avatars.githubusercontent.com/u/41837763?v=4)](https://github.com/ryangjchandler "ryangjchandler (1 commits)")[![Michael4d45](https://avatars.githubusercontent.com/u/2423882?v=4)](https://github.com/Michael4d45 "Michael4d45 (1 commits)")[![ashleyhindle](https://avatars.githubusercontent.com/u/454975?v=4)](https://github.com/ashleyhindle "ashleyhindle (1 commits)")[![crynobone](https://avatars.githubusercontent.com/u/172966?v=4)](https://github.com/crynobone "crynobone (1 commits)")

---

Tags

laravel

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/laravel-surveyor/health.svg)

```
[![Health](https://phpackages.com/badges/laravel-surveyor/health.svg)](https://phpackages.com/packages/laravel-surveyor)
```

###  Alternatives

[laravel/ranger

Laravel Ranger is a powerful introspection library for Laravel applications.

5138.9k4](/packages/laravel-ranger)[laravel/tinker

Powerful REPL for the Laravel framework.

7.4k423.8M1.8k](/packages/laravel-tinker)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.5k25.9M107](/packages/laravel-cashier)[laravel/boost

Laravel Boost accelerates AI-assisted development by providing the essential context and structure that AI needs to generate high-quality, Laravel-specific code.

3.5k10.6M274](/packages/laravel-boost)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k12.1M99](/packages/laravel-pulse)[laravel/passport

Laravel Passport provides OAuth2 server support to Laravel.

3.4k85.0M532](/packages/laravel-passport)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
