1. Go to this page and download the library: Download laravel/surveyor library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
laravel / surveyor example snippets
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();
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)) {
// ...
}
// 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();
// Read a method past the marker filter, to inspect a marker rather than act on it
$raw = $classResult->method('store');
// 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();
// Read a property past the marker filter
$raw = $classResult->property('email');
if ($classResult->hasConstant('STATUS_ACTIVE')) {
$constant = $classResult->getConstant('STATUS_ACTIVE');
}
use Attribute;
use Laravel\Surveyor\Contracts\Ignored;
#[Attribute(Attribute::TARGET_ALL)]
final class Ignore implements Ignored
{
//
}
use Laravel\Surveyor\Contracts\ConditionallyIgnored;
#[Attribute(Attribute::TARGET_ALL)]
final class Ignore implements ConditionallyIgnored
{
public function __construct(
public readonly string|array|null $unless = null,
public readonly string|array|null $when = null,
) {
}
public function unless(): string|array|null
{
return $this->unless;
}
public function when(): string|array|null
{
return $this->when;
}
}
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
}
// Nullability
$type->isNullable();
$type->nullable(true); // Mark as nullable
// Optionality
$type->isOptional();
$type->optional(); // Mark as optional
$type->
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();
use Laravel\Surveyor\Analyzer\Analyzer;
use Laravel\Surveyor\Analyzer\ModelAnalyzer;
$analyzer = app(Analyzer::class);
$result = $analyzer->analyzeClass(App\Models\User::class)->result();
// Properties will
$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();