repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
sequence
docstring
stringlengths
3
47.2k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
laravel/telescope
src/Telescope.php
Telescope.collectUpdates
protected static function collectUpdates($batchId) { return collect(static::$updatesQueue) ->each(function ($entry) use ($batchId) { $entry->change(['updated_batch_id' => $batchId]); }); }
php
protected static function collectUpdates($batchId) { return collect(static::$updatesQueue) ->each(function ($entry) use ($batchId) { $entry->change(['updated_batch_id' => $batchId]); }); }
[ "protected", "static", "function", "collectUpdates", "(", "$", "batchId", ")", "{", "return", "collect", "(", "static", "::", "$", "updatesQueue", ")", "->", "each", "(", "function", "(", "$", "entry", ")", "use", "(", "$", "batchId", ")", "{", "$", "entry", "->", "change", "(", "[", "'updated_batch_id'", "=>", "$", "batchId", "]", ")", ";", "}", ")", ";", "}" ]
Collect the updated entries for storage. @param string $batchId @return \Illuminate\Support\Collection
[ "Collect", "the", "updated", "entries", "for", "storage", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Telescope.php#L591-L597
train
laravel/telescope
src/TelescopeServiceProvider.php
TelescopeServiceProvider.registerStorageDriver
protected function registerStorageDriver() { $driver = config('telescope.driver'); if (method_exists($this, $method = 'register'.ucfirst($driver).'Driver')) { $this->$method(); } }
php
protected function registerStorageDriver() { $driver = config('telescope.driver'); if (method_exists($this, $method = 'register'.ucfirst($driver).'Driver')) { $this->$method(); } }
[ "protected", "function", "registerStorageDriver", "(", ")", "{", "$", "driver", "=", "config", "(", "'telescope.driver'", ")", ";", "if", "(", "method_exists", "(", "$", "this", ",", "$", "method", "=", "'register'", ".", "ucfirst", "(", "$", "driver", ")", ".", "'Driver'", ")", ")", "{", "$", "this", "->", "$", "method", "(", ")", ";", "}", "}" ]
Register the package storage driver. @return void
[ "Register", "the", "package", "storage", "driver", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/TelescopeServiceProvider.php#L126-L133
train
laravel/telescope
src/TelescopeServiceProvider.php
TelescopeServiceProvider.registerDatabaseDriver
protected function registerDatabaseDriver() { $this->app->singleton( EntriesRepository::class, DatabaseEntriesRepository::class ); $this->app->singleton( ClearableRepository::class, DatabaseEntriesRepository::class ); $this->app->singleton( PrunableRepository::class, DatabaseEntriesRepository::class ); $this->app->when(DatabaseEntriesRepository::class) ->needs('$connection') ->give(config('telescope.storage.database.connection')); $this->app->when(DatabaseEntriesRepository::class) ->needs('$chunkSize') ->give(config('telescope.storage.database.chunk')); }
php
protected function registerDatabaseDriver() { $this->app->singleton( EntriesRepository::class, DatabaseEntriesRepository::class ); $this->app->singleton( ClearableRepository::class, DatabaseEntriesRepository::class ); $this->app->singleton( PrunableRepository::class, DatabaseEntriesRepository::class ); $this->app->when(DatabaseEntriesRepository::class) ->needs('$connection') ->give(config('telescope.storage.database.connection')); $this->app->when(DatabaseEntriesRepository::class) ->needs('$chunkSize') ->give(config('telescope.storage.database.chunk')); }
[ "protected", "function", "registerDatabaseDriver", "(", ")", "{", "$", "this", "->", "app", "->", "singleton", "(", "EntriesRepository", "::", "class", ",", "DatabaseEntriesRepository", "::", "class", ")", ";", "$", "this", "->", "app", "->", "singleton", "(", "ClearableRepository", "::", "class", ",", "DatabaseEntriesRepository", "::", "class", ")", ";", "$", "this", "->", "app", "->", "singleton", "(", "PrunableRepository", "::", "class", ",", "DatabaseEntriesRepository", "::", "class", ")", ";", "$", "this", "->", "app", "->", "when", "(", "DatabaseEntriesRepository", "::", "class", ")", "->", "needs", "(", "'$connection'", ")", "->", "give", "(", "config", "(", "'telescope.storage.database.connection'", ")", ")", ";", "$", "this", "->", "app", "->", "when", "(", "DatabaseEntriesRepository", "::", "class", ")", "->", "needs", "(", "'$chunkSize'", ")", "->", "give", "(", "config", "(", "'telescope.storage.database.chunk'", ")", ")", ";", "}" ]
Register the package database storage driver. @return void
[ "Register", "the", "package", "database", "storage", "driver", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/TelescopeServiceProvider.php#L140-L161
train
laravel/telescope
src/Http/Controllers/EntryController.php
EntryController.status
protected function status() { if (! config('telescope.enabled', false)) { return 'disabled'; } if (cache('telescope:pause-recording', false)) { return 'paused'; } $watcher = config('telescope.watchers.'.$this->watcher()); if (! $watcher || (isset($watcher['enabled']) && ! $watcher['enabled'])) { return 'off'; } return 'enabled'; }
php
protected function status() { if (! config('telescope.enabled', false)) { return 'disabled'; } if (cache('telescope:pause-recording', false)) { return 'paused'; } $watcher = config('telescope.watchers.'.$this->watcher()); if (! $watcher || (isset($watcher['enabled']) && ! $watcher['enabled'])) { return 'off'; } return 'enabled'; }
[ "protected", "function", "status", "(", ")", "{", "if", "(", "!", "config", "(", "'telescope.enabled'", ",", "false", ")", ")", "{", "return", "'disabled'", ";", "}", "if", "(", "cache", "(", "'telescope:pause-recording'", ",", "false", ")", ")", "{", "return", "'paused'", ";", "}", "$", "watcher", "=", "config", "(", "'telescope.watchers.'", ".", "$", "this", "->", "watcher", "(", ")", ")", ";", "if", "(", "!", "$", "watcher", "||", "(", "isset", "(", "$", "watcher", "[", "'enabled'", "]", ")", "&&", "!", "$", "watcher", "[", "'enabled'", "]", ")", ")", "{", "return", "'off'", ";", "}", "return", "'enabled'", ";", "}" ]
Determine the watcher recording status. @return string
[ "Determine", "the", "watcher", "recording", "status", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Http/Controllers/EntryController.php#L66-L83
train
laravel/telescope
src/Watchers/ExceptionWatcher.php
ExceptionWatcher.recordException
public function recordException(MessageLogged $event) { if (! Telescope::isRecording() || $this->shouldIgnore($event)) { return; } $exception = $event->context['exception']; Telescope::recordException( IncomingExceptionEntry::make($exception, [ 'class' => get_class($exception), 'file' => $exception->getFile(), 'line' => $exception->getLine(), 'message' => $exception->getMessage(), 'trace' => $exception->getTrace(), 'line_preview' => ExceptionContext::get($exception), ])->tags($this->tags($event)) ); }
php
public function recordException(MessageLogged $event) { if (! Telescope::isRecording() || $this->shouldIgnore($event)) { return; } $exception = $event->context['exception']; Telescope::recordException( IncomingExceptionEntry::make($exception, [ 'class' => get_class($exception), 'file' => $exception->getFile(), 'line' => $exception->getLine(), 'message' => $exception->getMessage(), 'trace' => $exception->getTrace(), 'line_preview' => ExceptionContext::get($exception), ])->tags($this->tags($event)) ); }
[ "public", "function", "recordException", "(", "MessageLogged", "$", "event", ")", "{", "if", "(", "!", "Telescope", "::", "isRecording", "(", ")", "||", "$", "this", "->", "shouldIgnore", "(", "$", "event", ")", ")", "{", "return", ";", "}", "$", "exception", "=", "$", "event", "->", "context", "[", "'exception'", "]", ";", "Telescope", "::", "recordException", "(", "IncomingExceptionEntry", "::", "make", "(", "$", "exception", ",", "[", "'class'", "=>", "get_class", "(", "$", "exception", ")", ",", "'file'", "=>", "$", "exception", "->", "getFile", "(", ")", ",", "'line'", "=>", "$", "exception", "->", "getLine", "(", ")", ",", "'message'", "=>", "$", "exception", "->", "getMessage", "(", ")", ",", "'trace'", "=>", "$", "exception", "->", "getTrace", "(", ")", ",", "'line_preview'", "=>", "ExceptionContext", "::", "get", "(", "$", "exception", ")", ",", "]", ")", "->", "tags", "(", "$", "this", "->", "tags", "(", "$", "event", ")", ")", ")", ";", "}" ]
Record an exception was logged. @param \Illuminate\Log\Events\MessageLogged $event @return void
[ "Record", "an", "exception", "was", "logged", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Watchers/ExceptionWatcher.php#L31-L49
train
laravel/telescope
src/Watchers/JobWatcher.php
JobWatcher.recordJob
public function recordJob($connection, $queue, array $payload) { if (! Telescope::isRecording()) { return; } $content = array_merge([ 'status' => 'pending', ], $this->defaultJobData($connection, $queue, $payload, $this->data($payload))); Telescope::recordJob( $entry = IncomingEntry::make($content) ->tags($this->tags($payload)) ); return $entry; }
php
public function recordJob($connection, $queue, array $payload) { if (! Telescope::isRecording()) { return; } $content = array_merge([ 'status' => 'pending', ], $this->defaultJobData($connection, $queue, $payload, $this->data($payload))); Telescope::recordJob( $entry = IncomingEntry::make($content) ->tags($this->tags($payload)) ); return $entry; }
[ "public", "function", "recordJob", "(", "$", "connection", ",", "$", "queue", ",", "array", "$", "payload", ")", "{", "if", "(", "!", "Telescope", "::", "isRecording", "(", ")", ")", "{", "return", ";", "}", "$", "content", "=", "array_merge", "(", "[", "'status'", "=>", "'pending'", ",", "]", ",", "$", "this", "->", "defaultJobData", "(", "$", "connection", ",", "$", "queue", ",", "$", "payload", ",", "$", "this", "->", "data", "(", "$", "payload", ")", ")", ")", ";", "Telescope", "::", "recordJob", "(", "$", "entry", "=", "IncomingEntry", "::", "make", "(", "$", "content", ")", "->", "tags", "(", "$", "this", "->", "tags", "(", "$", "payload", ")", ")", ")", ";", "return", "$", "entry", ";", "}" ]
Record a job being created. @param string $connection @param string $queue @param array $payload @return \Laravel\Telescope\IncomingEntry|null
[ "Record", "a", "job", "being", "created", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Watchers/JobWatcher.php#L42-L58
train
laravel/telescope
src/Watchers/JobWatcher.php
JobWatcher.recordProcessedJob
public function recordProcessedJob(JobProcessed $event) { if (! Telescope::isRecording()) { return; } $uuid = $event->job->payload()['telescope_uuid'] ?? null; if (! $uuid) { return; } Telescope::recordUpdate(EntryUpdate::make( $uuid, EntryType::JOB, ['status' => 'processed'] )); }
php
public function recordProcessedJob(JobProcessed $event) { if (! Telescope::isRecording()) { return; } $uuid = $event->job->payload()['telescope_uuid'] ?? null; if (! $uuid) { return; } Telescope::recordUpdate(EntryUpdate::make( $uuid, EntryType::JOB, ['status' => 'processed'] )); }
[ "public", "function", "recordProcessedJob", "(", "JobProcessed", "$", "event", ")", "{", "if", "(", "!", "Telescope", "::", "isRecording", "(", ")", ")", "{", "return", ";", "}", "$", "uuid", "=", "$", "event", "->", "job", "->", "payload", "(", ")", "[", "'telescope_uuid'", "]", "??", "null", ";", "if", "(", "!", "$", "uuid", ")", "{", "return", ";", "}", "Telescope", "::", "recordUpdate", "(", "EntryUpdate", "::", "make", "(", "$", "uuid", ",", "EntryType", "::", "JOB", ",", "[", "'status'", "=>", "'processed'", "]", ")", ")", ";", "}" ]
Record a queued job was processed. @param \Illuminate\Queue\Events\JobProcessed $event @return void
[ "Record", "a", "queued", "job", "was", "processed", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Watchers/JobWatcher.php#L66-L81
train
laravel/telescope
src/Watchers/JobWatcher.php
JobWatcher.recordFailedJob
public function recordFailedJob(JobFailed $event) { if (! Telescope::isRecording()) { return; } $uuid = $event->job->payload()['telescope_uuid'] ?? null; if (! $uuid) { return; } Telescope::recordUpdate(EntryUpdate::make( $uuid, EntryType::JOB, [ 'status' => 'failed', 'exception' => [ 'message' => $event->exception->getMessage(), 'trace' => $event->exception->getTrace(), 'line' => $event->exception->getLine(), 'line_preview' => ExceptionContext::get($event->exception), ], ] )->addTags(['failed'])); }
php
public function recordFailedJob(JobFailed $event) { if (! Telescope::isRecording()) { return; } $uuid = $event->job->payload()['telescope_uuid'] ?? null; if (! $uuid) { return; } Telescope::recordUpdate(EntryUpdate::make( $uuid, EntryType::JOB, [ 'status' => 'failed', 'exception' => [ 'message' => $event->exception->getMessage(), 'trace' => $event->exception->getTrace(), 'line' => $event->exception->getLine(), 'line_preview' => ExceptionContext::get($event->exception), ], ] )->addTags(['failed'])); }
[ "public", "function", "recordFailedJob", "(", "JobFailed", "$", "event", ")", "{", "if", "(", "!", "Telescope", "::", "isRecording", "(", ")", ")", "{", "return", ";", "}", "$", "uuid", "=", "$", "event", "->", "job", "->", "payload", "(", ")", "[", "'telescope_uuid'", "]", "??", "null", ";", "if", "(", "!", "$", "uuid", ")", "{", "return", ";", "}", "Telescope", "::", "recordUpdate", "(", "EntryUpdate", "::", "make", "(", "$", "uuid", ",", "EntryType", "::", "JOB", ",", "[", "'status'", "=>", "'failed'", ",", "'exception'", "=>", "[", "'message'", "=>", "$", "event", "->", "exception", "->", "getMessage", "(", ")", ",", "'trace'", "=>", "$", "event", "->", "exception", "->", "getTrace", "(", ")", ",", "'line'", "=>", "$", "event", "->", "exception", "->", "getLine", "(", ")", ",", "'line_preview'", "=>", "ExceptionContext", "::", "get", "(", "$", "event", "->", "exception", ")", ",", "]", ",", "]", ")", "->", "addTags", "(", "[", "'failed'", "]", ")", ")", ";", "}" ]
Record a queue job has failed. @param \Illuminate\Queue\Events\JobFailed $event @return void
[ "Record", "a", "queue", "job", "has", "failed", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Watchers/JobWatcher.php#L89-L112
train
laravel/telescope
src/Watchers/JobWatcher.php
JobWatcher.defaultJobData
protected function defaultJobData($connection, $queue, array $payload, array $data) { return [ 'connection' => $connection, 'queue' => $queue, 'name' => $payload['displayName'], 'tries' => $payload['maxTries'], 'timeout' => $payload['timeout'], 'data' => $data, ]; }
php
protected function defaultJobData($connection, $queue, array $payload, array $data) { return [ 'connection' => $connection, 'queue' => $queue, 'name' => $payload['displayName'], 'tries' => $payload['maxTries'], 'timeout' => $payload['timeout'], 'data' => $data, ]; }
[ "protected", "function", "defaultJobData", "(", "$", "connection", ",", "$", "queue", ",", "array", "$", "payload", ",", "array", "$", "data", ")", "{", "return", "[", "'connection'", "=>", "$", "connection", ",", "'queue'", "=>", "$", "queue", ",", "'name'", "=>", "$", "payload", "[", "'displayName'", "]", ",", "'tries'", "=>", "$", "payload", "[", "'maxTries'", "]", ",", "'timeout'", "=>", "$", "payload", "[", "'timeout'", "]", ",", "'data'", "=>", "$", "data", ",", "]", ";", "}" ]
Get the default entry data for the given job. @param string $connection @param string $queue @param array $payload @param array $data @return array
[ "Get", "the", "default", "entry", "data", "for", "the", "given", "job", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Watchers/JobWatcher.php#L123-L133
train
laravel/telescope
src/TelescopeApplicationServiceProvider.php
TelescopeApplicationServiceProvider.authorization
protected function authorization() { $this->gate(); Telescope::auth(function ($request) { return app()->environment('local') || Gate::check('viewTelescope', [$request->user()]); }); }
php
protected function authorization() { $this->gate(); Telescope::auth(function ($request) { return app()->environment('local') || Gate::check('viewTelescope', [$request->user()]); }); }
[ "protected", "function", "authorization", "(", ")", "{", "$", "this", "->", "gate", "(", ")", ";", "Telescope", "::", "auth", "(", "function", "(", "$", "request", ")", "{", "return", "app", "(", ")", "->", "environment", "(", "'local'", ")", "||", "Gate", "::", "check", "(", "'viewTelescope'", ",", "[", "$", "request", "->", "user", "(", ")", "]", ")", ";", "}", ")", ";", "}" ]
Configure the Telescope authorization services. @return void
[ "Configure", "the", "Telescope", "authorization", "services", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/TelescopeApplicationServiceProvider.php#L25-L33
train
laravel/telescope
src/EntryUpdate.php
EntryUpdate.addTags
public function addTags(array $tags) { $this->tagsChanges['added'] = array_unique( array_merge($this->tagsChanges['added'], $tags) ); return $this; }
php
public function addTags(array $tags) { $this->tagsChanges['added'] = array_unique( array_merge($this->tagsChanges['added'], $tags) ); return $this; }
[ "public", "function", "addTags", "(", "array", "$", "tags", ")", "{", "$", "this", "->", "tagsChanges", "[", "'added'", "]", "=", "array_unique", "(", "array_merge", "(", "$", "this", "->", "tagsChanges", "[", "'added'", "]", ",", "$", "tags", ")", ")", ";", "return", "$", "this", ";", "}" ]
Add tags to the entry. @param array $tags @return $this
[ "Add", "tags", "to", "the", "entry", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/EntryUpdate.php#L80-L87
train
laravel/telescope
src/EntryUpdate.php
EntryUpdate.removeTags
public function removeTags(array $tags) { $this->tagsChanges['removed'] = array_unique( array_merge($this->tagsChanges['removed'], $tags) ); return $this; }
php
public function removeTags(array $tags) { $this->tagsChanges['removed'] = array_unique( array_merge($this->tagsChanges['removed'], $tags) ); return $this; }
[ "public", "function", "removeTags", "(", "array", "$", "tags", ")", "{", "$", "this", "->", "tagsChanges", "[", "'removed'", "]", "=", "array_unique", "(", "array_merge", "(", "$", "this", "->", "tagsChanges", "[", "'removed'", "]", ",", "$", "tags", ")", ")", ";", "return", "$", "this", ";", "}" ]
Remove tags from the entry. @param array $tags @return $this
[ "Remove", "tags", "from", "the", "entry", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/EntryUpdate.php#L95-L102
train
laravel/telescope
src/Watchers/RedisWatcher.php
RedisWatcher.recordCommand
public function recordCommand(CommandExecuted $event) { if (! Telescope::isRecording() || $this->shouldIgnore($event)) { return; } Telescope::recordRedis(IncomingEntry::make([ 'connection' => $event->connectionName, 'command' => $this->formatCommand($event->command, $event->parameters), 'time' => number_format($event->time, 2), ])); }
php
public function recordCommand(CommandExecuted $event) { if (! Telescope::isRecording() || $this->shouldIgnore($event)) { return; } Telescope::recordRedis(IncomingEntry::make([ 'connection' => $event->connectionName, 'command' => $this->formatCommand($event->command, $event->parameters), 'time' => number_format($event->time, 2), ])); }
[ "public", "function", "recordCommand", "(", "CommandExecuted", "$", "event", ")", "{", "if", "(", "!", "Telescope", "::", "isRecording", "(", ")", "||", "$", "this", "->", "shouldIgnore", "(", "$", "event", ")", ")", "{", "return", ";", "}", "Telescope", "::", "recordRedis", "(", "IncomingEntry", "::", "make", "(", "[", "'connection'", "=>", "$", "event", "->", "connectionName", ",", "'command'", "=>", "$", "this", "->", "formatCommand", "(", "$", "event", "->", "command", ",", "$", "event", "->", "parameters", ")", ",", "'time'", "=>", "number_format", "(", "$", "event", "->", "time", ",", "2", ")", ",", "]", ")", ")", ";", "}" ]
Record a Redis command was executed. @param \Illuminate\Redis\Events\CommandExecuted $event @return void
[ "Record", "a", "Redis", "command", "was", "executed", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Watchers/RedisWatcher.php#L28-L39
train
laravel/telescope
src/Watchers/RedisWatcher.php
RedisWatcher.formatCommand
private function formatCommand($command, $parameters) { $parameters = collect($parameters)->map(function ($parameter) { if (is_array($parameter)) { return collect($parameter)->map(function ($value, $key) { return is_int($key) ? $value : "{$key} {$value}"; })->implode(' '); } return $parameter; })->implode(' '); return "{$command} {$parameters}"; }
php
private function formatCommand($command, $parameters) { $parameters = collect($parameters)->map(function ($parameter) { if (is_array($parameter)) { return collect($parameter)->map(function ($value, $key) { return is_int($key) ? $value : "{$key} {$value}"; })->implode(' '); } return $parameter; })->implode(' '); return "{$command} {$parameters}"; }
[ "private", "function", "formatCommand", "(", "$", "command", ",", "$", "parameters", ")", "{", "$", "parameters", "=", "collect", "(", "$", "parameters", ")", "->", "map", "(", "function", "(", "$", "parameter", ")", "{", "if", "(", "is_array", "(", "$", "parameter", ")", ")", "{", "return", "collect", "(", "$", "parameter", ")", "->", "map", "(", "function", "(", "$", "value", ",", "$", "key", ")", "{", "return", "is_int", "(", "$", "key", ")", "?", "$", "value", ":", "\"{$key} {$value}\"", ";", "}", ")", "->", "implode", "(", "' '", ")", ";", "}", "return", "$", "parameter", ";", "}", ")", "->", "implode", "(", "' '", ")", ";", "return", "\"{$command} {$parameters}\"", ";", "}" ]
Format the given Redis command. @param string $command @param array $parameters @return string
[ "Format", "the", "given", "Redis", "command", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Watchers/RedisWatcher.php#L48-L61
train
laravel/telescope
src/ExtractTags.php
ExtractTags.from
public static function from($target) { if ($tags = static::explicitTags([$target])) { return $tags; } return static::modelsFor([$target])->map(function ($model) { return FormatModel::given($model); })->all(); }
php
public static function from($target) { if ($tags = static::explicitTags([$target])) { return $tags; } return static::modelsFor([$target])->map(function ($model) { return FormatModel::given($model); })->all(); }
[ "public", "static", "function", "from", "(", "$", "target", ")", "{", "if", "(", "$", "tags", "=", "static", "::", "explicitTags", "(", "[", "$", "target", "]", ")", ")", "{", "return", "$", "tags", ";", "}", "return", "static", "::", "modelsFor", "(", "[", "$", "target", "]", ")", "->", "map", "(", "function", "(", "$", "model", ")", "{", "return", "FormatModel", "::", "given", "(", "$", "model", ")", ";", "}", ")", "->", "all", "(", ")", ";", "}" ]
Get the tags for the given object. @param mixed $target @return array
[ "Get", "the", "tags", "for", "the", "given", "object", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/ExtractTags.php#L23-L32
train
laravel/telescope
src/ExtractTags.php
ExtractTags.fromArray
public static function fromArray(array $data) { $models = collect($data)->map(function ($value) { if ($value instanceof Model) { return [$value]; } elseif ($value instanceof EloquentCollection) { return $value->flatten(); } })->collapse()->filter(); return $models->map(function ($model) { return FormatModel::given($model); })->all(); }
php
public static function fromArray(array $data) { $models = collect($data)->map(function ($value) { if ($value instanceof Model) { return [$value]; } elseif ($value instanceof EloquentCollection) { return $value->flatten(); } })->collapse()->filter(); return $models->map(function ($model) { return FormatModel::given($model); })->all(); }
[ "public", "static", "function", "fromArray", "(", "array", "$", "data", ")", "{", "$", "models", "=", "collect", "(", "$", "data", ")", "->", "map", "(", "function", "(", "$", "value", ")", "{", "if", "(", "$", "value", "instanceof", "Model", ")", "{", "return", "[", "$", "value", "]", ";", "}", "elseif", "(", "$", "value", "instanceof", "EloquentCollection", ")", "{", "return", "$", "value", "->", "flatten", "(", ")", ";", "}", "}", ")", "->", "collapse", "(", ")", "->", "filter", "(", ")", ";", "return", "$", "models", "->", "map", "(", "function", "(", "$", "model", ")", "{", "return", "FormatModel", "::", "given", "(", "$", "model", ")", ";", "}", ")", "->", "all", "(", ")", ";", "}" ]
Determine the tags for the given array. @param array $data @return array
[ "Determine", "the", "tags", "for", "the", "given", "array", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/ExtractTags.php#L57-L70
train
laravel/telescope
src/ExtractTags.php
ExtractTags.tagsForListener
protected static function tagsForListener($job) { return collect( [static::extractListener($job), static::extractEvent($job), ])->map(function ($job) { return static::from($job); })->collapse()->unique()->toArray(); }
php
protected static function tagsForListener($job) { return collect( [static::extractListener($job), static::extractEvent($job), ])->map(function ($job) { return static::from($job); })->collapse()->unique()->toArray(); }
[ "protected", "static", "function", "tagsForListener", "(", "$", "job", ")", "{", "return", "collect", "(", "[", "static", "::", "extractListener", "(", "$", "job", ")", ",", "static", "::", "extractEvent", "(", "$", "job", ")", ",", "]", ")", "->", "map", "(", "function", "(", "$", "job", ")", "{", "return", "static", "::", "from", "(", "$", "job", ")", ";", "}", ")", "->", "collapse", "(", ")", "->", "unique", "(", ")", "->", "toArray", "(", ")", ";", "}" ]
Determine tags for the given queued listener. @param mixed $job @return array
[ "Determine", "tags", "for", "the", "given", "queued", "listener", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/ExtractTags.php#L91-L98
train
laravel/telescope
src/ExtractTags.php
ExtractTags.targetsFor
protected static function targetsFor($job) { switch (true) { case $job instanceof BroadcastEvent: return [$job->event]; case $job instanceof CallQueuedListener: return [static::extractEvent($job)]; case $job instanceof SendQueuedMailable: return [$job->mailable]; case $job instanceof SendQueuedNotifications: return [$job->notification]; default: return [$job]; } }
php
protected static function targetsFor($job) { switch (true) { case $job instanceof BroadcastEvent: return [$job->event]; case $job instanceof CallQueuedListener: return [static::extractEvent($job)]; case $job instanceof SendQueuedMailable: return [$job->mailable]; case $job instanceof SendQueuedNotifications: return [$job->notification]; default: return [$job]; } }
[ "protected", "static", "function", "targetsFor", "(", "$", "job", ")", "{", "switch", "(", "true", ")", "{", "case", "$", "job", "instanceof", "BroadcastEvent", ":", "return", "[", "$", "job", "->", "event", "]", ";", "case", "$", "job", "instanceof", "CallQueuedListener", ":", "return", "[", "static", "::", "extractEvent", "(", "$", "job", ")", "]", ";", "case", "$", "job", "instanceof", "SendQueuedMailable", ":", "return", "[", "$", "job", "->", "mailable", "]", ";", "case", "$", "job", "instanceof", "SendQueuedNotifications", ":", "return", "[", "$", "job", "->", "notification", "]", ";", "default", ":", "return", "[", "$", "job", "]", ";", "}", "}" ]
Get the actual target for the given job. @param mixed $job @return array
[ "Get", "the", "actual", "target", "for", "the", "given", "job", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/ExtractTags.php#L119-L133
train
laravel/telescope
src/ExtractTags.php
ExtractTags.modelsFor
protected static function modelsFor(array $targets) { $models = []; foreach ($targets as $target) { $models[] = collect((new ReflectionClass($target))->getProperties())->map(function ($property) use ($target) { $property->setAccessible(true); $value = $property->getValue($target); if ($value instanceof Model) { return [$value]; } elseif ($value instanceof EloquentCollection) { return $value->flatten(); } })->collapse()->filter()->all(); } return collect(Arr::collapse($models))->unique(); }
php
protected static function modelsFor(array $targets) { $models = []; foreach ($targets as $target) { $models[] = collect((new ReflectionClass($target))->getProperties())->map(function ($property) use ($target) { $property->setAccessible(true); $value = $property->getValue($target); if ($value instanceof Model) { return [$value]; } elseif ($value instanceof EloquentCollection) { return $value->flatten(); } })->collapse()->filter()->all(); } return collect(Arr::collapse($models))->unique(); }
[ "protected", "static", "function", "modelsFor", "(", "array", "$", "targets", ")", "{", "$", "models", "=", "[", "]", ";", "foreach", "(", "$", "targets", "as", "$", "target", ")", "{", "$", "models", "[", "]", "=", "collect", "(", "(", "new", "ReflectionClass", "(", "$", "target", ")", ")", "->", "getProperties", "(", ")", ")", "->", "map", "(", "function", "(", "$", "property", ")", "use", "(", "$", "target", ")", "{", "$", "property", "->", "setAccessible", "(", "true", ")", ";", "$", "value", "=", "$", "property", "->", "getValue", "(", "$", "target", ")", ";", "if", "(", "$", "value", "instanceof", "Model", ")", "{", "return", "[", "$", "value", "]", ";", "}", "elseif", "(", "$", "value", "instanceof", "EloquentCollection", ")", "{", "return", "$", "value", "->", "flatten", "(", ")", ";", "}", "}", ")", "->", "collapse", "(", ")", "->", "filter", "(", ")", "->", "all", "(", ")", ";", "}", "return", "collect", "(", "Arr", "::", "collapse", "(", "$", "models", ")", ")", "->", "unique", "(", ")", ";", "}" ]
Get the models from the given object. @param array $targets @return \Illuminate\Support\Collection
[ "Get", "the", "models", "from", "the", "given", "object", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/ExtractTags.php#L141-L160
train
laravel/telescope
src/ExtractTags.php
ExtractTags.extractEvent
protected static function extractEvent($job) { return isset($job->data[0]) && is_object($job->data[0]) ? $job->data[0] : new stdClass; }
php
protected static function extractEvent($job) { return isset($job->data[0]) && is_object($job->data[0]) ? $job->data[0] : new stdClass; }
[ "protected", "static", "function", "extractEvent", "(", "$", "job", ")", "{", "return", "isset", "(", "$", "job", "->", "data", "[", "0", "]", ")", "&&", "is_object", "(", "$", "job", "->", "data", "[", "0", "]", ")", "?", "$", "job", "->", "data", "[", "0", "]", ":", "new", "stdClass", ";", "}" ]
Extract the event from a queued job. @param mixed $job @return mixed
[ "Extract", "the", "event", "from", "a", "queued", "job", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/ExtractTags.php#L181-L186
train
laravel/telescope
src/ExtractProperties.php
ExtractProperties.from
public static function from($target) { return collect((new ReflectionClass($target))->getProperties()) ->mapWithKeys(function ($property) use ($target) { $property->setAccessible(true); if (($value = $property->getValue($target)) instanceof Model) { return [$property->getName() => FormatModel::given($value)]; } elseif (is_object($value)) { return [ $property->getName() => [ 'class' => get_class($value), 'properties' => json_decode(json_encode($value), true), ], ]; } else { return [$property->getName() => json_decode(json_encode($value), true)]; } })->toArray(); }
php
public static function from($target) { return collect((new ReflectionClass($target))->getProperties()) ->mapWithKeys(function ($property) use ($target) { $property->setAccessible(true); if (($value = $property->getValue($target)) instanceof Model) { return [$property->getName() => FormatModel::given($value)]; } elseif (is_object($value)) { return [ $property->getName() => [ 'class' => get_class($value), 'properties' => json_decode(json_encode($value), true), ], ]; } else { return [$property->getName() => json_decode(json_encode($value), true)]; } })->toArray(); }
[ "public", "static", "function", "from", "(", "$", "target", ")", "{", "return", "collect", "(", "(", "new", "ReflectionClass", "(", "$", "target", ")", ")", "->", "getProperties", "(", ")", ")", "->", "mapWithKeys", "(", "function", "(", "$", "property", ")", "use", "(", "$", "target", ")", "{", "$", "property", "->", "setAccessible", "(", "true", ")", ";", "if", "(", "(", "$", "value", "=", "$", "property", "->", "getValue", "(", "$", "target", ")", ")", "instanceof", "Model", ")", "{", "return", "[", "$", "property", "->", "getName", "(", ")", "=>", "FormatModel", "::", "given", "(", "$", "value", ")", "]", ";", "}", "elseif", "(", "is_object", "(", "$", "value", ")", ")", "{", "return", "[", "$", "property", "->", "getName", "(", ")", "=>", "[", "'class'", "=>", "get_class", "(", "$", "value", ")", ",", "'properties'", "=>", "json_decode", "(", "json_encode", "(", "$", "value", ")", ",", "true", ")", ",", "]", ",", "]", ";", "}", "else", "{", "return", "[", "$", "property", "->", "getName", "(", ")", "=>", "json_decode", "(", "json_encode", "(", "$", "value", ")", ",", "true", ")", "]", ";", "}", "}", ")", "->", "toArray", "(", ")", ";", "}" ]
Extract the properties for the given object in array form. The given array is ready for storage. @param mixed $target @return array
[ "Extract", "the", "properties", "for", "the", "given", "object", "in", "array", "form", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/ExtractProperties.php#L18-L37
train
laravel/telescope
src/Storage/EntryModel.php
EntryModel.scopeWithTelescopeOptions
public function scopeWithTelescopeOptions($query, $type, EntryQueryOptions $options) { $this->whereType($query, $type) ->whereBatchId($query, $options) ->whereTag($query, $options) ->whereFamilyHash($query, $options) ->whereBeforeSequence($query, $options) ->filter($query, $options); return $query; }
php
public function scopeWithTelescopeOptions($query, $type, EntryQueryOptions $options) { $this->whereType($query, $type) ->whereBatchId($query, $options) ->whereTag($query, $options) ->whereFamilyHash($query, $options) ->whereBeforeSequence($query, $options) ->filter($query, $options); return $query; }
[ "public", "function", "scopeWithTelescopeOptions", "(", "$", "query", ",", "$", "type", ",", "EntryQueryOptions", "$", "options", ")", "{", "$", "this", "->", "whereType", "(", "$", "query", ",", "$", "type", ")", "->", "whereBatchId", "(", "$", "query", ",", "$", "options", ")", "->", "whereTag", "(", "$", "query", ",", "$", "options", ")", "->", "whereFamilyHash", "(", "$", "query", ",", "$", "options", ")", "->", "whereBeforeSequence", "(", "$", "query", ",", "$", "options", ")", "->", "filter", "(", "$", "query", ",", "$", "options", ")", ";", "return", "$", "query", ";", "}" ]
Scope the query for the given query options. @param \Illuminate\Database\Eloquent\Builder $query @param string $type @param \Laravel\Telescope\Storage\EntryQueryOptions $options @return \Illuminate\Database\Eloquent\Builder
[ "Scope", "the", "query", "for", "the", "given", "query", "options", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Storage/EntryModel.php#L61-L71
train
laravel/telescope
src/Storage/EntryModel.php
EntryModel.whereBatchId
protected function whereBatchId($query, EntryQueryOptions $options) { $query->when($options->batchId, function ($query, $batchId) { return $query->where('batch_id', $batchId); }); return $this; }
php
protected function whereBatchId($query, EntryQueryOptions $options) { $query->when($options->batchId, function ($query, $batchId) { return $query->where('batch_id', $batchId); }); return $this; }
[ "protected", "function", "whereBatchId", "(", "$", "query", ",", "EntryQueryOptions", "$", "options", ")", "{", "$", "query", "->", "when", "(", "$", "options", "->", "batchId", ",", "function", "(", "$", "query", ",", "$", "batchId", ")", "{", "return", "$", "query", "->", "where", "(", "'batch_id'", ",", "$", "batchId", ")", ";", "}", ")", ";", "return", "$", "this", ";", "}" ]
Scope the query for the given batch ID. @param \Illuminate\Database\Eloquent\Builder $query @param \Laravel\Telescope\Storage\EntryQueryOptions $options @return $this
[ "Scope", "the", "query", "for", "the", "given", "batch", "ID", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Storage/EntryModel.php#L96-L103
train
laravel/telescope
src/Storage/EntryModel.php
EntryModel.whereBeforeSequence
protected function whereBeforeSequence($query, EntryQueryOptions $options) { $query->when($options->beforeSequence, function ($query, $beforeSequence) { return $query->where('sequence', '<', $beforeSequence); }); return $this; }
php
protected function whereBeforeSequence($query, EntryQueryOptions $options) { $query->when($options->beforeSequence, function ($query, $beforeSequence) { return $query->where('sequence', '<', $beforeSequence); }); return $this; }
[ "protected", "function", "whereBeforeSequence", "(", "$", "query", ",", "EntryQueryOptions", "$", "options", ")", "{", "$", "query", "->", "when", "(", "$", "options", "->", "beforeSequence", ",", "function", "(", "$", "query", ",", "$", "beforeSequence", ")", "{", "return", "$", "query", "->", "where", "(", "'sequence'", ",", "'<'", ",", "$", "beforeSequence", ")", ";", "}", ")", ";", "return", "$", "this", ";", "}" ]
Scope the query for the given pagination options. @param \Illuminate\Database\Eloquent\Builder $query @param \Laravel\Telescope\Storage\EntryQueryOptions $options @return $this
[ "Scope", "the", "query", "for", "the", "given", "pagination", "options", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Storage/EntryModel.php#L146-L153
train
laravel/telescope
src/Storage/EntryModel.php
EntryModel.filter
protected function filter($query, EntryQueryOptions $options) { if ($options->familyHash || $options->tag || $options->batchId) { return $this; } $query->where('should_display_on_index', true); return $this; }
php
protected function filter($query, EntryQueryOptions $options) { if ($options->familyHash || $options->tag || $options->batchId) { return $this; } $query->where('should_display_on_index', true); return $this; }
[ "protected", "function", "filter", "(", "$", "query", ",", "EntryQueryOptions", "$", "options", ")", "{", "if", "(", "$", "options", "->", "familyHash", "||", "$", "options", "->", "tag", "||", "$", "options", "->", "batchId", ")", "{", "return", "$", "this", ";", "}", "$", "query", "->", "where", "(", "'should_display_on_index'", ",", "true", ")", ";", "return", "$", "this", ";", "}" ]
Scope the query for the given display options. @param \Illuminate\Database\Eloquent\Builder $query @param \Laravel\Telescope\Storage\EntryQueryOptions $options @return $this
[ "Scope", "the", "query", "for", "the", "given", "display", "options", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Storage/EntryModel.php#L162-L171
train
laravel/telescope
src/Console/InstallCommand.php
InstallCommand.registerTelescopeServiceProvider
protected function registerTelescopeServiceProvider() { $namespace = str_replace_last('\\', '', $this->getAppNamespace()); $appConfig = file_get_contents(config_path('app.php')); if (Str::contains($appConfig, $namespace.'\\Providers\\TelescopeServiceProvider::class')) { return; } $lineEndingCount = [ "\r\n" => substr_count($appConfig, "\r\n"), "\r" => substr_count($appConfig, "\r"), "\n" => substr_count($appConfig, "\n"), ]; $eol = array_keys($lineEndingCount, max($lineEndingCount))[0]; file_put_contents(config_path('app.php'), str_replace( "{$namespace}\\Providers\EventServiceProvider::class,".$eol, "{$namespace}\\Providers\EventServiceProvider::class,".$eol." {$namespace}\Providers\TelescopeServiceProvider::class,".$eol, $appConfig )); file_put_contents(app_path('Providers/TelescopeServiceProvider.php'), str_replace( "namespace App\Providers;", "namespace {$namespace}\Providers;", file_get_contents(app_path('Providers/TelescopeServiceProvider.php')) )); }
php
protected function registerTelescopeServiceProvider() { $namespace = str_replace_last('\\', '', $this->getAppNamespace()); $appConfig = file_get_contents(config_path('app.php')); if (Str::contains($appConfig, $namespace.'\\Providers\\TelescopeServiceProvider::class')) { return; } $lineEndingCount = [ "\r\n" => substr_count($appConfig, "\r\n"), "\r" => substr_count($appConfig, "\r"), "\n" => substr_count($appConfig, "\n"), ]; $eol = array_keys($lineEndingCount, max($lineEndingCount))[0]; file_put_contents(config_path('app.php'), str_replace( "{$namespace}\\Providers\EventServiceProvider::class,".$eol, "{$namespace}\\Providers\EventServiceProvider::class,".$eol." {$namespace}\Providers\TelescopeServiceProvider::class,".$eol, $appConfig )); file_put_contents(app_path('Providers/TelescopeServiceProvider.php'), str_replace( "namespace App\Providers;", "namespace {$namespace}\Providers;", file_get_contents(app_path('Providers/TelescopeServiceProvider.php')) )); }
[ "protected", "function", "registerTelescopeServiceProvider", "(", ")", "{", "$", "namespace", "=", "str_replace_last", "(", "'\\\\'", ",", "''", ",", "$", "this", "->", "getAppNamespace", "(", ")", ")", ";", "$", "appConfig", "=", "file_get_contents", "(", "config_path", "(", "'app.php'", ")", ")", ";", "if", "(", "Str", "::", "contains", "(", "$", "appConfig", ",", "$", "namespace", ".", "'\\\\Providers\\\\TelescopeServiceProvider::class'", ")", ")", "{", "return", ";", "}", "$", "lineEndingCount", "=", "[", "\"\\r\\n\"", "=>", "substr_count", "(", "$", "appConfig", ",", "\"\\r\\n\"", ")", ",", "\"\\r\"", "=>", "substr_count", "(", "$", "appConfig", ",", "\"\\r\"", ")", ",", "\"\\n\"", "=>", "substr_count", "(", "$", "appConfig", ",", "\"\\n\"", ")", ",", "]", ";", "$", "eol", "=", "array_keys", "(", "$", "lineEndingCount", ",", "max", "(", "$", "lineEndingCount", ")", ")", "[", "0", "]", ";", "file_put_contents", "(", "config_path", "(", "'app.php'", ")", ",", "str_replace", "(", "\"{$namespace}\\\\Providers\\EventServiceProvider::class,\"", ".", "$", "eol", ",", "\"{$namespace}\\\\Providers\\EventServiceProvider::class,\"", ".", "$", "eol", ".", "\" {$namespace}\\Providers\\TelescopeServiceProvider::class,\"", ".", "$", "eol", ",", "$", "appConfig", ")", ")", ";", "file_put_contents", "(", "app_path", "(", "'Providers/TelescopeServiceProvider.php'", ")", ",", "str_replace", "(", "\"namespace App\\Providers;\"", ",", "\"namespace {$namespace}\\Providers;\"", ",", "file_get_contents", "(", "app_path", "(", "'Providers/TelescopeServiceProvider.php'", ")", ")", ")", ")", ";", "}" ]
Register the Telescope service provider in the application configuration file. @return void
[ "Register", "the", "Telescope", "service", "provider", "in", "the", "application", "configuration", "file", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Console/InstallCommand.php#L53-L82
train
laravel/telescope
src/Storage/DatabaseEntriesRepository.php
DatabaseEntriesRepository.find
public function find($id): EntryResult { $entry = EntryModel::on($this->connection)->whereUuid($id)->firstOrFail(); $tags = $this->table('telescope_entries_tags') ->where('entry_uuid', $id) ->pluck('tag') ->all(); return new EntryResult( $entry->uuid, null, $entry->batch_id, $entry->type, $entry->family_hash, $entry->content, $entry->created_at, $tags ); }
php
public function find($id): EntryResult { $entry = EntryModel::on($this->connection)->whereUuid($id)->firstOrFail(); $tags = $this->table('telescope_entries_tags') ->where('entry_uuid', $id) ->pluck('tag') ->all(); return new EntryResult( $entry->uuid, null, $entry->batch_id, $entry->type, $entry->family_hash, $entry->content, $entry->created_at, $tags ); }
[ "public", "function", "find", "(", "$", "id", ")", ":", "EntryResult", "{", "$", "entry", "=", "EntryModel", "::", "on", "(", "$", "this", "->", "connection", ")", "->", "whereUuid", "(", "$", "id", ")", "->", "firstOrFail", "(", ")", ";", "$", "tags", "=", "$", "this", "->", "table", "(", "'telescope_entries_tags'", ")", "->", "where", "(", "'entry_uuid'", ",", "$", "id", ")", "->", "pluck", "(", "'tag'", ")", "->", "all", "(", ")", ";", "return", "new", "EntryResult", "(", "$", "entry", "->", "uuid", ",", "null", ",", "$", "entry", "->", "batch_id", ",", "$", "entry", "->", "type", ",", "$", "entry", "->", "family_hash", ",", "$", "entry", "->", "content", ",", "$", "entry", "->", "created_at", ",", "$", "tags", ")", ";", "}" ]
Find the entry with the given ID. @param mixed $id @return \Laravel\Telescope\EntryResult
[ "Find", "the", "entry", "with", "the", "given", "ID", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Storage/DatabaseEntriesRepository.php#L60-L79
train
laravel/telescope
src/Storage/DatabaseEntriesRepository.php
DatabaseEntriesRepository.get
public function get($type, EntryQueryOptions $options) { return EntryModel::on($this->connection) ->withTelescopeOptions($type, $options) ->take($options->limit) ->orderByDesc('sequence') ->get()->reject(function ($entry) { return ! is_array($entry->content); })->map(function ($entry) { return new EntryResult( $entry->uuid, $entry->sequence, $entry->batch_id, $entry->type, $entry->family_hash, $entry->content, $entry->created_at, [] ); })->values(); }
php
public function get($type, EntryQueryOptions $options) { return EntryModel::on($this->connection) ->withTelescopeOptions($type, $options) ->take($options->limit) ->orderByDesc('sequence') ->get()->reject(function ($entry) { return ! is_array($entry->content); })->map(function ($entry) { return new EntryResult( $entry->uuid, $entry->sequence, $entry->batch_id, $entry->type, $entry->family_hash, $entry->content, $entry->created_at, [] ); })->values(); }
[ "public", "function", "get", "(", "$", "type", ",", "EntryQueryOptions", "$", "options", ")", "{", "return", "EntryModel", "::", "on", "(", "$", "this", "->", "connection", ")", "->", "withTelescopeOptions", "(", "$", "type", ",", "$", "options", ")", "->", "take", "(", "$", "options", "->", "limit", ")", "->", "orderByDesc", "(", "'sequence'", ")", "->", "get", "(", ")", "->", "reject", "(", "function", "(", "$", "entry", ")", "{", "return", "!", "is_array", "(", "$", "entry", "->", "content", ")", ";", "}", ")", "->", "map", "(", "function", "(", "$", "entry", ")", "{", "return", "new", "EntryResult", "(", "$", "entry", "->", "uuid", ",", "$", "entry", "->", "sequence", ",", "$", "entry", "->", "batch_id", ",", "$", "entry", "->", "type", ",", "$", "entry", "->", "family_hash", ",", "$", "entry", "->", "content", ",", "$", "entry", "->", "created_at", ",", "[", "]", ")", ";", "}", ")", "->", "values", "(", ")", ";", "}" ]
Return all the entries of a given type. @param string|null $type @param \Laravel\Telescope\Storage\EntryQueryOptions $options @return \Illuminate\Support\Collection|\Laravel\Telescope\EntryResult[]
[ "Return", "all", "the", "entries", "of", "a", "given", "type", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Storage/DatabaseEntriesRepository.php#L88-L108
train
laravel/telescope
src/Storage/DatabaseEntriesRepository.php
DatabaseEntriesRepository.store
public function store(Collection $entries) { if ($entries->isEmpty()) { return; } [$exceptions, $entries] = $entries->partition->isException(); $this->storeExceptions($exceptions); $table = $this->table('telescope_entries'); $entries->chunk($this->chunkSize)->each(function ($chunked) use ($table) { $table->insert($chunked->map(function ($entry) { $entry->content = json_encode($entry->content); return $entry->toArray(); })->toArray()); }); $this->storeTags($entries->pluck('tags', 'uuid')); }
php
public function store(Collection $entries) { if ($entries->isEmpty()) { return; } [$exceptions, $entries] = $entries->partition->isException(); $this->storeExceptions($exceptions); $table = $this->table('telescope_entries'); $entries->chunk($this->chunkSize)->each(function ($chunked) use ($table) { $table->insert($chunked->map(function ($entry) { $entry->content = json_encode($entry->content); return $entry->toArray(); })->toArray()); }); $this->storeTags($entries->pluck('tags', 'uuid')); }
[ "public", "function", "store", "(", "Collection", "$", "entries", ")", "{", "if", "(", "$", "entries", "->", "isEmpty", "(", ")", ")", "{", "return", ";", "}", "[", "$", "exceptions", ",", "$", "entries", "]", "=", "$", "entries", "->", "partition", "->", "isException", "(", ")", ";", "$", "this", "->", "storeExceptions", "(", "$", "exceptions", ")", ";", "$", "table", "=", "$", "this", "->", "table", "(", "'telescope_entries'", ")", ";", "$", "entries", "->", "chunk", "(", "$", "this", "->", "chunkSize", ")", "->", "each", "(", "function", "(", "$", "chunked", ")", "use", "(", "$", "table", ")", "{", "$", "table", "->", "insert", "(", "$", "chunked", "->", "map", "(", "function", "(", "$", "entry", ")", "{", "$", "entry", "->", "content", "=", "json_encode", "(", "$", "entry", "->", "content", ")", ";", "return", "$", "entry", "->", "toArray", "(", ")", ";", "}", ")", "->", "toArray", "(", ")", ")", ";", "}", ")", ";", "$", "this", "->", "storeTags", "(", "$", "entries", "->", "pluck", "(", "'tags'", ",", "'uuid'", ")", ")", ";", "}" ]
Store the given array of entries. @param \Illuminate\Support\Collection|\Laravel\Telescope\IncomingEntry[] $entries @return void
[ "Store", "the", "given", "array", "of", "entries", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Storage/DatabaseEntriesRepository.php#L116-L137
train
laravel/telescope
src/Storage/DatabaseEntriesRepository.php
DatabaseEntriesRepository.storeExceptions
protected function storeExceptions(Collection $exceptions) { $this->table('telescope_entries')->insert($exceptions->map(function ($exception) { $occurrences = $this->table('telescope_entries') ->where('type', EntryType::EXCEPTION) ->where('family_hash', $exception->familyHash()) ->count(); $this->table('telescope_entries') ->where('type', EntryType::EXCEPTION) ->where('family_hash', $exception->familyHash()) ->update(['should_display_on_index' => false]); return array_merge($exception->toArray(), [ 'family_hash' => $exception->familyHash(), 'content' => json_encode(array_merge( $exception->content, ['occurrences' => $occurrences + 1] )), ]); })->toArray()); $this->storeTags($exceptions->pluck('tags', 'uuid')); }
php
protected function storeExceptions(Collection $exceptions) { $this->table('telescope_entries')->insert($exceptions->map(function ($exception) { $occurrences = $this->table('telescope_entries') ->where('type', EntryType::EXCEPTION) ->where('family_hash', $exception->familyHash()) ->count(); $this->table('telescope_entries') ->where('type', EntryType::EXCEPTION) ->where('family_hash', $exception->familyHash()) ->update(['should_display_on_index' => false]); return array_merge($exception->toArray(), [ 'family_hash' => $exception->familyHash(), 'content' => json_encode(array_merge( $exception->content, ['occurrences' => $occurrences + 1] )), ]); })->toArray()); $this->storeTags($exceptions->pluck('tags', 'uuid')); }
[ "protected", "function", "storeExceptions", "(", "Collection", "$", "exceptions", ")", "{", "$", "this", "->", "table", "(", "'telescope_entries'", ")", "->", "insert", "(", "$", "exceptions", "->", "map", "(", "function", "(", "$", "exception", ")", "{", "$", "occurrences", "=", "$", "this", "->", "table", "(", "'telescope_entries'", ")", "->", "where", "(", "'type'", ",", "EntryType", "::", "EXCEPTION", ")", "->", "where", "(", "'family_hash'", ",", "$", "exception", "->", "familyHash", "(", ")", ")", "->", "count", "(", ")", ";", "$", "this", "->", "table", "(", "'telescope_entries'", ")", "->", "where", "(", "'type'", ",", "EntryType", "::", "EXCEPTION", ")", "->", "where", "(", "'family_hash'", ",", "$", "exception", "->", "familyHash", "(", ")", ")", "->", "update", "(", "[", "'should_display_on_index'", "=>", "false", "]", ")", ";", "return", "array_merge", "(", "$", "exception", "->", "toArray", "(", ")", ",", "[", "'family_hash'", "=>", "$", "exception", "->", "familyHash", "(", ")", ",", "'content'", "=>", "json_encode", "(", "array_merge", "(", "$", "exception", "->", "content", ",", "[", "'occurrences'", "=>", "$", "occurrences", "+", "1", "]", ")", ")", ",", "]", ")", ";", "}", ")", "->", "toArray", "(", ")", ")", ";", "$", "this", "->", "storeTags", "(", "$", "exceptions", "->", "pluck", "(", "'tags'", ",", "'uuid'", ")", ")", ";", "}" ]
Store the given array of exception entries. @param \Illuminate\Support\Collection|\Laravel\Telescope\IncomingEntry[] $exceptions @return void
[ "Store", "the", "given", "array", "of", "exception", "entries", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Storage/DatabaseEntriesRepository.php#L145-L167
train
laravel/telescope
src/Storage/DatabaseEntriesRepository.php
DatabaseEntriesRepository.storeTags
protected function storeTags($results) { $this->table('telescope_entries_tags')->insert($results->flatMap(function ($tags, $uuid) { return collect($tags)->map(function ($tag) use ($uuid) { return [ 'entry_uuid' => $uuid, 'tag' => $tag, ]; }); })->all()); }
php
protected function storeTags($results) { $this->table('telescope_entries_tags')->insert($results->flatMap(function ($tags, $uuid) { return collect($tags)->map(function ($tag) use ($uuid) { return [ 'entry_uuid' => $uuid, 'tag' => $tag, ]; }); })->all()); }
[ "protected", "function", "storeTags", "(", "$", "results", ")", "{", "$", "this", "->", "table", "(", "'telescope_entries_tags'", ")", "->", "insert", "(", "$", "results", "->", "flatMap", "(", "function", "(", "$", "tags", ",", "$", "uuid", ")", "{", "return", "collect", "(", "$", "tags", ")", "->", "map", "(", "function", "(", "$", "tag", ")", "use", "(", "$", "uuid", ")", "{", "return", "[", "'entry_uuid'", "=>", "$", "uuid", ",", "'tag'", "=>", "$", "tag", ",", "]", ";", "}", ")", ";", "}", ")", "->", "all", "(", ")", ")", ";", "}" ]
Store the tags for the given entries. @param \Illuminate\Support\Collection $results @return void
[ "Store", "the", "tags", "for", "the", "given", "entries", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Storage/DatabaseEntriesRepository.php#L175-L185
train
laravel/telescope
src/Storage/DatabaseEntriesRepository.php
DatabaseEntriesRepository.update
public function update(Collection $updates) { foreach ($updates as $update) { $entry = $this->table('telescope_entries') ->where('uuid', $update->uuid) ->where('type', $update->type) ->first(); if (! $entry) { continue; } $content = json_encode(array_merge( json_decode($entry->content, true) ?: [], $update->changes )); $this->table('telescope_entries') ->where('uuid', $update->uuid) ->where('type', $update->type) ->update(['content' => $content]); $this->updateTags($update); } }
php
public function update(Collection $updates) { foreach ($updates as $update) { $entry = $this->table('telescope_entries') ->where('uuid', $update->uuid) ->where('type', $update->type) ->first(); if (! $entry) { continue; } $content = json_encode(array_merge( json_decode($entry->content, true) ?: [], $update->changes )); $this->table('telescope_entries') ->where('uuid', $update->uuid) ->where('type', $update->type) ->update(['content' => $content]); $this->updateTags($update); } }
[ "public", "function", "update", "(", "Collection", "$", "updates", ")", "{", "foreach", "(", "$", "updates", "as", "$", "update", ")", "{", "$", "entry", "=", "$", "this", "->", "table", "(", "'telescope_entries'", ")", "->", "where", "(", "'uuid'", ",", "$", "update", "->", "uuid", ")", "->", "where", "(", "'type'", ",", "$", "update", "->", "type", ")", "->", "first", "(", ")", ";", "if", "(", "!", "$", "entry", ")", "{", "continue", ";", "}", "$", "content", "=", "json_encode", "(", "array_merge", "(", "json_decode", "(", "$", "entry", "->", "content", ",", "true", ")", "?", ":", "[", "]", ",", "$", "update", "->", "changes", ")", ")", ";", "$", "this", "->", "table", "(", "'telescope_entries'", ")", "->", "where", "(", "'uuid'", ",", "$", "update", "->", "uuid", ")", "->", "where", "(", "'type'", ",", "$", "update", "->", "type", ")", "->", "update", "(", "[", "'content'", "=>", "$", "content", "]", ")", ";", "$", "this", "->", "updateTags", "(", "$", "update", ")", ";", "}", "}" ]
Store the given entry updates. @param \Illuminate\Support\Collection|\Laravel\Telescope\EntryUpdate[] $updates @return void
[ "Store", "the", "given", "entry", "updates", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Storage/DatabaseEntriesRepository.php#L193-L216
train
laravel/telescope
src/Storage/DatabaseEntriesRepository.php
DatabaseEntriesRepository.updateTags
protected function updateTags($entry) { if (! empty($entry->tagsChanges['added'])) { $this->table('telescope_entries_tags')->insert( collect($entry->tagsChanges['added'])->map(function ($tag) use ($entry) { return [ 'entry_uuid' => $entry->uuid, 'tag' => $tag, ]; })->toArray() ); } collect($entry->tagsChanges['removed'])->each(function ($tag) use ($entry) { $this->table('telescope_entries_tags')->where([ 'entry_uuid' => $entry->uuid, 'tag' => $tag, ])->delete(); }); }
php
protected function updateTags($entry) { if (! empty($entry->tagsChanges['added'])) { $this->table('telescope_entries_tags')->insert( collect($entry->tagsChanges['added'])->map(function ($tag) use ($entry) { return [ 'entry_uuid' => $entry->uuid, 'tag' => $tag, ]; })->toArray() ); } collect($entry->tagsChanges['removed'])->each(function ($tag) use ($entry) { $this->table('telescope_entries_tags')->where([ 'entry_uuid' => $entry->uuid, 'tag' => $tag, ])->delete(); }); }
[ "protected", "function", "updateTags", "(", "$", "entry", ")", "{", "if", "(", "!", "empty", "(", "$", "entry", "->", "tagsChanges", "[", "'added'", "]", ")", ")", "{", "$", "this", "->", "table", "(", "'telescope_entries_tags'", ")", "->", "insert", "(", "collect", "(", "$", "entry", "->", "tagsChanges", "[", "'added'", "]", ")", "->", "map", "(", "function", "(", "$", "tag", ")", "use", "(", "$", "entry", ")", "{", "return", "[", "'entry_uuid'", "=>", "$", "entry", "->", "uuid", ",", "'tag'", "=>", "$", "tag", ",", "]", ";", "}", ")", "->", "toArray", "(", ")", ")", ";", "}", "collect", "(", "$", "entry", "->", "tagsChanges", "[", "'removed'", "]", ")", "->", "each", "(", "function", "(", "$", "tag", ")", "use", "(", "$", "entry", ")", "{", "$", "this", "->", "table", "(", "'telescope_entries_tags'", ")", "->", "where", "(", "[", "'entry_uuid'", "=>", "$", "entry", "->", "uuid", ",", "'tag'", "=>", "$", "tag", ",", "]", ")", "->", "delete", "(", ")", ";", "}", ")", ";", "}" ]
Update tags of the given entry. @param \Laravel\Telescope\EntryUpdate $entry @return void
[ "Update", "tags", "of", "the", "given", "entry", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Storage/DatabaseEntriesRepository.php#L224-L243
train
laravel/telescope
src/Storage/DatabaseEntriesRepository.php
DatabaseEntriesRepository.isMonitoring
public function isMonitoring(array $tags) { if (is_null($this->monitoredTags)) { $this->loadMonitoredTags(); } return count(array_intersect($tags, $this->monitoredTags)) > 0; }
php
public function isMonitoring(array $tags) { if (is_null($this->monitoredTags)) { $this->loadMonitoredTags(); } return count(array_intersect($tags, $this->monitoredTags)) > 0; }
[ "public", "function", "isMonitoring", "(", "array", "$", "tags", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "monitoredTags", ")", ")", "{", "$", "this", "->", "loadMonitoredTags", "(", ")", ";", "}", "return", "count", "(", "array_intersect", "(", "$", "tags", ",", "$", "this", "->", "monitoredTags", ")", ")", ">", "0", ";", "}" ]
Determine if any of the given tags are currently being monitored. @param array $tags @return bool
[ "Determine", "if", "any", "of", "the", "given", "tags", "are", "currently", "being", "monitored", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Storage/DatabaseEntriesRepository.php#L265-L272
train
laravel/telescope
src/Storage/DatabaseEntriesRepository.php
DatabaseEntriesRepository.monitor
public function monitor(array $tags) { $tags = array_diff($tags, $this->monitoring()); if (empty($tags)) { return; } $this->table('telescope_monitoring') ->insert(collect($tags) ->mapWithKeys(function ($tag) { return ['tag' => $tag]; })->all()); }
php
public function monitor(array $tags) { $tags = array_diff($tags, $this->monitoring()); if (empty($tags)) { return; } $this->table('telescope_monitoring') ->insert(collect($tags) ->mapWithKeys(function ($tag) { return ['tag' => $tag]; })->all()); }
[ "public", "function", "monitor", "(", "array", "$", "tags", ")", "{", "$", "tags", "=", "array_diff", "(", "$", "tags", ",", "$", "this", "->", "monitoring", "(", ")", ")", ";", "if", "(", "empty", "(", "$", "tags", ")", ")", "{", "return", ";", "}", "$", "this", "->", "table", "(", "'telescope_monitoring'", ")", "->", "insert", "(", "collect", "(", "$", "tags", ")", "->", "mapWithKeys", "(", "function", "(", "$", "tag", ")", "{", "return", "[", "'tag'", "=>", "$", "tag", "]", ";", "}", ")", "->", "all", "(", ")", ")", ";", "}" ]
Begin monitoring the given list of tags. @param array $tags @return void
[ "Begin", "monitoring", "the", "given", "list", "of", "tags", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Storage/DatabaseEntriesRepository.php#L290-L303
train
laravel/telescope
src/RegistersWatchers.php
RegistersWatchers.registerWatchers
protected static function registerWatchers($app) { foreach (config('telescope.watchers') as $key => $watcher) { if (is_string($key) && $watcher === false) { continue; } if (is_array($watcher) && ! ($watcher['enabled'] ?? true)) { continue; } $watcher = $app->make(is_string($key) ? $key : $watcher, [ 'options' => is_array($watcher) ? $watcher : [], ]); static::$watchers[] = get_class($watcher); $watcher->register($app); } }
php
protected static function registerWatchers($app) { foreach (config('telescope.watchers') as $key => $watcher) { if (is_string($key) && $watcher === false) { continue; } if (is_array($watcher) && ! ($watcher['enabled'] ?? true)) { continue; } $watcher = $app->make(is_string($key) ? $key : $watcher, [ 'options' => is_array($watcher) ? $watcher : [], ]); static::$watchers[] = get_class($watcher); $watcher->register($app); } }
[ "protected", "static", "function", "registerWatchers", "(", "$", "app", ")", "{", "foreach", "(", "config", "(", "'telescope.watchers'", ")", "as", "$", "key", "=>", "$", "watcher", ")", "{", "if", "(", "is_string", "(", "$", "key", ")", "&&", "$", "watcher", "===", "false", ")", "{", "continue", ";", "}", "if", "(", "is_array", "(", "$", "watcher", ")", "&&", "!", "(", "$", "watcher", "[", "'enabled'", "]", "??", "true", ")", ")", "{", "continue", ";", "}", "$", "watcher", "=", "$", "app", "->", "make", "(", "is_string", "(", "$", "key", ")", "?", "$", "key", ":", "$", "watcher", ",", "[", "'options'", "=>", "is_array", "(", "$", "watcher", ")", "?", "$", "watcher", ":", "[", "]", ",", "]", ")", ";", "static", "::", "$", "watchers", "[", "]", "=", "get_class", "(", "$", "watcher", ")", ";", "$", "watcher", "->", "register", "(", "$", "app", ")", ";", "}", "}" ]
Register the configured Telescope watchers. @param \Illuminate\Foundation\Application $app @return void
[ "Register", "the", "configured", "Telescope", "watchers", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/RegistersWatchers.php#L31-L50
train
laravel/telescope
src/IncomingExceptionEntry.php
IncomingExceptionEntry.isReportableException
public function isReportableException() { $handler = app(ExceptionHandler::class); return method_exists($handler, 'shouldReport') ? $handler->shouldReport($this->exception) : true; }
php
public function isReportableException() { $handler = app(ExceptionHandler::class); return method_exists($handler, 'shouldReport') ? $handler->shouldReport($this->exception) : true; }
[ "public", "function", "isReportableException", "(", ")", "{", "$", "handler", "=", "app", "(", "ExceptionHandler", "::", "class", ")", ";", "return", "method_exists", "(", "$", "handler", ",", "'shouldReport'", ")", "?", "$", "handler", "->", "shouldReport", "(", "$", "this", "->", "exception", ")", ":", "true", ";", "}" ]
Determine if the incoming entry is a reportable exception. @return bool
[ "Determine", "if", "the", "incoming", "entry", "is", "a", "reportable", "exception", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/IncomingExceptionEntry.php#L35-L41
train
laravel/telescope
src/Watchers/GateWatcher.php
GateWatcher.recordGateCheck
public function recordGateCheck(?Authenticatable $user, $ability, $result, $arguments) { if (! Telescope::isRecording() || $this->shouldIgnore($ability)) { return; } $caller = $this->getCallerFromStackTrace(); Telescope::recordGate(IncomingEntry::make([ 'ability' => $ability, 'result' => $result ? 'allowed' : 'denied', 'arguments' => $this->formatArguments($arguments), 'file' => $caller['file'], 'line' => $caller['line'], ])); return $result; }
php
public function recordGateCheck(?Authenticatable $user, $ability, $result, $arguments) { if (! Telescope::isRecording() || $this->shouldIgnore($ability)) { return; } $caller = $this->getCallerFromStackTrace(); Telescope::recordGate(IncomingEntry::make([ 'ability' => $ability, 'result' => $result ? 'allowed' : 'denied', 'arguments' => $this->formatArguments($arguments), 'file' => $caller['file'], 'line' => $caller['line'], ])); return $result; }
[ "public", "function", "recordGateCheck", "(", "?", "Authenticatable", "$", "user", ",", "$", "ability", ",", "$", "result", ",", "$", "arguments", ")", "{", "if", "(", "!", "Telescope", "::", "isRecording", "(", ")", "||", "$", "this", "->", "shouldIgnore", "(", "$", "ability", ")", ")", "{", "return", ";", "}", "$", "caller", "=", "$", "this", "->", "getCallerFromStackTrace", "(", ")", ";", "Telescope", "::", "recordGate", "(", "IncomingEntry", "::", "make", "(", "[", "'ability'", "=>", "$", "ability", ",", "'result'", "=>", "$", "result", "?", "'allowed'", ":", "'denied'", ",", "'arguments'", "=>", "$", "this", "->", "formatArguments", "(", "$", "arguments", ")", ",", "'file'", "=>", "$", "caller", "[", "'file'", "]", ",", "'line'", "=>", "$", "caller", "[", "'line'", "]", ",", "]", ")", ")", ";", "return", "$", "result", ";", "}" ]
Record a gate check. @param \Illuminate\Contracts\Auth\Authenticatable|null $user @param string $ability @param bool $result @param array $arguments @return bool
[ "Record", "a", "gate", "check", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Watchers/GateWatcher.php#L37-L54
train
laravel/telescope
src/Watchers/GateWatcher.php
GateWatcher.formatArguments
private function formatArguments($arguments) { return collect($arguments)->map(function ($argument) { return $argument instanceof Model ? FormatModel::given($argument) : $argument; })->toArray(); }
php
private function formatArguments($arguments) { return collect($arguments)->map(function ($argument) { return $argument instanceof Model ? FormatModel::given($argument) : $argument; })->toArray(); }
[ "private", "function", "formatArguments", "(", "$", "arguments", ")", "{", "return", "collect", "(", "$", "arguments", ")", "->", "map", "(", "function", "(", "$", "argument", ")", "{", "return", "$", "argument", "instanceof", "Model", "?", "FormatModel", "::", "given", "(", "$", "argument", ")", ":", "$", "argument", ";", "}", ")", "->", "toArray", "(", ")", ";", "}" ]
Format the given arguments. @param array $arguments @return array
[ "Format", "the", "given", "arguments", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Watchers/GateWatcher.php#L73-L78
train
laravel/telescope
src/Watchers/MailWatcher.php
MailWatcher.recordMail
public function recordMail(MessageSent $event) { if (! Telescope::isRecording()) { return; } Telescope::recordMail(IncomingEntry::make([ 'mailable' => $this->getMailable($event), 'queued' => $this->getQueuedStatus($event), 'from' => $event->message->getFrom(), 'replyTo' => $event->message->getReplyTo(), 'to' => $event->message->getTo(), 'cc' => $event->message->getCc(), 'bcc' => $event->message->getBcc(), 'subject' => $event->message->getSubject(), 'html' => $event->message->getBody(), 'raw' => $event->message->toString(), ])->tags($this->tags($event->message, $event->data))); }
php
public function recordMail(MessageSent $event) { if (! Telescope::isRecording()) { return; } Telescope::recordMail(IncomingEntry::make([ 'mailable' => $this->getMailable($event), 'queued' => $this->getQueuedStatus($event), 'from' => $event->message->getFrom(), 'replyTo' => $event->message->getReplyTo(), 'to' => $event->message->getTo(), 'cc' => $event->message->getCc(), 'bcc' => $event->message->getBcc(), 'subject' => $event->message->getSubject(), 'html' => $event->message->getBody(), 'raw' => $event->message->toString(), ])->tags($this->tags($event->message, $event->data))); }
[ "public", "function", "recordMail", "(", "MessageSent", "$", "event", ")", "{", "if", "(", "!", "Telescope", "::", "isRecording", "(", ")", ")", "{", "return", ";", "}", "Telescope", "::", "recordMail", "(", "IncomingEntry", "::", "make", "(", "[", "'mailable'", "=>", "$", "this", "->", "getMailable", "(", "$", "event", ")", ",", "'queued'", "=>", "$", "this", "->", "getQueuedStatus", "(", "$", "event", ")", ",", "'from'", "=>", "$", "event", "->", "message", "->", "getFrom", "(", ")", ",", "'replyTo'", "=>", "$", "event", "->", "message", "->", "getReplyTo", "(", ")", ",", "'to'", "=>", "$", "event", "->", "message", "->", "getTo", "(", ")", ",", "'cc'", "=>", "$", "event", "->", "message", "->", "getCc", "(", ")", ",", "'bcc'", "=>", "$", "event", "->", "message", "->", "getBcc", "(", ")", ",", "'subject'", "=>", "$", "event", "->", "message", "->", "getSubject", "(", ")", ",", "'html'", "=>", "$", "event", "->", "message", "->", "getBody", "(", ")", ",", "'raw'", "=>", "$", "event", "->", "message", "->", "toString", "(", ")", ",", "]", ")", "->", "tags", "(", "$", "this", "->", "tags", "(", "$", "event", "->", "message", ",", "$", "event", "->", "data", ")", ")", ")", ";", "}" ]
Record a mail message was sent. @param \Illuminate\Mail\Events\MessageSent $event @return void
[ "Record", "a", "mail", "message", "was", "sent", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Watchers/MailWatcher.php#L28-L46
train
laravel/telescope
src/Watchers/MailWatcher.php
MailWatcher.getQueuedStatus
protected function getQueuedStatus($event) { if (isset($event->data['__laravel_notification_queued'])) { return $event->data['__laravel_notification_queued']; } return $event->data['__telescope_queued'] ?? false; }
php
protected function getQueuedStatus($event) { if (isset($event->data['__laravel_notification_queued'])) { return $event->data['__laravel_notification_queued']; } return $event->data['__telescope_queued'] ?? false; }
[ "protected", "function", "getQueuedStatus", "(", "$", "event", ")", "{", "if", "(", "isset", "(", "$", "event", "->", "data", "[", "'__laravel_notification_queued'", "]", ")", ")", "{", "return", "$", "event", "->", "data", "[", "'__laravel_notification_queued'", "]", ";", "}", "return", "$", "event", "->", "data", "[", "'__telescope_queued'", "]", "??", "false", ";", "}" ]
Determine whether the mailable was queued. @param \Illuminate\Mail\Events\MessageSent $event @return bool
[ "Determine", "whether", "the", "mailable", "was", "queued", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Watchers/MailWatcher.php#L69-L76
train
laravel/telescope
src/Watchers/MailWatcher.php
MailWatcher.tags
private function tags($message, $data) { return array_merge( array_keys($message->getTo() ?: []), array_keys($message->getCc() ?: []), array_keys($message->getBcc() ?: []), $data['__telescope'] ?? [] ); }
php
private function tags($message, $data) { return array_merge( array_keys($message->getTo() ?: []), array_keys($message->getCc() ?: []), array_keys($message->getBcc() ?: []), $data['__telescope'] ?? [] ); }
[ "private", "function", "tags", "(", "$", "message", ",", "$", "data", ")", "{", "return", "array_merge", "(", "array_keys", "(", "$", "message", "->", "getTo", "(", ")", "?", ":", "[", "]", ")", ",", "array_keys", "(", "$", "message", "->", "getCc", "(", ")", "?", ":", "[", "]", ")", ",", "array_keys", "(", "$", "message", "->", "getBcc", "(", ")", "?", ":", "[", "]", ")", ",", "$", "data", "[", "'__telescope'", "]", "??", "[", "]", ")", ";", "}" ]
Extract the tags from the message. @param \Swift_Message $message @param array $data @return array
[ "Extract", "the", "tags", "from", "the", "message", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Watchers/MailWatcher.php#L85-L93
train
laravel/telescope
src/Http/Controllers/MailEmlController.php
MailEmlController.show
public function show(EntriesRepository $storage, $id) { return response($storage->find($id)->content['raw'], 200, [ 'Content-Type' => 'message/rfc822', 'Content-Disposition' => 'attachment; filename="mail-'.$id.'.eml"', ]); }
php
public function show(EntriesRepository $storage, $id) { return response($storage->find($id)->content['raw'], 200, [ 'Content-Type' => 'message/rfc822', 'Content-Disposition' => 'attachment; filename="mail-'.$id.'.eml"', ]); }
[ "public", "function", "show", "(", "EntriesRepository", "$", "storage", ",", "$", "id", ")", "{", "return", "response", "(", "$", "storage", "->", "find", "(", "$", "id", ")", "->", "content", "[", "'raw'", "]", ",", "200", ",", "[", "'Content-Type'", "=>", "'message/rfc822'", ",", "'Content-Disposition'", "=>", "'attachment; filename=\"mail-'", ".", "$", "id", ".", "'.eml\"'", ",", "]", ")", ";", "}" ]
Download the Eml content of the email. @param \Laravel\Telescope\Contracts\EntriesRepository $storage @param int $id @return mixed
[ "Download", "the", "Eml", "content", "of", "the", "email", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Http/Controllers/MailEmlController.php#L17-L23
train
laravel/telescope
src/Watchers/ModelWatcher.php
ModelWatcher.recordAction
public function recordAction($event, $data) { if (! Telescope::isRecording() || ! $this->shouldRecord($event)) { return; } $model = FormatModel::given($data[0]); $changes = $data[0]->getChanges(); Telescope::recordModelEvent(IncomingEntry::make(array_filter([ 'action' => $this->action($event), 'model' => $model, 'changes' => empty($changes) ? null : $changes, ]))->tags([$model])); }
php
public function recordAction($event, $data) { if (! Telescope::isRecording() || ! $this->shouldRecord($event)) { return; } $model = FormatModel::given($data[0]); $changes = $data[0]->getChanges(); Telescope::recordModelEvent(IncomingEntry::make(array_filter([ 'action' => $this->action($event), 'model' => $model, 'changes' => empty($changes) ? null : $changes, ]))->tags([$model])); }
[ "public", "function", "recordAction", "(", "$", "event", ",", "$", "data", ")", "{", "if", "(", "!", "Telescope", "::", "isRecording", "(", ")", "||", "!", "$", "this", "->", "shouldRecord", "(", "$", "event", ")", ")", "{", "return", ";", "}", "$", "model", "=", "FormatModel", "::", "given", "(", "$", "data", "[", "0", "]", ")", ";", "$", "changes", "=", "$", "data", "[", "0", "]", "->", "getChanges", "(", ")", ";", "Telescope", "::", "recordModelEvent", "(", "IncomingEntry", "::", "make", "(", "array_filter", "(", "[", "'action'", "=>", "$", "this", "->", "action", "(", "$", "event", ")", ",", "'model'", "=>", "$", "model", ",", "'changes'", "=>", "empty", "(", "$", "changes", ")", "?", "null", ":", "$", "changes", ",", "]", ")", ")", "->", "tags", "(", "[", "$", "model", "]", ")", ")", ";", "}" ]
Record an action. @param string $event @param array $data @return void
[ "Record", "an", "action", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Watchers/ModelWatcher.php#L30-L45
train
laravel/telescope
src/Watchers/ScheduleWatcher.php
ScheduleWatcher.recordCommand
public function recordCommand(CommandStarting $event) { if (! Telescope::isRecording() || $event->command !== 'schedule:run' && $event->command !== 'schedule:finish') { return; } collect(app(Schedule::class)->events())->each(function ($event) { $event->then(function () use ($event) { Telescope::recordScheduledCommand(IncomingEntry::make([ 'command' => $event instanceof CallbackEvent ? 'Closure' : $event->command, 'description' => $event->description, 'expression' => $event->expression, 'timezone' => $event->timezone, 'user' => $event->user, 'output' => $this->getEventOutput($event), ])); }); }); }
php
public function recordCommand(CommandStarting $event) { if (! Telescope::isRecording() || $event->command !== 'schedule:run' && $event->command !== 'schedule:finish') { return; } collect(app(Schedule::class)->events())->each(function ($event) { $event->then(function () use ($event) { Telescope::recordScheduledCommand(IncomingEntry::make([ 'command' => $event instanceof CallbackEvent ? 'Closure' : $event->command, 'description' => $event->description, 'expression' => $event->expression, 'timezone' => $event->timezone, 'user' => $event->user, 'output' => $this->getEventOutput($event), ])); }); }); }
[ "public", "function", "recordCommand", "(", "CommandStarting", "$", "event", ")", "{", "if", "(", "!", "Telescope", "::", "isRecording", "(", ")", "||", "$", "event", "->", "command", "!==", "'schedule:run'", "&&", "$", "event", "->", "command", "!==", "'schedule:finish'", ")", "{", "return", ";", "}", "collect", "(", "app", "(", "Schedule", "::", "class", ")", "->", "events", "(", ")", ")", "->", "each", "(", "function", "(", "$", "event", ")", "{", "$", "event", "->", "then", "(", "function", "(", ")", "use", "(", "$", "event", ")", "{", "Telescope", "::", "recordScheduledCommand", "(", "IncomingEntry", "::", "make", "(", "[", "'command'", "=>", "$", "event", "instanceof", "CallbackEvent", "?", "'Closure'", ":", "$", "event", "->", "command", ",", "'description'", "=>", "$", "event", "->", "description", ",", "'expression'", "=>", "$", "event", "->", "expression", ",", "'timezone'", "=>", "$", "event", "->", "timezone", ",", "'user'", "=>", "$", "event", "->", "user", ",", "'output'", "=>", "$", "this", "->", "getEventOutput", "(", "$", "event", ")", ",", "]", ")", ")", ";", "}", ")", ";", "}", ")", ";", "}" ]
Record a scheduled command was executed. @param \Illuminate\Console\Events\CommandStarting $event @return void
[ "Record", "a", "scheduled", "command", "was", "executed", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Watchers/ScheduleWatcher.php#L31-L51
train
laravel/telescope
src/Watchers/ScheduleWatcher.php
ScheduleWatcher.getEventOutput
protected function getEventOutput(Event $event) { if (! $event->output || $event->output === $event->getDefaultOutput() || $event->shouldAppendOutput || ! file_exists($event->output)) { return ''; } return trim(file_get_contents($event->output)); }
php
protected function getEventOutput(Event $event) { if (! $event->output || $event->output === $event->getDefaultOutput() || $event->shouldAppendOutput || ! file_exists($event->output)) { return ''; } return trim(file_get_contents($event->output)); }
[ "protected", "function", "getEventOutput", "(", "Event", "$", "event", ")", "{", "if", "(", "!", "$", "event", "->", "output", "||", "$", "event", "->", "output", "===", "$", "event", "->", "getDefaultOutput", "(", ")", "||", "$", "event", "->", "shouldAppendOutput", "||", "!", "file_exists", "(", "$", "event", "->", "output", ")", ")", "{", "return", "''", ";", "}", "return", "trim", "(", "file_get_contents", "(", "$", "event", "->", "output", ")", ")", ";", "}" ]
Get the output for the scheduled event. @param \Illuminate\Console\Scheduling\Event $event @return string|null
[ "Get", "the", "output", "for", "the", "scheduled", "event", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Watchers/ScheduleWatcher.php#L59-L69
train
laravel/telescope
src/ListensForStorageOpportunities.php
ListensForStorageOpportunities.storeEntriesAfterWorkerLoop
protected static function storeEntriesAfterWorkerLoop($app) { $app['events']->listen(JobProcessing::class, function () { static::startRecording(); static::$processingJobs[] = true; }); $app['events']->listen(JobProcessed::class, function ($event) use ($app) { static::storeIfDoneProcessingJob($event, $app); }); $app['events']->listen(JobFailed::class, function ($event) use ($app) { static::storeIfDoneProcessingJob($event, $app); }); $app['events']->listen(JobExceptionOccurred::class, function () { array_pop(static::$processingJobs); }); }
php
protected static function storeEntriesAfterWorkerLoop($app) { $app['events']->listen(JobProcessing::class, function () { static::startRecording(); static::$processingJobs[] = true; }); $app['events']->listen(JobProcessed::class, function ($event) use ($app) { static::storeIfDoneProcessingJob($event, $app); }); $app['events']->listen(JobFailed::class, function ($event) use ($app) { static::storeIfDoneProcessingJob($event, $app); }); $app['events']->listen(JobExceptionOccurred::class, function () { array_pop(static::$processingJobs); }); }
[ "protected", "static", "function", "storeEntriesAfterWorkerLoop", "(", "$", "app", ")", "{", "$", "app", "[", "'events'", "]", "->", "listen", "(", "JobProcessing", "::", "class", ",", "function", "(", ")", "{", "static", "::", "startRecording", "(", ")", ";", "static", "::", "$", "processingJobs", "[", "]", "=", "true", ";", "}", ")", ";", "$", "app", "[", "'events'", "]", "->", "listen", "(", "JobProcessed", "::", "class", ",", "function", "(", "$", "event", ")", "use", "(", "$", "app", ")", "{", "static", "::", "storeIfDoneProcessingJob", "(", "$", "event", ",", "$", "app", ")", ";", "}", ")", ";", "$", "app", "[", "'events'", "]", "->", "listen", "(", "JobFailed", "::", "class", ",", "function", "(", "$", "event", ")", "use", "(", "$", "app", ")", "{", "static", "::", "storeIfDoneProcessingJob", "(", "$", "event", ",", "$", "app", ")", ";", "}", ")", ";", "$", "app", "[", "'events'", "]", "->", "listen", "(", "JobExceptionOccurred", "::", "class", ",", "function", "(", ")", "{", "array_pop", "(", "static", "::", "$", "processingJobs", ")", ";", "}", ")", ";", "}" ]
Store entries after the queue worker loops. @param \Illuminate\Foundation\Application $app @return void
[ "Store", "entries", "after", "the", "queue", "worker", "loops", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/ListensForStorageOpportunities.php#L54-L73
train
laravel/telescope
src/ListensForStorageOpportunities.php
ListensForStorageOpportunities.storeIfDoneProcessingJob
protected static function storeIfDoneProcessingJob($event, $app) { array_pop(static::$processingJobs); if (empty(static::$processingJobs)) { static::store($app[EntriesRepository::class]); if ($event->connectionName !== 'sync') { static::stopRecording(); } } }
php
protected static function storeIfDoneProcessingJob($event, $app) { array_pop(static::$processingJobs); if (empty(static::$processingJobs)) { static::store($app[EntriesRepository::class]); if ($event->connectionName !== 'sync') { static::stopRecording(); } } }
[ "protected", "static", "function", "storeIfDoneProcessingJob", "(", "$", "event", ",", "$", "app", ")", "{", "array_pop", "(", "static", "::", "$", "processingJobs", ")", ";", "if", "(", "empty", "(", "static", "::", "$", "processingJobs", ")", ")", "{", "static", "::", "store", "(", "$", "app", "[", "EntriesRepository", "::", "class", "]", ")", ";", "if", "(", "$", "event", "->", "connectionName", "!==", "'sync'", ")", "{", "static", "::", "stopRecording", "(", ")", ";", "}", "}", "}" ]
Store the recorded entries if totally done processing the current job. @param \Illuminate\Queue\Events\JobProcessed $event @param \Illuminate\Foundation\Application $app @return void
[ "Store", "the", "recorded", "entries", "if", "totally", "done", "processing", "the", "current", "job", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/ListensForStorageOpportunities.php#L82-L93
train
laravel/telescope
src/Watchers/NotificationWatcher.php
NotificationWatcher.recordNotification
public function recordNotification(NotificationSent $event) { if (! Telescope::isRecording()) { return; } Telescope::recordNotification(IncomingEntry::make([ 'notification' => get_class($event->notification), 'queued' => in_array(ShouldQueue::class, class_implements($event->notification)), 'notifiable' => $this->formatNotifiable($event->notifiable), 'channel' => $event->channel, 'response' => $event->response, ])->tags($this->tags($event))); }
php
public function recordNotification(NotificationSent $event) { if (! Telescope::isRecording()) { return; } Telescope::recordNotification(IncomingEntry::make([ 'notification' => get_class($event->notification), 'queued' => in_array(ShouldQueue::class, class_implements($event->notification)), 'notifiable' => $this->formatNotifiable($event->notifiable), 'channel' => $event->channel, 'response' => $event->response, ])->tags($this->tags($event))); }
[ "public", "function", "recordNotification", "(", "NotificationSent", "$", "event", ")", "{", "if", "(", "!", "Telescope", "::", "isRecording", "(", ")", ")", "{", "return", ";", "}", "Telescope", "::", "recordNotification", "(", "IncomingEntry", "::", "make", "(", "[", "'notification'", "=>", "get_class", "(", "$", "event", "->", "notification", ")", ",", "'queued'", "=>", "in_array", "(", "ShouldQueue", "::", "class", ",", "class_implements", "(", "$", "event", "->", "notification", ")", ")", ",", "'notifiable'", "=>", "$", "this", "->", "formatNotifiable", "(", "$", "event", "->", "notifiable", ")", ",", "'channel'", "=>", "$", "event", "->", "channel", ",", "'response'", "=>", "$", "event", "->", "response", ",", "]", ")", "->", "tags", "(", "$", "this", "->", "tags", "(", "$", "event", ")", ")", ")", ";", "}" ]
Record a new notification message was sent. @param \Illuminate\Notifications\Events\NotificationSent $event @return void
[ "Record", "a", "new", "notification", "message", "was", "sent", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Watchers/NotificationWatcher.php#L33-L46
train
laravel/telescope
src/Watchers/NotificationWatcher.php
NotificationWatcher.tags
private function tags($event) { return array_merge([ $this->formatNotifiable($event->notifiable), ], ExtractTags::from($event->notification)); }
php
private function tags($event) { return array_merge([ $this->formatNotifiable($event->notifiable), ], ExtractTags::from($event->notification)); }
[ "private", "function", "tags", "(", "$", "event", ")", "{", "return", "array_merge", "(", "[", "$", "this", "->", "formatNotifiable", "(", "$", "event", "->", "notifiable", ")", ",", "]", ",", "ExtractTags", "::", "from", "(", "$", "event", "->", "notification", ")", ")", ";", "}" ]
Extract the tags for the given event. @param \Illuminate\Notifications\Events\NotificationSent $event @return array
[ "Extract", "the", "tags", "for", "the", "given", "event", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Watchers/NotificationWatcher.php#L54-L59
train
laravel/telescope
src/Watchers/NotificationWatcher.php
NotificationWatcher.formatNotifiable
private function formatNotifiable($notifiable) { if ($notifiable instanceof Model) { return FormatModel::given($notifiable); } elseif ($notifiable instanceof AnonymousNotifiable) { return 'Anonymous:'.implode(',', $notifiable->routes); } return get_class($notifiable); }
php
private function formatNotifiable($notifiable) { if ($notifiable instanceof Model) { return FormatModel::given($notifiable); } elseif ($notifiable instanceof AnonymousNotifiable) { return 'Anonymous:'.implode(',', $notifiable->routes); } return get_class($notifiable); }
[ "private", "function", "formatNotifiable", "(", "$", "notifiable", ")", "{", "if", "(", "$", "notifiable", "instanceof", "Model", ")", "{", "return", "FormatModel", "::", "given", "(", "$", "notifiable", ")", ";", "}", "elseif", "(", "$", "notifiable", "instanceof", "AnonymousNotifiable", ")", "{", "return", "'Anonymous:'", ".", "implode", "(", "','", ",", "$", "notifiable", "->", "routes", ")", ";", "}", "return", "get_class", "(", "$", "notifiable", ")", ";", "}" ]
Format the given notifiable into a tag. @param mixed $notifiable @return string
[ "Format", "the", "given", "notifiable", "into", "a", "tag", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Watchers/NotificationWatcher.php#L67-L76
train
laravel/telescope
src/ExceptionContext.php
ExceptionContext.get
public static function get(Throwable $exception) { return collect(explode("\n", file_get_contents($exception->getFile()))) ->slice($exception->getLine() - 10, 20) ->mapWithKeys(function ($value, $key) { return [$key + 1 => $value]; })->all(); }
php
public static function get(Throwable $exception) { return collect(explode("\n", file_get_contents($exception->getFile()))) ->slice($exception->getLine() - 10, 20) ->mapWithKeys(function ($value, $key) { return [$key + 1 => $value]; })->all(); }
[ "public", "static", "function", "get", "(", "Throwable", "$", "exception", ")", "{", "return", "collect", "(", "explode", "(", "\"\\n\"", ",", "file_get_contents", "(", "$", "exception", "->", "getFile", "(", ")", ")", ")", ")", "->", "slice", "(", "$", "exception", "->", "getLine", "(", ")", "-", "10", ",", "20", ")", "->", "mapWithKeys", "(", "function", "(", "$", "value", ",", "$", "key", ")", "{", "return", "[", "$", "key", "+", "1", "=>", "$", "value", "]", ";", "}", ")", "->", "all", "(", ")", ";", "}" ]
Get the exception code context for the given exception. @param \Throwable $exception @return array
[ "Get", "the", "exception", "code", "context", "for", "the", "given", "exception", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/ExceptionContext.php#L15-L22
train
laravel/telescope
src/Watchers/LogWatcher.php
LogWatcher.recordLog
public function recordLog(MessageLogged $event) { if (! Telescope::isRecording() || $this->shouldIgnore($event)) { return; } Telescope::recordLog( IncomingEntry::make([ 'level' => $event->level, 'message' => $event->message, 'context' => Arr::except($event->context, ['telescope']), ])->tags($this->tags($event)) ); }
php
public function recordLog(MessageLogged $event) { if (! Telescope::isRecording() || $this->shouldIgnore($event)) { return; } Telescope::recordLog( IncomingEntry::make([ 'level' => $event->level, 'message' => $event->message, 'context' => Arr::except($event->context, ['telescope']), ])->tags($this->tags($event)) ); }
[ "public", "function", "recordLog", "(", "MessageLogged", "$", "event", ")", "{", "if", "(", "!", "Telescope", "::", "isRecording", "(", ")", "||", "$", "this", "->", "shouldIgnore", "(", "$", "event", ")", ")", "{", "return", ";", "}", "Telescope", "::", "recordLog", "(", "IncomingEntry", "::", "make", "(", "[", "'level'", "=>", "$", "event", "->", "level", ",", "'message'", "=>", "$", "event", "->", "message", ",", "'context'", "=>", "Arr", "::", "except", "(", "$", "event", "->", "context", ",", "[", "'telescope'", "]", ")", ",", "]", ")", "->", "tags", "(", "$", "this", "->", "tags", "(", "$", "event", ")", ")", ")", ";", "}" ]
Record a message was logged. @param \Illuminate\Log\Events\MessageLogged $event @return void
[ "Record", "a", "message", "was", "logged", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Watchers/LogWatcher.php#L30-L43
train
laravel/telescope
src/Storage/EntryQueryOptions.php
EntryQueryOptions.fromRequest
public static function fromRequest(Request $request) { return (new static) ->batchId($request->batch_id) ->uuids($request->uuids) ->beforeSequence($request->before) ->tag($request->tag) ->familyHash($request->family_hash) ->limit($request->take ?? 50); }
php
public static function fromRequest(Request $request) { return (new static) ->batchId($request->batch_id) ->uuids($request->uuids) ->beforeSequence($request->before) ->tag($request->tag) ->familyHash($request->family_hash) ->limit($request->take ?? 50); }
[ "public", "static", "function", "fromRequest", "(", "Request", "$", "request", ")", "{", "return", "(", "new", "static", ")", "->", "batchId", "(", "$", "request", "->", "batch_id", ")", "->", "uuids", "(", "$", "request", "->", "uuids", ")", "->", "beforeSequence", "(", "$", "request", "->", "before", ")", "->", "tag", "(", "$", "request", "->", "tag", ")", "->", "familyHash", "(", "$", "request", "->", "family_hash", ")", "->", "limit", "(", "$", "request", "->", "take", "??", "50", ")", ";", "}" ]
Create new entry query options from the incoming request. @param \Illuminate\Http\Request $request @return static
[ "Create", "new", "entry", "query", "options", "from", "the", "incoming", "request", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Storage/EntryQueryOptions.php#L57-L66
train
laravel/telescope
src/Watchers/RequestWatcher.php
RequestWatcher.recordRequest
public function recordRequest(RequestHandled $event) { if (! Telescope::isRecording()) { return; } Telescope::recordRequest(IncomingEntry::make([ 'uri' => str_replace($event->request->root(), '', $event->request->fullUrl()) ?: '/', 'method' => $event->request->method(), 'controller_action' => optional($event->request->route())->getActionName(), 'middleware' => array_values(optional($event->request->route())->gatherMiddleware() ?? []), 'headers' => $this->headers($event->request->headers->all()), 'payload' => $this->payload($this->input($event->request)), 'session' => $this->payload($this->sessionVariables($event->request)), 'response_status' => $event->response->getStatusCode(), 'response' => $this->response($event->response), 'duration' => defined('LARAVEL_START') ? floor((microtime(true) - LARAVEL_START) * 1000) : null, ])); }
php
public function recordRequest(RequestHandled $event) { if (! Telescope::isRecording()) { return; } Telescope::recordRequest(IncomingEntry::make([ 'uri' => str_replace($event->request->root(), '', $event->request->fullUrl()) ?: '/', 'method' => $event->request->method(), 'controller_action' => optional($event->request->route())->getActionName(), 'middleware' => array_values(optional($event->request->route())->gatherMiddleware() ?? []), 'headers' => $this->headers($event->request->headers->all()), 'payload' => $this->payload($this->input($event->request)), 'session' => $this->payload($this->sessionVariables($event->request)), 'response_status' => $event->response->getStatusCode(), 'response' => $this->response($event->response), 'duration' => defined('LARAVEL_START') ? floor((microtime(true) - LARAVEL_START) * 1000) : null, ])); }
[ "public", "function", "recordRequest", "(", "RequestHandled", "$", "event", ")", "{", "if", "(", "!", "Telescope", "::", "isRecording", "(", ")", ")", "{", "return", ";", "}", "Telescope", "::", "recordRequest", "(", "IncomingEntry", "::", "make", "(", "[", "'uri'", "=>", "str_replace", "(", "$", "event", "->", "request", "->", "root", "(", ")", ",", "''", ",", "$", "event", "->", "request", "->", "fullUrl", "(", ")", ")", "?", ":", "'/'", ",", "'method'", "=>", "$", "event", "->", "request", "->", "method", "(", ")", ",", "'controller_action'", "=>", "optional", "(", "$", "event", "->", "request", "->", "route", "(", ")", ")", "->", "getActionName", "(", ")", ",", "'middleware'", "=>", "array_values", "(", "optional", "(", "$", "event", "->", "request", "->", "route", "(", ")", ")", "->", "gatherMiddleware", "(", ")", "??", "[", "]", ")", ",", "'headers'", "=>", "$", "this", "->", "headers", "(", "$", "event", "->", "request", "->", "headers", "->", "all", "(", ")", ")", ",", "'payload'", "=>", "$", "this", "->", "payload", "(", "$", "this", "->", "input", "(", "$", "event", "->", "request", ")", ")", ",", "'session'", "=>", "$", "this", "->", "payload", "(", "$", "this", "->", "sessionVariables", "(", "$", "event", "->", "request", ")", ")", ",", "'response_status'", "=>", "$", "event", "->", "response", "->", "getStatusCode", "(", ")", ",", "'response'", "=>", "$", "this", "->", "response", "(", "$", "event", "->", "response", ")", ",", "'duration'", "=>", "defined", "(", "'LARAVEL_START'", ")", "?", "floor", "(", "(", "microtime", "(", "true", ")", "-", "LARAVEL_START", ")", "*", "1000", ")", ":", "null", ",", "]", ")", ")", ";", "}" ]
Record an incoming HTTP request. @param \Illuminate\Foundation\Http\Events\RequestHandled $event @return void
[ "Record", "an", "incoming", "HTTP", "request", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Watchers/RequestWatcher.php#L36-L54
train
laravel/telescope
src/Watchers/RequestWatcher.php
RequestWatcher.headers
protected function headers($headers) { $headers = collect($headers)->map(function ($header) { return $header[0]; })->toArray(); return $this->hideParameters($headers, Telescope::$hiddenRequestHeaders ); }
php
protected function headers($headers) { $headers = collect($headers)->map(function ($header) { return $header[0]; })->toArray(); return $this->hideParameters($headers, Telescope::$hiddenRequestHeaders ); }
[ "protected", "function", "headers", "(", "$", "headers", ")", "{", "$", "headers", "=", "collect", "(", "$", "headers", ")", "->", "map", "(", "function", "(", "$", "header", ")", "{", "return", "$", "header", "[", "0", "]", ";", "}", ")", "->", "toArray", "(", ")", ";", "return", "$", "this", "->", "hideParameters", "(", "$", "headers", ",", "Telescope", "::", "$", "hiddenRequestHeaders", ")", ";", "}" ]
Format the given headers. @param array $headers @return array
[ "Format", "the", "given", "headers", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Watchers/RequestWatcher.php#L62-L71
train
laravel/telescope
src/Watchers/RequestWatcher.php
RequestWatcher.hideParameters
protected function hideParameters($data, $hidden) { foreach ($hidden as $parameter) { if (Arr::get($data, $parameter)) { Arr::set($data, $parameter, '********'); } } return $data; }
php
protected function hideParameters($data, $hidden) { foreach ($hidden as $parameter) { if (Arr::get($data, $parameter)) { Arr::set($data, $parameter, '********'); } } return $data; }
[ "protected", "function", "hideParameters", "(", "$", "data", ",", "$", "hidden", ")", "{", "foreach", "(", "$", "hidden", "as", "$", "parameter", ")", "{", "if", "(", "Arr", "::", "get", "(", "$", "data", ",", "$", "parameter", ")", ")", "{", "Arr", "::", "set", "(", "$", "data", ",", "$", "parameter", ",", "'********'", ")", ";", "}", "}", "return", "$", "data", ";", "}" ]
Hide the given parameters. @param array $data @param array $hidden @return mixed
[ "Hide", "the", "given", "parameters", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Watchers/RequestWatcher.php#L93-L102
train
laravel/telescope
src/Watchers/RequestWatcher.php
RequestWatcher.input
private function input(Request $request) { $files = $request->files->all(); array_walk_recursive($files, function (&$file) { $file = [ 'name' => $file->getClientOriginalName(), 'size' => $file->isFile() ? ($file->getSize() / 1000).'KB' : '0', ]; }); return array_replace_recursive($request->input(), $files); }
php
private function input(Request $request) { $files = $request->files->all(); array_walk_recursive($files, function (&$file) { $file = [ 'name' => $file->getClientOriginalName(), 'size' => $file->isFile() ? ($file->getSize() / 1000).'KB' : '0', ]; }); return array_replace_recursive($request->input(), $files); }
[ "private", "function", "input", "(", "Request", "$", "request", ")", "{", "$", "files", "=", "$", "request", "->", "files", "->", "all", "(", ")", ";", "array_walk_recursive", "(", "$", "files", ",", "function", "(", "&", "$", "file", ")", "{", "$", "file", "=", "[", "'name'", "=>", "$", "file", "->", "getClientOriginalName", "(", ")", ",", "'size'", "=>", "$", "file", "->", "isFile", "(", ")", "?", "(", "$", "file", "->", "getSize", "(", ")", "/", "1000", ")", ".", "'KB'", ":", "'0'", ",", "]", ";", "}", ")", ";", "return", "array_replace_recursive", "(", "$", "request", "->", "input", "(", ")", ",", "$", "files", ")", ";", "}" ]
Extract the input from the given request. @param \Illuminate\Http\Request $request @return array
[ "Extract", "the", "input", "from", "the", "given", "request", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Watchers/RequestWatcher.php#L121-L133
train
laravel/telescope
src/Watchers/RequestWatcher.php
RequestWatcher.response
protected function response(Response $response) { $content = $response->getContent(); if (is_string($content) && is_array(json_decode($content, true)) && json_last_error() === JSON_ERROR_NONE) { return $this->contentWithinLimits($content) ? $this->hideParameters(json_decode($content, true), Telescope::$hiddenResponseParameters) : 'Purged By Telescope'; } if ($response instanceof RedirectResponse) { return 'Redirected to '.$response->getTargetUrl(); } if ($response instanceof IlluminateResponse && $response->getOriginalContent() instanceof View) { return [ 'view' => $response->getOriginalContent()->getPath(), 'data' => $this->extractDataFromView($response->getOriginalContent()), ]; } return 'HTML Response'; }
php
protected function response(Response $response) { $content = $response->getContent(); if (is_string($content) && is_array(json_decode($content, true)) && json_last_error() === JSON_ERROR_NONE) { return $this->contentWithinLimits($content) ? $this->hideParameters(json_decode($content, true), Telescope::$hiddenResponseParameters) : 'Purged By Telescope'; } if ($response instanceof RedirectResponse) { return 'Redirected to '.$response->getTargetUrl(); } if ($response instanceof IlluminateResponse && $response->getOriginalContent() instanceof View) { return [ 'view' => $response->getOriginalContent()->getPath(), 'data' => $this->extractDataFromView($response->getOriginalContent()), ]; } return 'HTML Response'; }
[ "protected", "function", "response", "(", "Response", "$", "response", ")", "{", "$", "content", "=", "$", "response", "->", "getContent", "(", ")", ";", "if", "(", "is_string", "(", "$", "content", ")", "&&", "is_array", "(", "json_decode", "(", "$", "content", ",", "true", ")", ")", "&&", "json_last_error", "(", ")", "===", "JSON_ERROR_NONE", ")", "{", "return", "$", "this", "->", "contentWithinLimits", "(", "$", "content", ")", "?", "$", "this", "->", "hideParameters", "(", "json_decode", "(", "$", "content", ",", "true", ")", ",", "Telescope", "::", "$", "hiddenResponseParameters", ")", ":", "'Purged By Telescope'", ";", "}", "if", "(", "$", "response", "instanceof", "RedirectResponse", ")", "{", "return", "'Redirected to '", ".", "$", "response", "->", "getTargetUrl", "(", ")", ";", "}", "if", "(", "$", "response", "instanceof", "IlluminateResponse", "&&", "$", "response", "->", "getOriginalContent", "(", ")", "instanceof", "View", ")", "{", "return", "[", "'view'", "=>", "$", "response", "->", "getOriginalContent", "(", ")", "->", "getPath", "(", ")", ",", "'data'", "=>", "$", "this", "->", "extractDataFromView", "(", "$", "response", "->", "getOriginalContent", "(", ")", ")", ",", "]", ";", "}", "return", "'HTML Response'", ";", "}" ]
Format the given response object. @param \Symfony\Component\HttpFoundation\Response $response @return array|string
[ "Format", "the", "given", "response", "object", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Watchers/RequestWatcher.php#L141-L165
train
laravel/telescope
src/Watchers/RequestWatcher.php
RequestWatcher.extractDataFromView
protected function extractDataFromView($view) { return collect($view->getData())->map(function ($value) { if ($value instanceof Model) { return FormatModel::given($value); } elseif (is_object($value)) { return [ 'class' => get_class($value), 'properties' => json_decode(json_encode($value), true), ]; } else { return json_decode(json_encode($value), true); } })->toArray(); }
php
protected function extractDataFromView($view) { return collect($view->getData())->map(function ($value) { if ($value instanceof Model) { return FormatModel::given($value); } elseif (is_object($value)) { return [ 'class' => get_class($value), 'properties' => json_decode(json_encode($value), true), ]; } else { return json_decode(json_encode($value), true); } })->toArray(); }
[ "protected", "function", "extractDataFromView", "(", "$", "view", ")", "{", "return", "collect", "(", "$", "view", "->", "getData", "(", ")", ")", "->", "map", "(", "function", "(", "$", "value", ")", "{", "if", "(", "$", "value", "instanceof", "Model", ")", "{", "return", "FormatModel", "::", "given", "(", "$", "value", ")", ";", "}", "elseif", "(", "is_object", "(", "$", "value", ")", ")", "{", "return", "[", "'class'", "=>", "get_class", "(", "$", "value", ")", ",", "'properties'", "=>", "json_decode", "(", "json_encode", "(", "$", "value", ")", ",", "true", ")", ",", "]", ";", "}", "else", "{", "return", "json_decode", "(", "json_encode", "(", "$", "value", ")", ",", "true", ")", ";", "}", "}", ")", "->", "toArray", "(", ")", ";", "}" ]
Extract the data from the given view in array form. @param \Illuminate\View\View $view @return array
[ "Extract", "the", "data", "from", "the", "given", "view", "in", "array", "form", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Watchers/RequestWatcher.php#L186-L200
train
laravel/telescope
src/Watchers/CommandWatcher.php
CommandWatcher.recordCommand
public function recordCommand(CommandFinished $event) { if (! Telescope::isRecording() || $this->shouldIgnore($event)) { return; } Telescope::recordCommand(IncomingEntry::make([ 'command' => $event->command ?? $event->input->getArguments()['command'] ?? 'default', 'exit_code' => $event->exitCode, 'arguments' => $event->input->getArguments(), 'options' => $event->input->getOptions(), ])); }
php
public function recordCommand(CommandFinished $event) { if (! Telescope::isRecording() || $this->shouldIgnore($event)) { return; } Telescope::recordCommand(IncomingEntry::make([ 'command' => $event->command ?? $event->input->getArguments()['command'] ?? 'default', 'exit_code' => $event->exitCode, 'arguments' => $event->input->getArguments(), 'options' => $event->input->getOptions(), ])); }
[ "public", "function", "recordCommand", "(", "CommandFinished", "$", "event", ")", "{", "if", "(", "!", "Telescope", "::", "isRecording", "(", ")", "||", "$", "this", "->", "shouldIgnore", "(", "$", "event", ")", ")", "{", "return", ";", "}", "Telescope", "::", "recordCommand", "(", "IncomingEntry", "::", "make", "(", "[", "'command'", "=>", "$", "event", "->", "command", "??", "$", "event", "->", "input", "->", "getArguments", "(", ")", "[", "'command'", "]", "??", "'default'", ",", "'exit_code'", "=>", "$", "event", "->", "exitCode", ",", "'arguments'", "=>", "$", "event", "->", "input", "->", "getArguments", "(", ")", ",", "'options'", "=>", "$", "event", "->", "input", "->", "getOptions", "(", ")", ",", "]", ")", ")", ";", "}" ]
Record an Artisan command was executed. @param \Illuminate\Console\Events\CommandFinished $event @return void
[ "Record", "an", "Artisan", "command", "was", "executed", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Watchers/CommandWatcher.php#L28-L40
train
laravel/telescope
src/Watchers/CacheWatcher.php
CacheWatcher.recordCacheHit
public function recordCacheHit(CacheHit $event) { if (! Telescope::isRecording() || $this->shouldIgnore($event)) { return; } Telescope::recordCache(IncomingEntry::make([ 'type' => 'hit', 'key' => $event->key, 'value' => $event->value, ])); }
php
public function recordCacheHit(CacheHit $event) { if (! Telescope::isRecording() || $this->shouldIgnore($event)) { return; } Telescope::recordCache(IncomingEntry::make([ 'type' => 'hit', 'key' => $event->key, 'value' => $event->value, ])); }
[ "public", "function", "recordCacheHit", "(", "CacheHit", "$", "event", ")", "{", "if", "(", "!", "Telescope", "::", "isRecording", "(", ")", "||", "$", "this", "->", "shouldIgnore", "(", "$", "event", ")", ")", "{", "return", ";", "}", "Telescope", "::", "recordCache", "(", "IncomingEntry", "::", "make", "(", "[", "'type'", "=>", "'hit'", ",", "'key'", "=>", "$", "event", "->", "key", ",", "'value'", "=>", "$", "event", "->", "value", ",", "]", ")", ")", ";", "}" ]
Record a cache key was found. @param \Illuminate\Cache\Events\CacheHit $event @return void
[ "Record", "a", "cache", "key", "was", "found", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Watchers/CacheWatcher.php#L36-L47
train
laravel/telescope
src/Watchers/CacheWatcher.php
CacheWatcher.recordCacheMissed
public function recordCacheMissed(CacheMissed $event) { if (! Telescope::isRecording() || $this->shouldIgnore($event)) { return; } Telescope::recordCache(IncomingEntry::make([ 'type' => 'missed', 'key' => $event->key, ])); }
php
public function recordCacheMissed(CacheMissed $event) { if (! Telescope::isRecording() || $this->shouldIgnore($event)) { return; } Telescope::recordCache(IncomingEntry::make([ 'type' => 'missed', 'key' => $event->key, ])); }
[ "public", "function", "recordCacheMissed", "(", "CacheMissed", "$", "event", ")", "{", "if", "(", "!", "Telescope", "::", "isRecording", "(", ")", "||", "$", "this", "->", "shouldIgnore", "(", "$", "event", ")", ")", "{", "return", ";", "}", "Telescope", "::", "recordCache", "(", "IncomingEntry", "::", "make", "(", "[", "'type'", "=>", "'missed'", ",", "'key'", "=>", "$", "event", "->", "key", ",", "]", ")", ")", ";", "}" ]
Record a missing cache key. @param \Illuminate\Cache\Events\CacheMissed $event @return void
[ "Record", "a", "missing", "cache", "key", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Watchers/CacheWatcher.php#L55-L65
train
laravel/telescope
src/Watchers/CacheWatcher.php
CacheWatcher.recordKeyWritten
public function recordKeyWritten(KeyWritten $event) { if (! Telescope::isRecording() || $this->shouldIgnore($event)) { return; } Telescope::recordCache(IncomingEntry::make([ 'type' => 'set', 'key' => $event->key, 'value' => $event->value, 'expiration' => $this->formatExpiration($event), ])); }
php
public function recordKeyWritten(KeyWritten $event) { if (! Telescope::isRecording() || $this->shouldIgnore($event)) { return; } Telescope::recordCache(IncomingEntry::make([ 'type' => 'set', 'key' => $event->key, 'value' => $event->value, 'expiration' => $this->formatExpiration($event), ])); }
[ "public", "function", "recordKeyWritten", "(", "KeyWritten", "$", "event", ")", "{", "if", "(", "!", "Telescope", "::", "isRecording", "(", ")", "||", "$", "this", "->", "shouldIgnore", "(", "$", "event", ")", ")", "{", "return", ";", "}", "Telescope", "::", "recordCache", "(", "IncomingEntry", "::", "make", "(", "[", "'type'", "=>", "'set'", ",", "'key'", "=>", "$", "event", "->", "key", ",", "'value'", "=>", "$", "event", "->", "value", ",", "'expiration'", "=>", "$", "this", "->", "formatExpiration", "(", "$", "event", ")", ",", "]", ")", ")", ";", "}" ]
Record a cache key was updated. @param \Illuminate\Cache\Events\KeyWritten $event @return void
[ "Record", "a", "cache", "key", "was", "updated", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/Watchers/CacheWatcher.php#L73-L85
train
laravel/telescope
src/IncomingEntry.php
IncomingEntry.user
public function user($user) { $this->user = $user; $this->content = array_merge($this->content, [ 'user' => [ 'id' => $user->getAuthIdentifier(), 'name' => $user->name ?? null, 'email' => $user->email ?? null, ], ]); $this->tags(['Auth:'.$user->getAuthIdentifier()]); return $this; }
php
public function user($user) { $this->user = $user; $this->content = array_merge($this->content, [ 'user' => [ 'id' => $user->getAuthIdentifier(), 'name' => $user->name ?? null, 'email' => $user->email ?? null, ], ]); $this->tags(['Auth:'.$user->getAuthIdentifier()]); return $this; }
[ "public", "function", "user", "(", "$", "user", ")", "{", "$", "this", "->", "user", "=", "$", "user", ";", "$", "this", "->", "content", "=", "array_merge", "(", "$", "this", "->", "content", ",", "[", "'user'", "=>", "[", "'id'", "=>", "$", "user", "->", "getAuthIdentifier", "(", ")", ",", "'name'", "=>", "$", "user", "->", "name", "??", "null", ",", "'email'", "=>", "$", "user", "->", "email", "??", "null", ",", "]", ",", "]", ")", ";", "$", "this", "->", "tags", "(", "[", "'Auth:'", ".", "$", "user", "->", "getAuthIdentifier", "(", ")", "]", ")", ";", "return", "$", "this", ";", "}" ]
Set the currently authenticated user. @param \Illuminate\Contracts\Auth\Authenticatable $user @return $this
[ "Set", "the", "currently", "authenticated", "user", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/IncomingEntry.php#L126-L141
train
laravel/telescope
src/IncomingEntry.php
IncomingEntry.tags
public function tags(array $tags) { $this->tags = array_unique(array_merge($this->tags, $tags)); return $this; }
php
public function tags(array $tags) { $this->tags = array_unique(array_merge($this->tags, $tags)); return $this; }
[ "public", "function", "tags", "(", "array", "$", "tags", ")", "{", "$", "this", "->", "tags", "=", "array_unique", "(", "array_merge", "(", "$", "this", "->", "tags", ",", "$", "tags", ")", ")", ";", "return", "$", "this", ";", "}" ]
Merge tags into the entry's existing tags. @param array $tags @return $this
[ "Merge", "tags", "into", "the", "entry", "s", "existing", "tags", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/IncomingEntry.php#L149-L154
train
laravel/telescope
src/IncomingEntry.php
IncomingEntry.hasMonitoredTag
public function hasMonitoredTag() { if (! empty($this->tags)) { return app(EntriesRepository::class)->isMonitoring($this->tags); } return false; }
php
public function hasMonitoredTag() { if (! empty($this->tags)) { return app(EntriesRepository::class)->isMonitoring($this->tags); } return false; }
[ "public", "function", "hasMonitoredTag", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "tags", ")", ")", "{", "return", "app", "(", "EntriesRepository", "::", "class", ")", "->", "isMonitoring", "(", "$", "this", "->", "tags", ")", ";", "}", "return", "false", ";", "}" ]
Determine if the incoming entry has a monitored tag. @return bool
[ "Determine", "if", "the", "incoming", "entry", "has", "a", "monitored", "tag", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/IncomingEntry.php#L161-L168
train
laravel/telescope
src/IncomingEntry.php
IncomingEntry.toArray
public function toArray() { return [ 'uuid' => $this->uuid, 'batch_id' => $this->batchId, 'type' => $this->type, 'content' => $this->content, 'created_at' => $this->recordedAt->toDateTimeString(), ]; }
php
public function toArray() { return [ 'uuid' => $this->uuid, 'batch_id' => $this->batchId, 'type' => $this->type, 'content' => $this->content, 'created_at' => $this->recordedAt->toDateTimeString(), ]; }
[ "public", "function", "toArray", "(", ")", "{", "return", "[", "'uuid'", "=>", "$", "this", "->", "uuid", ",", "'batch_id'", "=>", "$", "this", "->", "batchId", ",", "'type'", "=>", "$", "this", "->", "type", ",", "'content'", "=>", "$", "this", "->", "content", ",", "'created_at'", "=>", "$", "this", "->", "recordedAt", "->", "toDateTimeString", "(", ")", ",", "]", ";", "}" ]
Get an array representation of the entry for storage. @return array
[ "Get", "an", "array", "representation", "of", "the", "entry", "for", "storage", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/IncomingEntry.php#L236-L245
train
laravel/telescope
src/IncomingDumpEntry.php
IncomingDumpEntry.assignEntryPointFromBatch
public function assignEntryPointFromBatch(array $batch) { $entryPoint = collect($batch)->first(function ($entry) { return in_array($entry->type, [EntryType::REQUEST, EntryType::JOB, EntryType::COMMAND]); }); if (! $entryPoint) { return; } $this->content = array_merge($this->content, [ 'entry_point_type' => $entryPoint->type, 'entry_point_uuid' => $entryPoint->uuid, 'entry_point_description' => $this->entryPointDescription($entryPoint), ]); }
php
public function assignEntryPointFromBatch(array $batch) { $entryPoint = collect($batch)->first(function ($entry) { return in_array($entry->type, [EntryType::REQUEST, EntryType::JOB, EntryType::COMMAND]); }); if (! $entryPoint) { return; } $this->content = array_merge($this->content, [ 'entry_point_type' => $entryPoint->type, 'entry_point_uuid' => $entryPoint->uuid, 'entry_point_description' => $this->entryPointDescription($entryPoint), ]); }
[ "public", "function", "assignEntryPointFromBatch", "(", "array", "$", "batch", ")", "{", "$", "entryPoint", "=", "collect", "(", "$", "batch", ")", "->", "first", "(", "function", "(", "$", "entry", ")", "{", "return", "in_array", "(", "$", "entry", "->", "type", ",", "[", "EntryType", "::", "REQUEST", ",", "EntryType", "::", "JOB", ",", "EntryType", "::", "COMMAND", "]", ")", ";", "}", ")", ";", "if", "(", "!", "$", "entryPoint", ")", "{", "return", ";", "}", "$", "this", "->", "content", "=", "array_merge", "(", "$", "this", "->", "content", ",", "[", "'entry_point_type'", "=>", "$", "entryPoint", "->", "type", ",", "'entry_point_uuid'", "=>", "$", "entryPoint", "->", "uuid", ",", "'entry_point_description'", "=>", "$", "this", "->", "entryPointDescription", "(", "$", "entryPoint", ")", ",", "]", ")", ";", "}" ]
Assign entry point parameters from the given batch entries. @param array $batch @return void
[ "Assign", "entry", "point", "parameters", "from", "the", "given", "batch", "entries", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/IncomingDumpEntry.php#L23-L38
train
laravel/telescope
src/IncomingDumpEntry.php
IncomingDumpEntry.entryPointDescription
private function entryPointDescription($entryPoint) { switch ($entryPoint->type) { case EntryType::REQUEST: return $entryPoint->content['method'].' '.$entryPoint->content['uri']; case EntryType::JOB: return $entryPoint->content['name']; case EntryType::COMMAND: return $entryPoint->content['command']; } return ''; }
php
private function entryPointDescription($entryPoint) { switch ($entryPoint->type) { case EntryType::REQUEST: return $entryPoint->content['method'].' '.$entryPoint->content['uri']; case EntryType::JOB: return $entryPoint->content['name']; case EntryType::COMMAND: return $entryPoint->content['command']; } return ''; }
[ "private", "function", "entryPointDescription", "(", "$", "entryPoint", ")", "{", "switch", "(", "$", "entryPoint", "->", "type", ")", "{", "case", "EntryType", "::", "REQUEST", ":", "return", "$", "entryPoint", "->", "content", "[", "'method'", "]", ".", "' '", ".", "$", "entryPoint", "->", "content", "[", "'uri'", "]", ";", "case", "EntryType", "::", "JOB", ":", "return", "$", "entryPoint", "->", "content", "[", "'name'", "]", ";", "case", "EntryType", "::", "COMMAND", ":", "return", "$", "entryPoint", "->", "content", "[", "'command'", "]", ";", "}", "return", "''", ";", "}" ]
Description for the entry point. @param \Laravel\Telescope\IncomingDumpEntry $entryPoint @return string
[ "Description", "for", "the", "entry", "point", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/IncomingDumpEntry.php#L46-L60
train
laravel/telescope
src/EntryResult.php
EntryResult.jsonSerialize
public function jsonSerialize() { return [ 'id' => $this->id, 'sequence' => $this->sequence, 'batch_id' => $this->batchId, 'type' => $this->type, 'content' => $this->content, 'tags' => $this->tags, 'family_hash' => $this->familyHash, 'created_at' => $this->createdAt->toDateTimeString(), ]; }
php
public function jsonSerialize() { return [ 'id' => $this->id, 'sequence' => $this->sequence, 'batch_id' => $this->batchId, 'type' => $this->type, 'content' => $this->content, 'tags' => $this->tags, 'family_hash' => $this->familyHash, 'created_at' => $this->createdAt->toDateTimeString(), ]; }
[ "public", "function", "jsonSerialize", "(", ")", "{", "return", "[", "'id'", "=>", "$", "this", "->", "id", ",", "'sequence'", "=>", "$", "this", "->", "sequence", ",", "'batch_id'", "=>", "$", "this", "->", "batchId", ",", "'type'", "=>", "$", "this", "->", "type", ",", "'content'", "=>", "$", "this", "->", "content", ",", "'tags'", "=>", "$", "this", "->", "tags", ",", "'family_hash'", "=>", "$", "this", "->", "familyHash", ",", "'created_at'", "=>", "$", "this", "->", "createdAt", "->", "toDateTimeString", "(", ")", ",", "]", ";", "}" ]
Get the array representation of the entry. @return array
[ "Get", "the", "array", "representation", "of", "the", "entry", "." ]
e5f9512a41f21319d9c99cef618baba0d9206dce
https://github.com/laravel/telescope/blob/e5f9512a41f21319d9c99cef618baba0d9206dce/src/EntryResult.php#L94-L106
train
vimeo/psalm
src/Psalm/Internal/ExecutionEnvironment/GitInfoCollector.php
GitInfoCollector.collect
public function collect() : GitInfo { $branch = $this->collectBranch(); $commit = $this->collectCommit(); $remotes = $this->collectRemotes(); return new GitInfo($branch, $commit, $remotes); }
php
public function collect() : GitInfo { $branch = $this->collectBranch(); $commit = $this->collectCommit(); $remotes = $this->collectRemotes(); return new GitInfo($branch, $commit, $remotes); }
[ "public", "function", "collect", "(", ")", ":", "GitInfo", "{", "$", "branch", "=", "$", "this", "->", "collectBranch", "(", ")", ";", "$", "commit", "=", "$", "this", "->", "collectCommit", "(", ")", ";", "$", "remotes", "=", "$", "this", "->", "collectRemotes", "(", ")", ";", "return", "new", "GitInfo", "(", "$", "branch", ",", "$", "commit", ",", "$", "remotes", ")", ";", "}" ]
Collect git repository info.
[ "Collect", "git", "repository", "info", "." ]
dd409871876fcafb4a85ac3901453fb05c46814c
https://github.com/vimeo/psalm/blob/dd409871876fcafb4a85ac3901453fb05c46814c/src/Psalm/Internal/ExecutionEnvironment/GitInfoCollector.php#L38-L45
train
vimeo/psalm
src/Psalm/Internal/LanguageServer/Message.php
Message.parse
public static function parse(string $msg): Message { $obj = new self; $parts = explode("\r\n", $msg); $obj->body = MessageBody::parse(array_pop($parts)); foreach ($parts as $line) { if ($line) { $pair = explode(': ', $line); $obj->headers[$pair[0]] = $pair[1]; } } return $obj; }
php
public static function parse(string $msg): Message { $obj = new self; $parts = explode("\r\n", $msg); $obj->body = MessageBody::parse(array_pop($parts)); foreach ($parts as $line) { if ($line) { $pair = explode(': ', $line); $obj->headers[$pair[0]] = $pair[1]; } } return $obj; }
[ "public", "static", "function", "parse", "(", "string", "$", "msg", ")", ":", "Message", "{", "$", "obj", "=", "new", "self", ";", "$", "parts", "=", "explode", "(", "\"\\r\\n\"", ",", "$", "msg", ")", ";", "$", "obj", "->", "body", "=", "MessageBody", "::", "parse", "(", "array_pop", "(", "$", "parts", ")", ")", ";", "foreach", "(", "$", "parts", "as", "$", "line", ")", "{", "if", "(", "$", "line", ")", "{", "$", "pair", "=", "explode", "(", "': '", ",", "$", "line", ")", ";", "$", "obj", "->", "headers", "[", "$", "pair", "[", "0", "]", "]", "=", "$", "pair", "[", "1", "]", ";", "}", "}", "return", "$", "obj", ";", "}" ]
Parses a message @param string $msg @return Message @psalm-suppress UnusedMethod
[ "Parses", "a", "message" ]
dd409871876fcafb4a85ac3901453fb05c46814c
https://github.com/vimeo/psalm/blob/dd409871876fcafb4a85ac3901453fb05c46814c/src/Psalm/Internal/LanguageServer/Message.php#L30-L42
train
vimeo/psalm
src/Psalm/Internal/Visitor/SimpleNameResolver.php
SimpleNameResolver.resolveName
protected function resolveName(Name $name, $type) { $resolvedName = $this->nameContext->getResolvedName($name, $type); if (null !== $resolvedName) { $name->setAttribute('resolvedName', $resolvedName->toString()); } return $name; }
php
protected function resolveName(Name $name, $type) { $resolvedName = $this->nameContext->getResolvedName($name, $type); if (null !== $resolvedName) { $name->setAttribute('resolvedName', $resolvedName->toString()); } return $name; }
[ "protected", "function", "resolveName", "(", "Name", "$", "name", ",", "$", "type", ")", "{", "$", "resolvedName", "=", "$", "this", "->", "nameContext", "->", "getResolvedName", "(", "$", "name", ",", "$", "type", ")", ";", "if", "(", "null", "!==", "$", "resolvedName", ")", "{", "$", "name", "->", "setAttribute", "(", "'resolvedName'", ",", "$", "resolvedName", "->", "toString", "(", ")", ")", ";", "}", "return", "$", "name", ";", "}" ]
Resolve name, according to name resolver options. @param Name $name Function or constant name to resolve @param int $type One of Stmt\Use_::TYPE_* @return Name Resolved name, or original name with attribute
[ "Resolve", "name", "according", "to", "name", "resolver", "options", "." ]
dd409871876fcafb4a85ac3901453fb05c46814c
https://github.com/vimeo/psalm/blob/dd409871876fcafb4a85ac3901453fb05c46814c/src/Psalm/Internal/Visitor/SimpleNameResolver.php#L194-L200
train
vimeo/psalm
src/Psalm/Internal/Fork/Pool.php
Pool.streamForParent
private static function streamForParent(array $sockets) { list($for_read, $for_write) = $sockets; // The parent will not use the write channel, so it // must be closed to prevent deadlock. fclose($for_write); // stream_select will be used to read multiple streams, so these // must be set to non-blocking mode. if (!stream_set_blocking($for_read, false)) { error_log('unable to set read stream to non-blocking'); exit(self::EXIT_FAILURE); } return $for_read; }
php
private static function streamForParent(array $sockets) { list($for_read, $for_write) = $sockets; // The parent will not use the write channel, so it // must be closed to prevent deadlock. fclose($for_write); // stream_select will be used to read multiple streams, so these // must be set to non-blocking mode. if (!stream_set_blocking($for_read, false)) { error_log('unable to set read stream to non-blocking'); exit(self::EXIT_FAILURE); } return $for_read; }
[ "private", "static", "function", "streamForParent", "(", "array", "$", "sockets", ")", "{", "list", "(", "$", "for_read", ",", "$", "for_write", ")", "=", "$", "sockets", ";", "// The parent will not use the write channel, so it", "// must be closed to prevent deadlock.", "fclose", "(", "$", "for_write", ")", ";", "// stream_select will be used to read multiple streams, so these", "// must be set to non-blocking mode.", "if", "(", "!", "stream_set_blocking", "(", "$", "for_read", ",", "false", ")", ")", "{", "error_log", "(", "'unable to set read stream to non-blocking'", ")", ";", "exit", "(", "self", "::", "EXIT_FAILURE", ")", ";", "}", "return", "$", "for_read", ";", "}" ]
Prepare the socket pair to be used in a parent process and return the stream the parent will use to read results. @param resource[] $sockets the socket pair for IPC @return resource
[ "Prepare", "the", "socket", "pair", "to", "be", "used", "in", "a", "parent", "process", "and", "return", "the", "stream", "the", "parent", "will", "use", "to", "read", "results", "." ]
dd409871876fcafb4a85ac3901453fb05c46814c
https://github.com/vimeo/psalm/blob/dd409871876fcafb4a85ac3901453fb05c46814c/src/Psalm/Internal/Fork/Pool.php#L137-L153
train
vimeo/psalm
src/Psalm/Internal/Fork/Pool.php
Pool.readResultsFromChildren
private function readResultsFromChildren() { // Create an array of all active streams, indexed by // resource id. $streams = []; foreach ($this->read_streams as $stream) { $streams[intval($stream)] = $stream; } // Create an array for the content received on each stream, // indexed by resource id. $content = array_fill_keys(array_keys($streams), ''); // Read the data off of all the stream. while (count($streams) > 0) { $needs_read = array_values($streams); $needs_write = null; $needs_except = null; // Wait for data on at least one stream. $num = stream_select($needs_read, $needs_write, $needs_except, null /* no timeout */); if ($num === false) { error_log('unable to select on read stream'); exit(self::EXIT_FAILURE); } // For each stream that was ready, read the content. foreach ($needs_read as $file) { $buffer = fread($file, 1024); if ($buffer) { $content[intval($file)] .= $buffer; } // If the stream has closed, stop trying to select on it. if (feof($file)) { fclose($file); unset($streams[intval($file)]); } } } // Unmarshal the content into its original form. return array_values( array_map( /** * @param string $data * * @return array */ function ($data) { /** @var array */ $result = unserialize($data); /** @psalm-suppress DocblockTypeContradiction */ if (!\is_array($result)) { error_log( 'Child terminated without returning a serialized array - response type=' . gettype($result) ); $this->did_have_error = true; } return $result; }, $content ) ); }
php
private function readResultsFromChildren() { // Create an array of all active streams, indexed by // resource id. $streams = []; foreach ($this->read_streams as $stream) { $streams[intval($stream)] = $stream; } // Create an array for the content received on each stream, // indexed by resource id. $content = array_fill_keys(array_keys($streams), ''); // Read the data off of all the stream. while (count($streams) > 0) { $needs_read = array_values($streams); $needs_write = null; $needs_except = null; // Wait for data on at least one stream. $num = stream_select($needs_read, $needs_write, $needs_except, null /* no timeout */); if ($num === false) { error_log('unable to select on read stream'); exit(self::EXIT_FAILURE); } // For each stream that was ready, read the content. foreach ($needs_read as $file) { $buffer = fread($file, 1024); if ($buffer) { $content[intval($file)] .= $buffer; } // If the stream has closed, stop trying to select on it. if (feof($file)) { fclose($file); unset($streams[intval($file)]); } } } // Unmarshal the content into its original form. return array_values( array_map( /** * @param string $data * * @return array */ function ($data) { /** @var array */ $result = unserialize($data); /** @psalm-suppress DocblockTypeContradiction */ if (!\is_array($result)) { error_log( 'Child terminated without returning a serialized array - response type=' . gettype($result) ); $this->did_have_error = true; } return $result; }, $content ) ); }
[ "private", "function", "readResultsFromChildren", "(", ")", "{", "// Create an array of all active streams, indexed by", "// resource id.", "$", "streams", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "read_streams", "as", "$", "stream", ")", "{", "$", "streams", "[", "intval", "(", "$", "stream", ")", "]", "=", "$", "stream", ";", "}", "// Create an array for the content received on each stream,", "// indexed by resource id.", "$", "content", "=", "array_fill_keys", "(", "array_keys", "(", "$", "streams", ")", ",", "''", ")", ";", "// Read the data off of all the stream.", "while", "(", "count", "(", "$", "streams", ")", ">", "0", ")", "{", "$", "needs_read", "=", "array_values", "(", "$", "streams", ")", ";", "$", "needs_write", "=", "null", ";", "$", "needs_except", "=", "null", ";", "// Wait for data on at least one stream.", "$", "num", "=", "stream_select", "(", "$", "needs_read", ",", "$", "needs_write", ",", "$", "needs_except", ",", "null", "/* no timeout */", ")", ";", "if", "(", "$", "num", "===", "false", ")", "{", "error_log", "(", "'unable to select on read stream'", ")", ";", "exit", "(", "self", "::", "EXIT_FAILURE", ")", ";", "}", "// For each stream that was ready, read the content.", "foreach", "(", "$", "needs_read", "as", "$", "file", ")", "{", "$", "buffer", "=", "fread", "(", "$", "file", ",", "1024", ")", ";", "if", "(", "$", "buffer", ")", "{", "$", "content", "[", "intval", "(", "$", "file", ")", "]", ".=", "$", "buffer", ";", "}", "// If the stream has closed, stop trying to select on it.", "if", "(", "feof", "(", "$", "file", ")", ")", "{", "fclose", "(", "$", "file", ")", ";", "unset", "(", "$", "streams", "[", "intval", "(", "$", "file", ")", "]", ")", ";", "}", "}", "}", "// Unmarshal the content into its original form.", "return", "array_values", "(", "array_map", "(", "/**\n * @param string $data\n *\n * @return array\n */", "function", "(", "$", "data", ")", "{", "/** @var array */", "$", "result", "=", "unserialize", "(", "$", "data", ")", ";", "/** @psalm-suppress DocblockTypeContradiction */", "if", "(", "!", "\\", "is_array", "(", "$", "result", ")", ")", "{", "error_log", "(", "'Child terminated without returning a serialized array - response type='", ".", "gettype", "(", "$", "result", ")", ")", ";", "$", "this", "->", "did_have_error", "=", "true", ";", "}", "return", "$", "result", ";", "}", ",", "$", "content", ")", ")", ";", "}" ]
Read the results that each child process has serialized on their write streams. The results are returned in an array, one for each worker. The order of the results is not maintained. @return array @psalm-suppress MixedAssignment @psalm-suppress MixedOperand
[ "Read", "the", "results", "that", "each", "child", "process", "has", "serialized", "on", "their", "write", "streams", ".", "The", "results", "are", "returned", "in", "an", "array", "one", "for", "each", "worker", ".", "The", "order", "of", "the", "results", "is", "not", "maintained", "." ]
dd409871876fcafb4a85ac3901453fb05c46814c
https://github.com/vimeo/psalm/blob/dd409871876fcafb4a85ac3901453fb05c46814c/src/Psalm/Internal/Fork/Pool.php#L184-L249
train
vimeo/psalm
src/Psalm/Internal/Fork/Pool.php
Pool.wait
public function wait(): array { // Read all the streams from child processes into an array. $content = $this->readResultsFromChildren(); // Wait for all children to return foreach ($this->child_pid_list as $child_pid) { $process_lookup = posix_kill($child_pid, 0); $status = 0; if ($process_lookup) { /** * @psalm-suppress UndefinedConstant - does not exist on windows * @psalm-suppress MixedArgument */ posix_kill($child_pid, SIGALRM); if (pcntl_waitpid($child_pid, $status) < 0) { error_log(posix_strerror(posix_get_last_error())); } } // Check to see if the child died a graceful death if (pcntl_wifsignaled($status)) { $return_code = pcntl_wexitstatus($status); $term_sig = pcntl_wtermsig($status); /** * @psalm-suppress UndefinedConstant - does not exist on windows */ if ($term_sig !== SIGALRM) { $this->did_have_error = true; error_log("Child terminated with return code $return_code and signal $term_sig"); } } } return $content; }
php
public function wait(): array { // Read all the streams from child processes into an array. $content = $this->readResultsFromChildren(); // Wait for all children to return foreach ($this->child_pid_list as $child_pid) { $process_lookup = posix_kill($child_pid, 0); $status = 0; if ($process_lookup) { /** * @psalm-suppress UndefinedConstant - does not exist on windows * @psalm-suppress MixedArgument */ posix_kill($child_pid, SIGALRM); if (pcntl_waitpid($child_pid, $status) < 0) { error_log(posix_strerror(posix_get_last_error())); } } // Check to see if the child died a graceful death if (pcntl_wifsignaled($status)) { $return_code = pcntl_wexitstatus($status); $term_sig = pcntl_wtermsig($status); /** * @psalm-suppress UndefinedConstant - does not exist on windows */ if ($term_sig !== SIGALRM) { $this->did_have_error = true; error_log("Child terminated with return code $return_code and signal $term_sig"); } } } return $content; }
[ "public", "function", "wait", "(", ")", ":", "array", "{", "// Read all the streams from child processes into an array.", "$", "content", "=", "$", "this", "->", "readResultsFromChildren", "(", ")", ";", "// Wait for all children to return", "foreach", "(", "$", "this", "->", "child_pid_list", "as", "$", "child_pid", ")", "{", "$", "process_lookup", "=", "posix_kill", "(", "$", "child_pid", ",", "0", ")", ";", "$", "status", "=", "0", ";", "if", "(", "$", "process_lookup", ")", "{", "/**\n * @psalm-suppress UndefinedConstant - does not exist on windows\n * @psalm-suppress MixedArgument\n */", "posix_kill", "(", "$", "child_pid", ",", "SIGALRM", ")", ";", "if", "(", "pcntl_waitpid", "(", "$", "child_pid", ",", "$", "status", ")", "<", "0", ")", "{", "error_log", "(", "posix_strerror", "(", "posix_get_last_error", "(", ")", ")", ")", ";", "}", "}", "// Check to see if the child died a graceful death", "if", "(", "pcntl_wifsignaled", "(", "$", "status", ")", ")", "{", "$", "return_code", "=", "pcntl_wexitstatus", "(", "$", "status", ")", ";", "$", "term_sig", "=", "pcntl_wtermsig", "(", "$", "status", ")", ";", "/**\n * @psalm-suppress UndefinedConstant - does not exist on windows\n */", "if", "(", "$", "term_sig", "!==", "SIGALRM", ")", "{", "$", "this", "->", "did_have_error", "=", "true", ";", "error_log", "(", "\"Child terminated with return code $return_code and signal $term_sig\"", ")", ";", "}", "}", "}", "return", "$", "content", ";", "}" ]
Wait for all child processes to complete @return array
[ "Wait", "for", "all", "child", "processes", "to", "complete" ]
dd409871876fcafb4a85ac3901453fb05c46814c
https://github.com/vimeo/psalm/blob/dd409871876fcafb4a85ac3901453fb05c46814c/src/Psalm/Internal/Fork/Pool.php#L256-L295
train
vimeo/psalm
src/Psalm/Internal/Traverser/CustomTraverser.php
CustomTraverser.traverseNode
protected function traverseNode(Node $node) : Node { foreach ($node->getSubNodeNames() as $name) { $subNode =& $node->$name; if (\is_array($subNode)) { $subNode = $this->traverseArray($subNode); if ($this->stopTraversal) { break; } } elseif ($subNode instanceof Node) { $traverseChildren = true; foreach ($this->visitors as $visitor) { $return = $visitor->enterNode($subNode, $traverseChildren); if (null !== $return) { if ($return instanceof Node) { $subNode = $return; } elseif (self::DONT_TRAVERSE_CHILDREN === $return) { $traverseChildren = false; } elseif (self::STOP_TRAVERSAL === $return) { $this->stopTraversal = true; break 2; } else { throw new \LogicException( 'enterNode() returned invalid value of type ' . gettype($return) ); } } } if ($traverseChildren) { $subNode = $this->traverseNode($subNode); if ($this->stopTraversal) { break; } } foreach ($this->visitors as $visitor) { $return = $visitor->leaveNode($subNode); if (null !== $return) { if ($return instanceof Node) { $subNode = $return; } elseif (self::STOP_TRAVERSAL === $return) { $this->stopTraversal = true; break 2; } elseif (\is_array($return)) { throw new \LogicException( 'leaveNode() may only return an array ' . 'if the parent structure is an array' ); } else { throw new \LogicException( 'leaveNode() returned invalid value of type ' . gettype($return) ); } } } } } return $node; }
php
protected function traverseNode(Node $node) : Node { foreach ($node->getSubNodeNames() as $name) { $subNode =& $node->$name; if (\is_array($subNode)) { $subNode = $this->traverseArray($subNode); if ($this->stopTraversal) { break; } } elseif ($subNode instanceof Node) { $traverseChildren = true; foreach ($this->visitors as $visitor) { $return = $visitor->enterNode($subNode, $traverseChildren); if (null !== $return) { if ($return instanceof Node) { $subNode = $return; } elseif (self::DONT_TRAVERSE_CHILDREN === $return) { $traverseChildren = false; } elseif (self::STOP_TRAVERSAL === $return) { $this->stopTraversal = true; break 2; } else { throw new \LogicException( 'enterNode() returned invalid value of type ' . gettype($return) ); } } } if ($traverseChildren) { $subNode = $this->traverseNode($subNode); if ($this->stopTraversal) { break; } } foreach ($this->visitors as $visitor) { $return = $visitor->leaveNode($subNode); if (null !== $return) { if ($return instanceof Node) { $subNode = $return; } elseif (self::STOP_TRAVERSAL === $return) { $this->stopTraversal = true; break 2; } elseif (\is_array($return)) { throw new \LogicException( 'leaveNode() may only return an array ' . 'if the parent structure is an array' ); } else { throw new \LogicException( 'leaveNode() returned invalid value of type ' . gettype($return) ); } } } } } return $node; }
[ "protected", "function", "traverseNode", "(", "Node", "$", "node", ")", ":", "Node", "{", "foreach", "(", "$", "node", "->", "getSubNodeNames", "(", ")", "as", "$", "name", ")", "{", "$", "subNode", "=", "&", "$", "node", "->", "$", "name", ";", "if", "(", "\\", "is_array", "(", "$", "subNode", ")", ")", "{", "$", "subNode", "=", "$", "this", "->", "traverseArray", "(", "$", "subNode", ")", ";", "if", "(", "$", "this", "->", "stopTraversal", ")", "{", "break", ";", "}", "}", "elseif", "(", "$", "subNode", "instanceof", "Node", ")", "{", "$", "traverseChildren", "=", "true", ";", "foreach", "(", "$", "this", "->", "visitors", "as", "$", "visitor", ")", "{", "$", "return", "=", "$", "visitor", "->", "enterNode", "(", "$", "subNode", ",", "$", "traverseChildren", ")", ";", "if", "(", "null", "!==", "$", "return", ")", "{", "if", "(", "$", "return", "instanceof", "Node", ")", "{", "$", "subNode", "=", "$", "return", ";", "}", "elseif", "(", "self", "::", "DONT_TRAVERSE_CHILDREN", "===", "$", "return", ")", "{", "$", "traverseChildren", "=", "false", ";", "}", "elseif", "(", "self", "::", "STOP_TRAVERSAL", "===", "$", "return", ")", "{", "$", "this", "->", "stopTraversal", "=", "true", ";", "break", "2", ";", "}", "else", "{", "throw", "new", "\\", "LogicException", "(", "'enterNode() returned invalid value of type '", ".", "gettype", "(", "$", "return", ")", ")", ";", "}", "}", "}", "if", "(", "$", "traverseChildren", ")", "{", "$", "subNode", "=", "$", "this", "->", "traverseNode", "(", "$", "subNode", ")", ";", "if", "(", "$", "this", "->", "stopTraversal", ")", "{", "break", ";", "}", "}", "foreach", "(", "$", "this", "->", "visitors", "as", "$", "visitor", ")", "{", "$", "return", "=", "$", "visitor", "->", "leaveNode", "(", "$", "subNode", ")", ";", "if", "(", "null", "!==", "$", "return", ")", "{", "if", "(", "$", "return", "instanceof", "Node", ")", "{", "$", "subNode", "=", "$", "return", ";", "}", "elseif", "(", "self", "::", "STOP_TRAVERSAL", "===", "$", "return", ")", "{", "$", "this", "->", "stopTraversal", "=", "true", ";", "break", "2", ";", "}", "elseif", "(", "\\", "is_array", "(", "$", "return", ")", ")", "{", "throw", "new", "\\", "LogicException", "(", "'leaveNode() may only return an array '", ".", "'if the parent structure is an array'", ")", ";", "}", "else", "{", "throw", "new", "\\", "LogicException", "(", "'leaveNode() returned invalid value of type '", ".", "gettype", "(", "$", "return", ")", ")", ";", "}", "}", "}", "}", "}", "return", "$", "node", ";", "}" ]
Recursively traverse a node. @param Node $node Node to traverse. @return Node Result of traversal (may be original node or new one)
[ "Recursively", "traverse", "a", "node", "." ]
dd409871876fcafb4a85ac3901453fb05c46814c
https://github.com/vimeo/psalm/blob/dd409871876fcafb4a85ac3901453fb05c46814c/src/Psalm/Internal/Traverser/CustomTraverser.php#L25-L86
train
vimeo/psalm
src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php
ClassLikeAnalyzer.getFQCLNFromNameObject
public static function getFQCLNFromNameObject( PhpParser\Node\Name $class_name, Aliases $aliases ) { /** @var string|null */ $resolved_name = $class_name->getAttribute('resolvedName'); if ($resolved_name) { return $resolved_name; } if ($class_name instanceof PhpParser\Node\Name\FullyQualified) { return implode('\\', $class_name->parts); } if (in_array($class_name->parts[0], ['self', 'static', 'parent'], true)) { return $class_name->parts[0]; } return Type::getFQCLNFromString( implode('\\', $class_name->parts), $aliases ); }
php
public static function getFQCLNFromNameObject( PhpParser\Node\Name $class_name, Aliases $aliases ) { /** @var string|null */ $resolved_name = $class_name->getAttribute('resolvedName'); if ($resolved_name) { return $resolved_name; } if ($class_name instanceof PhpParser\Node\Name\FullyQualified) { return implode('\\', $class_name->parts); } if (in_array($class_name->parts[0], ['self', 'static', 'parent'], true)) { return $class_name->parts[0]; } return Type::getFQCLNFromString( implode('\\', $class_name->parts), $aliases ); }
[ "public", "static", "function", "getFQCLNFromNameObject", "(", "PhpParser", "\\", "Node", "\\", "Name", "$", "class_name", ",", "Aliases", "$", "aliases", ")", "{", "/** @var string|null */", "$", "resolved_name", "=", "$", "class_name", "->", "getAttribute", "(", "'resolvedName'", ")", ";", "if", "(", "$", "resolved_name", ")", "{", "return", "$", "resolved_name", ";", "}", "if", "(", "$", "class_name", "instanceof", "PhpParser", "\\", "Node", "\\", "Name", "\\", "FullyQualified", ")", "{", "return", "implode", "(", "'\\\\'", ",", "$", "class_name", "->", "parts", ")", ";", "}", "if", "(", "in_array", "(", "$", "class_name", "->", "parts", "[", "0", "]", ",", "[", "'self'", ",", "'static'", ",", "'parent'", "]", ",", "true", ")", ")", "{", "return", "$", "class_name", "->", "parts", "[", "0", "]", ";", "}", "return", "Type", "::", "getFQCLNFromString", "(", "implode", "(", "'\\\\'", ",", "$", "class_name", "->", "parts", ")", ",", "$", "aliases", ")", ";", "}" ]
Gets the fully-qualified class name from a Name object @param PhpParser\Node\Name $class_name @param Aliases $aliases @return string
[ "Gets", "the", "fully", "-", "qualified", "class", "name", "from", "a", "Name", "object" ]
dd409871876fcafb4a85ac3901453fb05c46814c
https://github.com/vimeo/psalm/blob/dd409871876fcafb4a85ac3901453fb05c46814c/src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php#L356-L379
train
vimeo/psalm
src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php
ClassLikeAnalyzer.getTypeFromValue
public static function getTypeFromValue($value) { switch (gettype($value)) { case 'boolean': if ($value) { return Type::getTrue(); } return Type::getFalse(); case 'integer': return Type::getInt(false, $value); case 'double': return Type::getFloat($value); case 'string': return Type::getString($value); case 'array': return Type::getArray(); case 'NULL': return Type::getNull(); default: return Type::getMixed(); } }
php
public static function getTypeFromValue($value) { switch (gettype($value)) { case 'boolean': if ($value) { return Type::getTrue(); } return Type::getFalse(); case 'integer': return Type::getInt(false, $value); case 'double': return Type::getFloat($value); case 'string': return Type::getString($value); case 'array': return Type::getArray(); case 'NULL': return Type::getNull(); default: return Type::getMixed(); } }
[ "public", "static", "function", "getTypeFromValue", "(", "$", "value", ")", "{", "switch", "(", "gettype", "(", "$", "value", ")", ")", "{", "case", "'boolean'", ":", "if", "(", "$", "value", ")", "{", "return", "Type", "::", "getTrue", "(", ")", ";", "}", "return", "Type", "::", "getFalse", "(", ")", ";", "case", "'integer'", ":", "return", "Type", "::", "getInt", "(", "false", ",", "$", "value", ")", ";", "case", "'double'", ":", "return", "Type", "::", "getFloat", "(", "$", "value", ")", ";", "case", "'string'", ":", "return", "Type", "::", "getString", "(", "$", "value", ")", ";", "case", "'array'", ":", "return", "Type", "::", "getArray", "(", ")", ";", "case", "'NULL'", ":", "return", "Type", "::", "getNull", "(", ")", ";", "default", ":", "return", "Type", "::", "getMixed", "(", ")", ";", "}", "}" ]
Gets the Psalm type from a particular value @param mixed $value @return Type\Union
[ "Gets", "the", "Psalm", "type", "from", "a", "particular", "value" ]
dd409871876fcafb4a85ac3901453fb05c46814c
https://github.com/vimeo/psalm/blob/dd409871876fcafb4a85ac3901453fb05c46814c/src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php#L440-L468
train
vimeo/psalm
examples/plugins/composer-based/echo-checker/EchoChecker.php
EchoChecker.afterStatementAnalysis
public static function afterStatementAnalysis( PhpParser\Node\Stmt $stmt, Context $context, StatementsSource $statements_source, Codebase $codebase, array &$file_replacements = [] ) { if ($stmt instanceof PhpParser\Node\Stmt\Echo_) { foreach ($stmt->exprs as $expr) { if (!isset($expr->inferredType) || $expr->inferredType->hasMixed()) { if (IssueBuffer::accepts( new ArgumentTypeCoercion( 'Echo requires an unescaped string, ' . $expr->inferredType . ' provided', new CodeLocation($statements_source, $expr), 'echo' ), $statements_source->getSuppressedIssues() )) { // keep soldiering on } continue; } $types = $expr->inferredType->getTypes(); foreach ($types as $type) { if ($type instanceof \Psalm\Type\Atomic\TString && !$type instanceof \Psalm\Type\Atomic\TLiteralString && !$type instanceof \Psalm\Type\Atomic\THtmlEscapedString ) { if (IssueBuffer::accepts( new ArgumentTypeCoercion( 'Echo requires an unescaped string, ' . $expr->inferredType . ' provided', new CodeLocation($statements_source, $expr), 'echo' ), $statements_source->getSuppressedIssues() )) { // keep soldiering on } } } } } }
php
public static function afterStatementAnalysis( PhpParser\Node\Stmt $stmt, Context $context, StatementsSource $statements_source, Codebase $codebase, array &$file_replacements = [] ) { if ($stmt instanceof PhpParser\Node\Stmt\Echo_) { foreach ($stmt->exprs as $expr) { if (!isset($expr->inferredType) || $expr->inferredType->hasMixed()) { if (IssueBuffer::accepts( new ArgumentTypeCoercion( 'Echo requires an unescaped string, ' . $expr->inferredType . ' provided', new CodeLocation($statements_source, $expr), 'echo' ), $statements_source->getSuppressedIssues() )) { // keep soldiering on } continue; } $types = $expr->inferredType->getTypes(); foreach ($types as $type) { if ($type instanceof \Psalm\Type\Atomic\TString && !$type instanceof \Psalm\Type\Atomic\TLiteralString && !$type instanceof \Psalm\Type\Atomic\THtmlEscapedString ) { if (IssueBuffer::accepts( new ArgumentTypeCoercion( 'Echo requires an unescaped string, ' . $expr->inferredType . ' provided', new CodeLocation($statements_source, $expr), 'echo' ), $statements_source->getSuppressedIssues() )) { // keep soldiering on } } } } } }
[ "public", "static", "function", "afterStatementAnalysis", "(", "PhpParser", "\\", "Node", "\\", "Stmt", "$", "stmt", ",", "Context", "$", "context", ",", "StatementsSource", "$", "statements_source", ",", "Codebase", "$", "codebase", ",", "array", "&", "$", "file_replacements", "=", "[", "]", ")", "{", "if", "(", "$", "stmt", "instanceof", "PhpParser", "\\", "Node", "\\", "Stmt", "\\", "Echo_", ")", "{", "foreach", "(", "$", "stmt", "->", "exprs", "as", "$", "expr", ")", "{", "if", "(", "!", "isset", "(", "$", "expr", "->", "inferredType", ")", "||", "$", "expr", "->", "inferredType", "->", "hasMixed", "(", ")", ")", "{", "if", "(", "IssueBuffer", "::", "accepts", "(", "new", "ArgumentTypeCoercion", "(", "'Echo requires an unescaped string, '", ".", "$", "expr", "->", "inferredType", ".", "' provided'", ",", "new", "CodeLocation", "(", "$", "statements_source", ",", "$", "expr", ")", ",", "'echo'", ")", ",", "$", "statements_source", "->", "getSuppressedIssues", "(", ")", ")", ")", "{", "// keep soldiering on", "}", "continue", ";", "}", "$", "types", "=", "$", "expr", "->", "inferredType", "->", "getTypes", "(", ")", ";", "foreach", "(", "$", "types", "as", "$", "type", ")", "{", "if", "(", "$", "type", "instanceof", "\\", "Psalm", "\\", "Type", "\\", "Atomic", "\\", "TString", "&&", "!", "$", "type", "instanceof", "\\", "Psalm", "\\", "Type", "\\", "Atomic", "\\", "TLiteralString", "&&", "!", "$", "type", "instanceof", "\\", "Psalm", "\\", "Type", "\\", "Atomic", "\\", "THtmlEscapedString", ")", "{", "if", "(", "IssueBuffer", "::", "accepts", "(", "new", "ArgumentTypeCoercion", "(", "'Echo requires an unescaped string, '", ".", "$", "expr", "->", "inferredType", ".", "' provided'", ",", "new", "CodeLocation", "(", "$", "statements_source", ",", "$", "expr", ")", ",", "'echo'", ")", ",", "$", "statements_source", "->", "getSuppressedIssues", "(", ")", ")", ")", "{", "// keep soldiering on", "}", "}", "}", "}", "}", "}" ]
Called after a statement has been checked @param FileManipulation[] $file_replacements @return null|false
[ "Called", "after", "a", "statement", "has", "been", "checked" ]
dd409871876fcafb4a85ac3901453fb05c46814c
https://github.com/vimeo/psalm/blob/dd409871876fcafb4a85ac3901453fb05c46814c/examples/plugins/composer-based/echo-checker/EchoChecker.php#L23-L68
train
vimeo/psalm
src/Psalm/Internal/Codebase/Scanner.php
Scanner.fileExistsForClassLike
private function fileExistsForClassLike(ClassLikes $classlikes, $fq_class_name) { $fq_class_name_lc = strtolower($fq_class_name); if (isset($this->classlike_files[$fq_class_name_lc])) { return true; } if ($fq_class_name === 'self') { return false; } if (isset($this->existing_classlikes_lc[$fq_class_name_lc])) { throw new \InvalidArgumentException('Why are you asking about a builtin class?'); } $composer_file_path = $this->config->getComposerFilePathForClassLike($fq_class_name); if ($composer_file_path && file_exists($composer_file_path)) { if ($this->debug_output) { echo 'Using composer to locate file for ' . $fq_class_name . "\n"; } $classlikes->addFullyQualifiedClassLikeName( $fq_class_name_lc, realpath($composer_file_path) ); return true; } $old_level = error_reporting(); if (!$this->debug_output) { error_reporting(E_ERROR); } try { if ($this->debug_output) { echo 'Using reflection to locate file for ' . $fq_class_name . "\n"; } /** @psalm-suppress TypeCoercion */ $reflected_class = new \ReflectionClass($fq_class_name); } catch (\Throwable $e) { error_reporting($old_level); // do not cache any results here (as case-sensitive filenames can screw things up) return false; } error_reporting($old_level); /** @psalm-suppress MixedMethodCall due to Reflection class weirdness */ $file_path = (string)$reflected_class->getFileName(); // if the file was autoloaded but exists in evaled code only, return false if (!file_exists($file_path)) { return false; } $new_fq_class_name = $reflected_class->getName(); if (strtolower($new_fq_class_name) !== strtolower($fq_class_name)) { $classlikes->addClassAlias($new_fq_class_name, strtolower($fq_class_name)); $fq_class_name_lc = strtolower($new_fq_class_name); } $fq_class_name = $new_fq_class_name; $classlikes->addFullyQualifiedClassLikeName($fq_class_name_lc); if ($reflected_class->isInterface()) { $classlikes->addFullyQualifiedInterfaceName($fq_class_name, $file_path); } elseif ($reflected_class->isTrait()) { $classlikes->addFullyQualifiedTraitName($fq_class_name, $file_path); } else { $classlikes->addFullyQualifiedClassName($fq_class_name, $file_path); } return true; }
php
private function fileExistsForClassLike(ClassLikes $classlikes, $fq_class_name) { $fq_class_name_lc = strtolower($fq_class_name); if (isset($this->classlike_files[$fq_class_name_lc])) { return true; } if ($fq_class_name === 'self') { return false; } if (isset($this->existing_classlikes_lc[$fq_class_name_lc])) { throw new \InvalidArgumentException('Why are you asking about a builtin class?'); } $composer_file_path = $this->config->getComposerFilePathForClassLike($fq_class_name); if ($composer_file_path && file_exists($composer_file_path)) { if ($this->debug_output) { echo 'Using composer to locate file for ' . $fq_class_name . "\n"; } $classlikes->addFullyQualifiedClassLikeName( $fq_class_name_lc, realpath($composer_file_path) ); return true; } $old_level = error_reporting(); if (!$this->debug_output) { error_reporting(E_ERROR); } try { if ($this->debug_output) { echo 'Using reflection to locate file for ' . $fq_class_name . "\n"; } /** @psalm-suppress TypeCoercion */ $reflected_class = new \ReflectionClass($fq_class_name); } catch (\Throwable $e) { error_reporting($old_level); // do not cache any results here (as case-sensitive filenames can screw things up) return false; } error_reporting($old_level); /** @psalm-suppress MixedMethodCall due to Reflection class weirdness */ $file_path = (string)$reflected_class->getFileName(); // if the file was autoloaded but exists in evaled code only, return false if (!file_exists($file_path)) { return false; } $new_fq_class_name = $reflected_class->getName(); if (strtolower($new_fq_class_name) !== strtolower($fq_class_name)) { $classlikes->addClassAlias($new_fq_class_name, strtolower($fq_class_name)); $fq_class_name_lc = strtolower($new_fq_class_name); } $fq_class_name = $new_fq_class_name; $classlikes->addFullyQualifiedClassLikeName($fq_class_name_lc); if ($reflected_class->isInterface()) { $classlikes->addFullyQualifiedInterfaceName($fq_class_name, $file_path); } elseif ($reflected_class->isTrait()) { $classlikes->addFullyQualifiedTraitName($fq_class_name, $file_path); } else { $classlikes->addFullyQualifiedClassName($fq_class_name, $file_path); } return true; }
[ "private", "function", "fileExistsForClassLike", "(", "ClassLikes", "$", "classlikes", ",", "$", "fq_class_name", ")", "{", "$", "fq_class_name_lc", "=", "strtolower", "(", "$", "fq_class_name", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "classlike_files", "[", "$", "fq_class_name_lc", "]", ")", ")", "{", "return", "true", ";", "}", "if", "(", "$", "fq_class_name", "===", "'self'", ")", "{", "return", "false", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "existing_classlikes_lc", "[", "$", "fq_class_name_lc", "]", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Why are you asking about a builtin class?'", ")", ";", "}", "$", "composer_file_path", "=", "$", "this", "->", "config", "->", "getComposerFilePathForClassLike", "(", "$", "fq_class_name", ")", ";", "if", "(", "$", "composer_file_path", "&&", "file_exists", "(", "$", "composer_file_path", ")", ")", "{", "if", "(", "$", "this", "->", "debug_output", ")", "{", "echo", "'Using composer to locate file for '", ".", "$", "fq_class_name", ".", "\"\\n\"", ";", "}", "$", "classlikes", "->", "addFullyQualifiedClassLikeName", "(", "$", "fq_class_name_lc", ",", "realpath", "(", "$", "composer_file_path", ")", ")", ";", "return", "true", ";", "}", "$", "old_level", "=", "error_reporting", "(", ")", ";", "if", "(", "!", "$", "this", "->", "debug_output", ")", "{", "error_reporting", "(", "E_ERROR", ")", ";", "}", "try", "{", "if", "(", "$", "this", "->", "debug_output", ")", "{", "echo", "'Using reflection to locate file for '", ".", "$", "fq_class_name", ".", "\"\\n\"", ";", "}", "/** @psalm-suppress TypeCoercion */", "$", "reflected_class", "=", "new", "\\", "ReflectionClass", "(", "$", "fq_class_name", ")", ";", "}", "catch", "(", "\\", "Throwable", "$", "e", ")", "{", "error_reporting", "(", "$", "old_level", ")", ";", "// do not cache any results here (as case-sensitive filenames can screw things up)", "return", "false", ";", "}", "error_reporting", "(", "$", "old_level", ")", ";", "/** @psalm-suppress MixedMethodCall due to Reflection class weirdness */", "$", "file_path", "=", "(", "string", ")", "$", "reflected_class", "->", "getFileName", "(", ")", ";", "// if the file was autoloaded but exists in evaled code only, return false", "if", "(", "!", "file_exists", "(", "$", "file_path", ")", ")", "{", "return", "false", ";", "}", "$", "new_fq_class_name", "=", "$", "reflected_class", "->", "getName", "(", ")", ";", "if", "(", "strtolower", "(", "$", "new_fq_class_name", ")", "!==", "strtolower", "(", "$", "fq_class_name", ")", ")", "{", "$", "classlikes", "->", "addClassAlias", "(", "$", "new_fq_class_name", ",", "strtolower", "(", "$", "fq_class_name", ")", ")", ";", "$", "fq_class_name_lc", "=", "strtolower", "(", "$", "new_fq_class_name", ")", ";", "}", "$", "fq_class_name", "=", "$", "new_fq_class_name", ";", "$", "classlikes", "->", "addFullyQualifiedClassLikeName", "(", "$", "fq_class_name_lc", ")", ";", "if", "(", "$", "reflected_class", "->", "isInterface", "(", ")", ")", "{", "$", "classlikes", "->", "addFullyQualifiedInterfaceName", "(", "$", "fq_class_name", ",", "$", "file_path", ")", ";", "}", "elseif", "(", "$", "reflected_class", "->", "isTrait", "(", ")", ")", "{", "$", "classlikes", "->", "addFullyQualifiedTraitName", "(", "$", "fq_class_name", ",", "$", "file_path", ")", ";", "}", "else", "{", "$", "classlikes", "->", "addFullyQualifiedClassName", "(", "$", "fq_class_name", ",", "$", "file_path", ")", ";", "}", "return", "true", ";", "}" ]
Checks whether a class exists, and if it does then records what file it's in for later checking @param string $fq_class_name @return bool
[ "Checks", "whether", "a", "class", "exists", "and", "if", "it", "does", "then", "records", "what", "file", "it", "s", "in", "for", "later", "checking" ]
dd409871876fcafb4a85ac3901453fb05c46814c
https://github.com/vimeo/psalm/blob/dd409871876fcafb4a85ac3901453fb05c46814c/src/Psalm/Internal/Codebase/Scanner.php#L677-L758
train
vimeo/psalm
src/Psalm/Internal/Analyzer/TypeAnalyzer.php
TypeAnalyzer.isContainedByInPhp
public static function isContainedByInPhp( Type\Union $input_type = null, Type\Union $container_type ) { if (!$input_type) { return false; } if ($input_type->getId() === $container_type->getId()) { return true; } if ($input_type->isNullable() && !$container_type->isNullable()) { return false; } $input_type_not_null = clone $input_type; $input_type_not_null->removeType('null'); $container_type_not_null = clone $container_type; $container_type_not_null->removeType('null'); if ($input_type_not_null->getId() === $container_type_not_null->getId()) { return true; } if ($input_type_not_null->hasArray() && $container_type_not_null->hasType('iterable')) { return true; } return false; }
php
public static function isContainedByInPhp( Type\Union $input_type = null, Type\Union $container_type ) { if (!$input_type) { return false; } if ($input_type->getId() === $container_type->getId()) { return true; } if ($input_type->isNullable() && !$container_type->isNullable()) { return false; } $input_type_not_null = clone $input_type; $input_type_not_null->removeType('null'); $container_type_not_null = clone $container_type; $container_type_not_null->removeType('null'); if ($input_type_not_null->getId() === $container_type_not_null->getId()) { return true; } if ($input_type_not_null->hasArray() && $container_type_not_null->hasType('iterable')) { return true; } return false; }
[ "public", "static", "function", "isContainedByInPhp", "(", "Type", "\\", "Union", "$", "input_type", "=", "null", ",", "Type", "\\", "Union", "$", "container_type", ")", "{", "if", "(", "!", "$", "input_type", ")", "{", "return", "false", ";", "}", "if", "(", "$", "input_type", "->", "getId", "(", ")", "===", "$", "container_type", "->", "getId", "(", ")", ")", "{", "return", "true", ";", "}", "if", "(", "$", "input_type", "->", "isNullable", "(", ")", "&&", "!", "$", "container_type", "->", "isNullable", "(", ")", ")", "{", "return", "false", ";", "}", "$", "input_type_not_null", "=", "clone", "$", "input_type", ";", "$", "input_type_not_null", "->", "removeType", "(", "'null'", ")", ";", "$", "container_type_not_null", "=", "clone", "$", "container_type", ";", "$", "container_type_not_null", "->", "removeType", "(", "'null'", ")", ";", "if", "(", "$", "input_type_not_null", "->", "getId", "(", ")", "===", "$", "container_type_not_null", "->", "getId", "(", ")", ")", "{", "return", "true", ";", "}", "if", "(", "$", "input_type_not_null", "->", "hasArray", "(", ")", "&&", "$", "container_type_not_null", "->", "hasType", "(", "'iterable'", ")", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Used for comparing signature typehints, uses PHP's light contravariance rules @param Type\Union $input_type @param Type\Union $container_type @return bool
[ "Used", "for", "comparing", "signature", "typehints", "uses", "PHP", "s", "light", "contravariance", "rules" ]
dd409871876fcafb4a85ac3901453fb05c46814c
https://github.com/vimeo/psalm/blob/dd409871876fcafb4a85ac3901453fb05c46814c/src/Psalm/Internal/Analyzer/TypeAnalyzer.php#L181-L212
train
vimeo/psalm
src/Psalm/Internal/Analyzer/TypeAnalyzer.php
TypeAnalyzer.isSimplyContainedBy
public static function isSimplyContainedBy( Type\Union $input_type, Type\Union $container_type ) { if ($input_type->getId() === $container_type->getId()) { return true; } if ($input_type->isNullable() && !$container_type->isNullable()) { return false; } $input_type_not_null = clone $input_type; $input_type_not_null->removeType('null'); $container_type_not_null = clone $container_type; $container_type_not_null->removeType('null'); return (bool) array_intersect_key( $input_type_not_null->getTypes(), $container_type_not_null->getTypes() ); }
php
public static function isSimplyContainedBy( Type\Union $input_type, Type\Union $container_type ) { if ($input_type->getId() === $container_type->getId()) { return true; } if ($input_type->isNullable() && !$container_type->isNullable()) { return false; } $input_type_not_null = clone $input_type; $input_type_not_null->removeType('null'); $container_type_not_null = clone $container_type; $container_type_not_null->removeType('null'); return (bool) array_intersect_key( $input_type_not_null->getTypes(), $container_type_not_null->getTypes() ); }
[ "public", "static", "function", "isSimplyContainedBy", "(", "Type", "\\", "Union", "$", "input_type", ",", "Type", "\\", "Union", "$", "container_type", ")", "{", "if", "(", "$", "input_type", "->", "getId", "(", ")", "===", "$", "container_type", "->", "getId", "(", ")", ")", "{", "return", "true", ";", "}", "if", "(", "$", "input_type", "->", "isNullable", "(", ")", "&&", "!", "$", "container_type", "->", "isNullable", "(", ")", ")", "{", "return", "false", ";", "}", "$", "input_type_not_null", "=", "clone", "$", "input_type", ";", "$", "input_type_not_null", "->", "removeType", "(", "'null'", ")", ";", "$", "container_type_not_null", "=", "clone", "$", "container_type", ";", "$", "container_type_not_null", "->", "removeType", "(", "'null'", ")", ";", "return", "(", "bool", ")", "array_intersect_key", "(", "$", "input_type_not_null", "->", "getTypes", "(", ")", ",", "$", "container_type_not_null", "->", "getTypes", "(", ")", ")", ";", "}" ]
Used for comparing docblock types to signature types before we know about all types @param Type\Union $input_type @param Type\Union $container_type @return bool
[ "Used", "for", "comparing", "docblock", "types", "to", "signature", "types", "before", "we", "know", "about", "all", "types" ]
dd409871876fcafb4a85ac3901453fb05c46814c
https://github.com/vimeo/psalm/blob/dd409871876fcafb4a85ac3901453fb05c46814c/src/Psalm/Internal/Analyzer/TypeAnalyzer.php#L222-L244
train
vimeo/psalm
src/Psalm/Internal/ExecutionEnvironment/BuildInfoCollector.php
BuildInfoCollector.fillJenkins
protected function fillJenkins() : self { if (isset($this->env['JENKINS_URL']) && isset($this->env['BUILD_NUMBER'])) { $this->readEnv['CI_BUILD_NUMBER'] = $this->env['BUILD_NUMBER']; $this->readEnv['CI_BUILD_URL'] = $this->env['JENKINS_URL']; $this->env['CI_NAME'] = 'jenkins'; // backup $this->readEnv['BUILD_NUMBER'] = $this->env['BUILD_NUMBER']; $this->readEnv['JENKINS_URL'] = $this->env['JENKINS_URL']; $this->readEnv['CI_NAME'] = $this->env['CI_NAME']; } return $this; }
php
protected function fillJenkins() : self { if (isset($this->env['JENKINS_URL']) && isset($this->env['BUILD_NUMBER'])) { $this->readEnv['CI_BUILD_NUMBER'] = $this->env['BUILD_NUMBER']; $this->readEnv['CI_BUILD_URL'] = $this->env['JENKINS_URL']; $this->env['CI_NAME'] = 'jenkins'; // backup $this->readEnv['BUILD_NUMBER'] = $this->env['BUILD_NUMBER']; $this->readEnv['JENKINS_URL'] = $this->env['JENKINS_URL']; $this->readEnv['CI_NAME'] = $this->env['CI_NAME']; } return $this; }
[ "protected", "function", "fillJenkins", "(", ")", ":", "self", "{", "if", "(", "isset", "(", "$", "this", "->", "env", "[", "'JENKINS_URL'", "]", ")", "&&", "isset", "(", "$", "this", "->", "env", "[", "'BUILD_NUMBER'", "]", ")", ")", "{", "$", "this", "->", "readEnv", "[", "'CI_BUILD_NUMBER'", "]", "=", "$", "this", "->", "env", "[", "'BUILD_NUMBER'", "]", ";", "$", "this", "->", "readEnv", "[", "'CI_BUILD_URL'", "]", "=", "$", "this", "->", "env", "[", "'JENKINS_URL'", "]", ";", "$", "this", "->", "env", "[", "'CI_NAME'", "]", "=", "'jenkins'", ";", "// backup", "$", "this", "->", "readEnv", "[", "'BUILD_NUMBER'", "]", "=", "$", "this", "->", "env", "[", "'BUILD_NUMBER'", "]", ";", "$", "this", "->", "readEnv", "[", "'JENKINS_URL'", "]", "=", "$", "this", "->", "env", "[", "'JENKINS_URL'", "]", ";", "$", "this", "->", "readEnv", "[", "'CI_NAME'", "]", "=", "$", "this", "->", "env", "[", "'CI_NAME'", "]", ";", "}", "return", "$", "this", ";", "}" ]
Fill Jenkins environment variables. "JENKINS_URL", "BUILD_NUMBER" must be set. @return $this
[ "Fill", "Jenkins", "environment", "variables", "." ]
dd409871876fcafb4a85ac3901453fb05c46814c
https://github.com/vimeo/psalm/blob/dd409871876fcafb4a85ac3901453fb05c46814c/src/Psalm/Internal/ExecutionEnvironment/BuildInfoCollector.php#L184-L198
train
vimeo/psalm
src/Psalm/Internal/ExecutionEnvironment/BuildInfoCollector.php
BuildInfoCollector.fillScrutinizer
protected function fillScrutinizer() : self { if (isset($this->env['SCRUTINIZER']) && $this->env['SCRUTINIZER']) { $this->readEnv['CI_JOB_ID'] = $this->env['SCRUTINIZER_INSPECTION_UUID']; $this->readEnv['CI_BRANCH'] = $this->env['SCRUTINIZER_BRANCH']; $this->readEnv['CI_PR_NUMBER'] = $this->env['SCRUTINIZER_PR_NUMBER'] ?? ''; // backup $this->readEnv['CI_NAME'] = 'Scrutinizer'; $repo_slug = (string) $this->env['SCRUTINIZER_PROJECT'] ?? ''; if ($repo_slug) { $slug_parts = explode('/', $repo_slug); if ($this->readEnv['CI_PR_NUMBER']) { $this->readEnv['CI_PR_REPO_OWNER'] = $slug_parts[1]; $this->readEnv['CI_PR_REPO_NAME'] = $slug_parts[2]; } else { $this->readEnv['CI_REPO_OWNER'] = $slug_parts[1]; $this->readEnv['CI_REPO_NAME'] = $slug_parts[2]; } } } return $this; }
php
protected function fillScrutinizer() : self { if (isset($this->env['SCRUTINIZER']) && $this->env['SCRUTINIZER']) { $this->readEnv['CI_JOB_ID'] = $this->env['SCRUTINIZER_INSPECTION_UUID']; $this->readEnv['CI_BRANCH'] = $this->env['SCRUTINIZER_BRANCH']; $this->readEnv['CI_PR_NUMBER'] = $this->env['SCRUTINIZER_PR_NUMBER'] ?? ''; // backup $this->readEnv['CI_NAME'] = 'Scrutinizer'; $repo_slug = (string) $this->env['SCRUTINIZER_PROJECT'] ?? ''; if ($repo_slug) { $slug_parts = explode('/', $repo_slug); if ($this->readEnv['CI_PR_NUMBER']) { $this->readEnv['CI_PR_REPO_OWNER'] = $slug_parts[1]; $this->readEnv['CI_PR_REPO_NAME'] = $slug_parts[2]; } else { $this->readEnv['CI_REPO_OWNER'] = $slug_parts[1]; $this->readEnv['CI_REPO_NAME'] = $slug_parts[2]; } } } return $this; }
[ "protected", "function", "fillScrutinizer", "(", ")", ":", "self", "{", "if", "(", "isset", "(", "$", "this", "->", "env", "[", "'SCRUTINIZER'", "]", ")", "&&", "$", "this", "->", "env", "[", "'SCRUTINIZER'", "]", ")", "{", "$", "this", "->", "readEnv", "[", "'CI_JOB_ID'", "]", "=", "$", "this", "->", "env", "[", "'SCRUTINIZER_INSPECTION_UUID'", "]", ";", "$", "this", "->", "readEnv", "[", "'CI_BRANCH'", "]", "=", "$", "this", "->", "env", "[", "'SCRUTINIZER_BRANCH'", "]", ";", "$", "this", "->", "readEnv", "[", "'CI_PR_NUMBER'", "]", "=", "$", "this", "->", "env", "[", "'SCRUTINIZER_PR_NUMBER'", "]", "??", "''", ";", "// backup", "$", "this", "->", "readEnv", "[", "'CI_NAME'", "]", "=", "'Scrutinizer'", ";", "$", "repo_slug", "=", "(", "string", ")", "$", "this", "->", "env", "[", "'SCRUTINIZER_PROJECT'", "]", "??", "''", ";", "if", "(", "$", "repo_slug", ")", "{", "$", "slug_parts", "=", "explode", "(", "'/'", ",", "$", "repo_slug", ")", ";", "if", "(", "$", "this", "->", "readEnv", "[", "'CI_PR_NUMBER'", "]", ")", "{", "$", "this", "->", "readEnv", "[", "'CI_PR_REPO_OWNER'", "]", "=", "$", "slug_parts", "[", "1", "]", ";", "$", "this", "->", "readEnv", "[", "'CI_PR_REPO_NAME'", "]", "=", "$", "slug_parts", "[", "2", "]", ";", "}", "else", "{", "$", "this", "->", "readEnv", "[", "'CI_REPO_OWNER'", "]", "=", "$", "slug_parts", "[", "1", "]", ";", "$", "this", "->", "readEnv", "[", "'CI_REPO_NAME'", "]", "=", "$", "slug_parts", "[", "2", "]", ";", "}", "}", "}", "return", "$", "this", ";", "}" ]
Fill Scrutinizer environment variables. "JENKINS_URL", "BUILD_NUMBER" must be set. @return $this
[ "Fill", "Scrutinizer", "environment", "variables", "." ]
dd409871876fcafb4a85ac3901453fb05c46814c
https://github.com/vimeo/psalm/blob/dd409871876fcafb4a85ac3901453fb05c46814c/src/Psalm/Internal/ExecutionEnvironment/BuildInfoCollector.php#L207-L233
train
vimeo/psalm
src/Psalm/Internal/Analyzer/MethodAnalyzer.php
MethodAnalyzer.checkStatic
public static function checkStatic( $method_id, $self_call, $is_context_dynamic, Codebase $codebase, CodeLocation $code_location, array $suppressed_issues, &$is_dynamic_this_method = false ) { $codebase_methods = $codebase->methods; if ($method_id === 'Closure::fromcallable') { return true; } $original_method_id = $method_id; $method_id = $codebase_methods->getDeclaringMethodId($method_id); if (!$method_id) { throw new \LogicException('Declaring method for ' . $original_method_id . ' should not be null'); } $storage = $codebase_methods->getStorage($method_id); if (!$storage->is_static) { if ($self_call) { if (!$is_context_dynamic) { if (IssueBuffer::accepts( new NonStaticSelfCall( 'Method ' . $codebase_methods->getCasedMethodId($method_id) . ' is not static, but is called ' . 'using self::', $code_location ), $suppressed_issues )) { return false; } } else { $is_dynamic_this_method = true; } } else { if (IssueBuffer::accepts( new InvalidStaticInvocation( 'Method ' . $codebase_methods->getCasedMethodId($method_id) . ' is not static, but is called ' . 'statically', $code_location ), $suppressed_issues )) { return false; } } } return true; }
php
public static function checkStatic( $method_id, $self_call, $is_context_dynamic, Codebase $codebase, CodeLocation $code_location, array $suppressed_issues, &$is_dynamic_this_method = false ) { $codebase_methods = $codebase->methods; if ($method_id === 'Closure::fromcallable') { return true; } $original_method_id = $method_id; $method_id = $codebase_methods->getDeclaringMethodId($method_id); if (!$method_id) { throw new \LogicException('Declaring method for ' . $original_method_id . ' should not be null'); } $storage = $codebase_methods->getStorage($method_id); if (!$storage->is_static) { if ($self_call) { if (!$is_context_dynamic) { if (IssueBuffer::accepts( new NonStaticSelfCall( 'Method ' . $codebase_methods->getCasedMethodId($method_id) . ' is not static, but is called ' . 'using self::', $code_location ), $suppressed_issues )) { return false; } } else { $is_dynamic_this_method = true; } } else { if (IssueBuffer::accepts( new InvalidStaticInvocation( 'Method ' . $codebase_methods->getCasedMethodId($method_id) . ' is not static, but is called ' . 'statically', $code_location ), $suppressed_issues )) { return false; } } } return true; }
[ "public", "static", "function", "checkStatic", "(", "$", "method_id", ",", "$", "self_call", ",", "$", "is_context_dynamic", ",", "Codebase", "$", "codebase", ",", "CodeLocation", "$", "code_location", ",", "array", "$", "suppressed_issues", ",", "&", "$", "is_dynamic_this_method", "=", "false", ")", "{", "$", "codebase_methods", "=", "$", "codebase", "->", "methods", ";", "if", "(", "$", "method_id", "===", "'Closure::fromcallable'", ")", "{", "return", "true", ";", "}", "$", "original_method_id", "=", "$", "method_id", ";", "$", "method_id", "=", "$", "codebase_methods", "->", "getDeclaringMethodId", "(", "$", "method_id", ")", ";", "if", "(", "!", "$", "method_id", ")", "{", "throw", "new", "\\", "LogicException", "(", "'Declaring method for '", ".", "$", "original_method_id", ".", "' should not be null'", ")", ";", "}", "$", "storage", "=", "$", "codebase_methods", "->", "getStorage", "(", "$", "method_id", ")", ";", "if", "(", "!", "$", "storage", "->", "is_static", ")", "{", "if", "(", "$", "self_call", ")", "{", "if", "(", "!", "$", "is_context_dynamic", ")", "{", "if", "(", "IssueBuffer", "::", "accepts", "(", "new", "NonStaticSelfCall", "(", "'Method '", ".", "$", "codebase_methods", "->", "getCasedMethodId", "(", "$", "method_id", ")", ".", "' is not static, but is called '", ".", "'using self::'", ",", "$", "code_location", ")", ",", "$", "suppressed_issues", ")", ")", "{", "return", "false", ";", "}", "}", "else", "{", "$", "is_dynamic_this_method", "=", "true", ";", "}", "}", "else", "{", "if", "(", "IssueBuffer", "::", "accepts", "(", "new", "InvalidStaticInvocation", "(", "'Method '", ".", "$", "codebase_methods", "->", "getCasedMethodId", "(", "$", "method_id", ")", ".", "' is not static, but is called '", ".", "'statically'", ",", "$", "code_location", ")", ",", "$", "suppressed_issues", ")", ")", "{", "return", "false", ";", "}", "}", "}", "return", "true", ";", "}" ]
Determines whether a given method is static or not @param string $method_id @param bool $self_call @param bool $is_context_dynamic @param CodeLocation $code_location @param array<string> $suppressed_issues @param bool $is_dynamic_this_method @return bool
[ "Determines", "whether", "a", "given", "method", "is", "static", "or", "not" ]
dd409871876fcafb4a85ac3901453fb05c46814c
https://github.com/vimeo/psalm/blob/dd409871876fcafb4a85ac3901453fb05c46814c/src/Psalm/Internal/Analyzer/MethodAnalyzer.php#L81-L139
train
vimeo/psalm
src/Psalm/Type/Algebra.php
Algebra.simplifyCNF
public static function simplifyCNF(array $clauses) { $cloned_clauses = []; // avoid strict duplicates foreach ($clauses as $clause) { $unique_clause = clone $clause; foreach ($unique_clause->possibilities as $var_id => $possibilities) { if (count($possibilities)) { $unique_clause->possibilities[$var_id] = array_unique($possibilities); } } $cloned_clauses[$clause->getHash()] = $unique_clause; } // remove impossible types foreach ($cloned_clauses as $clause_a) { if (count($clause_a->possibilities) !== 1 || count(array_values($clause_a->possibilities)[0]) !== 1) { continue; } if (!$clause_a->reconcilable || $clause_a->wedge) { continue; } $clause_var = array_keys($clause_a->possibilities)[0]; $only_type = array_pop(array_values($clause_a->possibilities)[0]); $negated_clause_type = self::negateType($only_type); foreach ($cloned_clauses as $clause_b) { if ($clause_a === $clause_b || !$clause_b->reconcilable || $clause_b->wedge) { continue; } if (isset($clause_b->possibilities[$clause_var]) && in_array($negated_clause_type, $clause_b->possibilities[$clause_var], true) ) { $clause_b->possibilities[$clause_var] = array_filter( $clause_b->possibilities[$clause_var], /** * @param string $possible_type * * @return bool */ function ($possible_type) use ($negated_clause_type) { return $possible_type !== $negated_clause_type; } ); if (count($clause_b->possibilities[$clause_var]) === 0) { unset($clause_b->possibilities[$clause_var]); $clause_b->impossibilities = null; } } } } $deduped_clauses = []; // avoid strict duplicates foreach ($cloned_clauses as $clause) { $deduped_clauses[$clause->getHash()] = clone $clause; } $deduped_clauses = array_filter( $deduped_clauses, /** * @return bool */ function (Clause $clause) { return count($clause->possibilities) || $clause->wedge; } ); $simplified_clauses = []; foreach ($deduped_clauses as $clause_a) { $is_redundant = false; foreach ($deduped_clauses as $clause_b) { if ($clause_a === $clause_b || !$clause_b->reconcilable || $clause_b->wedge || $clause_a->wedge ) { continue; } if ($clause_a->contains($clause_b)) { $is_redundant = true; break; } } if (!$is_redundant) { $simplified_clauses[] = $clause_a; } } return $simplified_clauses; }
php
public static function simplifyCNF(array $clauses) { $cloned_clauses = []; // avoid strict duplicates foreach ($clauses as $clause) { $unique_clause = clone $clause; foreach ($unique_clause->possibilities as $var_id => $possibilities) { if (count($possibilities)) { $unique_clause->possibilities[$var_id] = array_unique($possibilities); } } $cloned_clauses[$clause->getHash()] = $unique_clause; } // remove impossible types foreach ($cloned_clauses as $clause_a) { if (count($clause_a->possibilities) !== 1 || count(array_values($clause_a->possibilities)[0]) !== 1) { continue; } if (!$clause_a->reconcilable || $clause_a->wedge) { continue; } $clause_var = array_keys($clause_a->possibilities)[0]; $only_type = array_pop(array_values($clause_a->possibilities)[0]); $negated_clause_type = self::negateType($only_type); foreach ($cloned_clauses as $clause_b) { if ($clause_a === $clause_b || !$clause_b->reconcilable || $clause_b->wedge) { continue; } if (isset($clause_b->possibilities[$clause_var]) && in_array($negated_clause_type, $clause_b->possibilities[$clause_var], true) ) { $clause_b->possibilities[$clause_var] = array_filter( $clause_b->possibilities[$clause_var], /** * @param string $possible_type * * @return bool */ function ($possible_type) use ($negated_clause_type) { return $possible_type !== $negated_clause_type; } ); if (count($clause_b->possibilities[$clause_var]) === 0) { unset($clause_b->possibilities[$clause_var]); $clause_b->impossibilities = null; } } } } $deduped_clauses = []; // avoid strict duplicates foreach ($cloned_clauses as $clause) { $deduped_clauses[$clause->getHash()] = clone $clause; } $deduped_clauses = array_filter( $deduped_clauses, /** * @return bool */ function (Clause $clause) { return count($clause->possibilities) || $clause->wedge; } ); $simplified_clauses = []; foreach ($deduped_clauses as $clause_a) { $is_redundant = false; foreach ($deduped_clauses as $clause_b) { if ($clause_a === $clause_b || !$clause_b->reconcilable || $clause_b->wedge || $clause_a->wedge ) { continue; } if ($clause_a->contains($clause_b)) { $is_redundant = true; break; } } if (!$is_redundant) { $simplified_clauses[] = $clause_a; } } return $simplified_clauses; }
[ "public", "static", "function", "simplifyCNF", "(", "array", "$", "clauses", ")", "{", "$", "cloned_clauses", "=", "[", "]", ";", "// avoid strict duplicates", "foreach", "(", "$", "clauses", "as", "$", "clause", ")", "{", "$", "unique_clause", "=", "clone", "$", "clause", ";", "foreach", "(", "$", "unique_clause", "->", "possibilities", "as", "$", "var_id", "=>", "$", "possibilities", ")", "{", "if", "(", "count", "(", "$", "possibilities", ")", ")", "{", "$", "unique_clause", "->", "possibilities", "[", "$", "var_id", "]", "=", "array_unique", "(", "$", "possibilities", ")", ";", "}", "}", "$", "cloned_clauses", "[", "$", "clause", "->", "getHash", "(", ")", "]", "=", "$", "unique_clause", ";", "}", "// remove impossible types", "foreach", "(", "$", "cloned_clauses", "as", "$", "clause_a", ")", "{", "if", "(", "count", "(", "$", "clause_a", "->", "possibilities", ")", "!==", "1", "||", "count", "(", "array_values", "(", "$", "clause_a", "->", "possibilities", ")", "[", "0", "]", ")", "!==", "1", ")", "{", "continue", ";", "}", "if", "(", "!", "$", "clause_a", "->", "reconcilable", "||", "$", "clause_a", "->", "wedge", ")", "{", "continue", ";", "}", "$", "clause_var", "=", "array_keys", "(", "$", "clause_a", "->", "possibilities", ")", "[", "0", "]", ";", "$", "only_type", "=", "array_pop", "(", "array_values", "(", "$", "clause_a", "->", "possibilities", ")", "[", "0", "]", ")", ";", "$", "negated_clause_type", "=", "self", "::", "negateType", "(", "$", "only_type", ")", ";", "foreach", "(", "$", "cloned_clauses", "as", "$", "clause_b", ")", "{", "if", "(", "$", "clause_a", "===", "$", "clause_b", "||", "!", "$", "clause_b", "->", "reconcilable", "||", "$", "clause_b", "->", "wedge", ")", "{", "continue", ";", "}", "if", "(", "isset", "(", "$", "clause_b", "->", "possibilities", "[", "$", "clause_var", "]", ")", "&&", "in_array", "(", "$", "negated_clause_type", ",", "$", "clause_b", "->", "possibilities", "[", "$", "clause_var", "]", ",", "true", ")", ")", "{", "$", "clause_b", "->", "possibilities", "[", "$", "clause_var", "]", "=", "array_filter", "(", "$", "clause_b", "->", "possibilities", "[", "$", "clause_var", "]", ",", "/**\n * @param string $possible_type\n *\n * @return bool\n */", "function", "(", "$", "possible_type", ")", "use", "(", "$", "negated_clause_type", ")", "{", "return", "$", "possible_type", "!==", "$", "negated_clause_type", ";", "}", ")", ";", "if", "(", "count", "(", "$", "clause_b", "->", "possibilities", "[", "$", "clause_var", "]", ")", "===", "0", ")", "{", "unset", "(", "$", "clause_b", "->", "possibilities", "[", "$", "clause_var", "]", ")", ";", "$", "clause_b", "->", "impossibilities", "=", "null", ";", "}", "}", "}", "}", "$", "deduped_clauses", "=", "[", "]", ";", "// avoid strict duplicates", "foreach", "(", "$", "cloned_clauses", "as", "$", "clause", ")", "{", "$", "deduped_clauses", "[", "$", "clause", "->", "getHash", "(", ")", "]", "=", "clone", "$", "clause", ";", "}", "$", "deduped_clauses", "=", "array_filter", "(", "$", "deduped_clauses", ",", "/**\n * @return bool\n */", "function", "(", "Clause", "$", "clause", ")", "{", "return", "count", "(", "$", "clause", "->", "possibilities", ")", "||", "$", "clause", "->", "wedge", ";", "}", ")", ";", "$", "simplified_clauses", "=", "[", "]", ";", "foreach", "(", "$", "deduped_clauses", "as", "$", "clause_a", ")", "{", "$", "is_redundant", "=", "false", ";", "foreach", "(", "$", "deduped_clauses", "as", "$", "clause_b", ")", "{", "if", "(", "$", "clause_a", "===", "$", "clause_b", "||", "!", "$", "clause_b", "->", "reconcilable", "||", "$", "clause_b", "->", "wedge", "||", "$", "clause_a", "->", "wedge", ")", "{", "continue", ";", "}", "if", "(", "$", "clause_a", "->", "contains", "(", "$", "clause_b", ")", ")", "{", "$", "is_redundant", "=", "true", ";", "break", ";", "}", "}", "if", "(", "!", "$", "is_redundant", ")", "{", "$", "simplified_clauses", "[", "]", "=", "$", "clause_a", ";", "}", "}", "return", "$", "simplified_clauses", ";", "}" ]
This is a very simple simplification heuristic for CNF formulae. It simplifies formulae: ($a) && ($a || $b) => $a (!$a) && (!$b) && ($a || $b || $c) => $c @param array<int, Clause> $clauses @return array<int, Clause>
[ "This", "is", "a", "very", "simple", "simplification", "heuristic", "for", "CNF", "formulae", "." ]
dd409871876fcafb4a85ac3901453fb05c46814c
https://github.com/vimeo/psalm/blob/dd409871876fcafb4a85ac3901453fb05c46814c/src/Psalm/Type/Algebra.php#L222-L322
train
vimeo/psalm
src/Psalm/Type/Algebra.php
Algebra.getTruthsFromFormula
public static function getTruthsFromFormula( array $clauses, array &$cond_referenced_var_ids = [] ) { $truths = []; if (empty($clauses)) { return []; } foreach ($clauses as $clause) { if (!$clause->reconcilable) { continue; } foreach ($clause->possibilities as $var => $possible_types) { // if there's only one possible type, return it if (count($clause->possibilities) === 1 && count($possible_types) === 1) { if (isset($truths[$var])) { $truths[$var][] = [array_pop($possible_types)]; } else { $truths[$var] = [[array_pop($possible_types)]]; } } elseif (count($clause->possibilities) === 1) { // if there's only one active clause, return all the non-negation clause members ORed together $things_that_can_be_said = array_filter( $possible_types, /** * @param string $possible_type * * @return bool * * @psalm-suppress MixedOperand */ function ($possible_type) { return $possible_type[0] !== '!'; } ); if ($things_that_can_be_said && count($things_that_can_be_said) === count($possible_types)) { $things_that_can_be_said = array_unique($things_that_can_be_said); if ($clause->generated && count($possible_types) > 1) { unset($cond_referenced_var_ids[$var]); } /** @var array<int, string> $things_that_can_be_said */ $truths[$var] = [$things_that_can_be_said]; } } } } return $truths; }
php
public static function getTruthsFromFormula( array $clauses, array &$cond_referenced_var_ids = [] ) { $truths = []; if (empty($clauses)) { return []; } foreach ($clauses as $clause) { if (!$clause->reconcilable) { continue; } foreach ($clause->possibilities as $var => $possible_types) { // if there's only one possible type, return it if (count($clause->possibilities) === 1 && count($possible_types) === 1) { if (isset($truths[$var])) { $truths[$var][] = [array_pop($possible_types)]; } else { $truths[$var] = [[array_pop($possible_types)]]; } } elseif (count($clause->possibilities) === 1) { // if there's only one active clause, return all the non-negation clause members ORed together $things_that_can_be_said = array_filter( $possible_types, /** * @param string $possible_type * * @return bool * * @psalm-suppress MixedOperand */ function ($possible_type) { return $possible_type[0] !== '!'; } ); if ($things_that_can_be_said && count($things_that_can_be_said) === count($possible_types)) { $things_that_can_be_said = array_unique($things_that_can_be_said); if ($clause->generated && count($possible_types) > 1) { unset($cond_referenced_var_ids[$var]); } /** @var array<int, string> $things_that_can_be_said */ $truths[$var] = [$things_that_can_be_said]; } } } } return $truths; }
[ "public", "static", "function", "getTruthsFromFormula", "(", "array", "$", "clauses", ",", "array", "&", "$", "cond_referenced_var_ids", "=", "[", "]", ")", "{", "$", "truths", "=", "[", "]", ";", "if", "(", "empty", "(", "$", "clauses", ")", ")", "{", "return", "[", "]", ";", "}", "foreach", "(", "$", "clauses", "as", "$", "clause", ")", "{", "if", "(", "!", "$", "clause", "->", "reconcilable", ")", "{", "continue", ";", "}", "foreach", "(", "$", "clause", "->", "possibilities", "as", "$", "var", "=>", "$", "possible_types", ")", "{", "// if there's only one possible type, return it", "if", "(", "count", "(", "$", "clause", "->", "possibilities", ")", "===", "1", "&&", "count", "(", "$", "possible_types", ")", "===", "1", ")", "{", "if", "(", "isset", "(", "$", "truths", "[", "$", "var", "]", ")", ")", "{", "$", "truths", "[", "$", "var", "]", "[", "]", "=", "[", "array_pop", "(", "$", "possible_types", ")", "]", ";", "}", "else", "{", "$", "truths", "[", "$", "var", "]", "=", "[", "[", "array_pop", "(", "$", "possible_types", ")", "]", "]", ";", "}", "}", "elseif", "(", "count", "(", "$", "clause", "->", "possibilities", ")", "===", "1", ")", "{", "// if there's only one active clause, return all the non-negation clause members ORed together", "$", "things_that_can_be_said", "=", "array_filter", "(", "$", "possible_types", ",", "/**\n * @param string $possible_type\n *\n * @return bool\n *\n * @psalm-suppress MixedOperand\n */", "function", "(", "$", "possible_type", ")", "{", "return", "$", "possible_type", "[", "0", "]", "!==", "'!'", ";", "}", ")", ";", "if", "(", "$", "things_that_can_be_said", "&&", "count", "(", "$", "things_that_can_be_said", ")", "===", "count", "(", "$", "possible_types", ")", ")", "{", "$", "things_that_can_be_said", "=", "array_unique", "(", "$", "things_that_can_be_said", ")", ";", "if", "(", "$", "clause", "->", "generated", "&&", "count", "(", "$", "possible_types", ")", ">", "1", ")", "{", "unset", "(", "$", "cond_referenced_var_ids", "[", "$", "var", "]", ")", ";", "}", "/** @var array<int, string> $things_that_can_be_said */", "$", "truths", "[", "$", "var", "]", "=", "[", "$", "things_that_can_be_said", "]", ";", "}", "}", "}", "}", "return", "$", "truths", ";", "}" ]
Look for clauses with only one possible value @param array<int, Clause> $clauses @param array<string, bool> $cond_referenced_var_ids @return array<string, array<int, array<int, string>>>
[ "Look", "for", "clauses", "with", "only", "one", "possible", "value" ]
dd409871876fcafb4a85ac3901453fb05c46814c
https://github.com/vimeo/psalm/blob/dd409871876fcafb4a85ac3901453fb05c46814c/src/Psalm/Type/Algebra.php#L332-L386
train
vimeo/psalm
src/Psalm/Internal/LanguageServer/Client/TextDocument.php
TextDocument.publishDiagnostics
public function publishDiagnostics(string $uri, array $diagnostics): Promise { return $this->handler->notify('textDocument/publishDiagnostics', [ 'uri' => $uri, 'diagnostics' => $diagnostics ]); }
php
public function publishDiagnostics(string $uri, array $diagnostics): Promise { return $this->handler->notify('textDocument/publishDiagnostics', [ 'uri' => $uri, 'diagnostics' => $diagnostics ]); }
[ "public", "function", "publishDiagnostics", "(", "string", "$", "uri", ",", "array", "$", "diagnostics", ")", ":", "Promise", "{", "return", "$", "this", "->", "handler", "->", "notify", "(", "'textDocument/publishDiagnostics'", ",", "[", "'uri'", "=>", "$", "uri", ",", "'diagnostics'", "=>", "$", "diagnostics", "]", ")", ";", "}" ]
Diagnostics notification are sent from the server to the client to signal results of validation runs. @param string $uri @param Diagnostic[] $diagnostics @return Promise <void>
[ "Diagnostics", "notification", "are", "sent", "from", "the", "server", "to", "the", "client", "to", "signal", "results", "of", "validation", "runs", "." ]
dd409871876fcafb4a85ac3901453fb05c46814c
https://github.com/vimeo/psalm/blob/dd409871876fcafb4a85ac3901453fb05c46814c/src/Psalm/Internal/LanguageServer/Client/TextDocument.php#L40-L46
train
vimeo/psalm
src/Psalm/Internal/LanguageServer/Client/TextDocument.php
TextDocument.xcontent
public function xcontent(TextDocumentIdentifier $textDocument): Promise { return call( /** * @return \Generator<int, mixed, mixed, TextDocumentItem> */ function () use ($textDocument) { $result = yield $this->handler->request( 'textDocument/xcontent', ['textDocument' => $textDocument] ); /** @var TextDocumentItem */ return $this->mapper->map($result, new TextDocumentItem); } ); }
php
public function xcontent(TextDocumentIdentifier $textDocument): Promise { return call( /** * @return \Generator<int, mixed, mixed, TextDocumentItem> */ function () use ($textDocument) { $result = yield $this->handler->request( 'textDocument/xcontent', ['textDocument' => $textDocument] ); /** @var TextDocumentItem */ return $this->mapper->map($result, new TextDocumentItem); } ); }
[ "public", "function", "xcontent", "(", "TextDocumentIdentifier", "$", "textDocument", ")", ":", "Promise", "{", "return", "call", "(", "/**\n * @return \\Generator<int, mixed, mixed, TextDocumentItem>\n */", "function", "(", ")", "use", "(", "$", "textDocument", ")", "{", "$", "result", "=", "yield", "$", "this", "->", "handler", "->", "request", "(", "'textDocument/xcontent'", ",", "[", "'textDocument'", "=>", "$", "textDocument", "]", ")", ";", "/** @var TextDocumentItem */", "return", "$", "this", "->", "mapper", "->", "map", "(", "$", "result", ",", "new", "TextDocumentItem", ")", ";", "}", ")", ";", "}" ]
The content request is sent from a server to a client to request the current content of a text document identified by the URI @param TextDocumentIdentifier $textDocument The document to get the content for @return Promise<TextDocumentItem> The document's current content
[ "The", "content", "request", "is", "sent", "from", "a", "server", "to", "a", "client", "to", "request", "the", "current", "content", "of", "a", "text", "document", "identified", "by", "the", "URI" ]
dd409871876fcafb4a85ac3901453fb05c46814c
https://github.com/vimeo/psalm/blob/dd409871876fcafb4a85ac3901453fb05c46814c/src/Psalm/Internal/LanguageServer/Client/TextDocument.php#L55-L71
train
vimeo/psalm
src/Psalm/Internal/Analyzer/StatementsAnalyzer.php
StatementsAnalyzer.getFirstAppearance
public function getFirstAppearance($var_id) { return isset($this->all_vars[$var_id]) ? $this->all_vars[$var_id] : null; }
php
public function getFirstAppearance($var_id) { return isset($this->all_vars[$var_id]) ? $this->all_vars[$var_id] : null; }
[ "public", "function", "getFirstAppearance", "(", "$", "var_id", ")", "{", "return", "isset", "(", "$", "this", "->", "all_vars", "[", "$", "var_id", "]", ")", "?", "$", "this", "->", "all_vars", "[", "$", "var_id", "]", ":", "null", ";", "}" ]
The first appearance of the variable in this set of statements being evaluated @param string $var_id @return CodeLocation|null
[ "The", "first", "appearance", "of", "the", "variable", "in", "this", "set", "of", "statements", "being", "evaluated" ]
dd409871876fcafb4a85ac3901453fb05c46814c
https://github.com/vimeo/psalm/blob/dd409871876fcafb4a85ac3901453fb05c46814c/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php#L1593-L1596
train
vimeo/psalm
src/Psalm/Internal/Codebase/Properties.php
Properties.propertyExists
public function propertyExists( string $property_id, bool $read_mode, StatementsSource $source = null, Context $context = null, CodeLocation $code_location = null ) { // remove trailing backslash if it exists $property_id = preg_replace('/^\\\\/', '', $property_id); list($fq_class_name, $property_name) = explode('::$', $property_id); if ($this->property_existence_provider->has($fq_class_name)) { $property_exists = $this->property_existence_provider->doesPropertyExist( $fq_class_name, $property_name, $read_mode, $source, $context, $code_location ); if ($property_exists !== null) { return $property_exists; } } $class_storage = $this->classlike_storage_provider->get($fq_class_name); if (isset($class_storage->declaring_property_ids[$property_name])) { $declaring_property_class = $class_storage->declaring_property_ids[$property_name]; if ($context && $context->calling_method_id) { $this->file_reference_provider->addMethodReferenceToClassMember( $context->calling_method_id, strtolower($declaring_property_class) . '::$' . $property_name ); } elseif ($source) { $this->file_reference_provider->addFileReferenceToClassMember( $source->getFilePath(), strtolower($declaring_property_class) . '::$' . $property_name ); } if ($this->collect_locations && $code_location) { $this->file_reference_provider->addCallingLocationForClassProperty( $code_location, strtolower($declaring_property_class) . '::$' . $property_name ); } return true; } if ($context && $context->calling_method_id) { $this->file_reference_provider->addMethodReferenceToMissingClassMember( $context->calling_method_id, strtolower($fq_class_name) . '::$' . $property_name ); } elseif ($source) { $this->file_reference_provider->addFileReferenceToMissingClassMember( $source->getFilePath(), strtolower($fq_class_name) . '::$' . $property_name ); } return false; }
php
public function propertyExists( string $property_id, bool $read_mode, StatementsSource $source = null, Context $context = null, CodeLocation $code_location = null ) { // remove trailing backslash if it exists $property_id = preg_replace('/^\\\\/', '', $property_id); list($fq_class_name, $property_name) = explode('::$', $property_id); if ($this->property_existence_provider->has($fq_class_name)) { $property_exists = $this->property_existence_provider->doesPropertyExist( $fq_class_name, $property_name, $read_mode, $source, $context, $code_location ); if ($property_exists !== null) { return $property_exists; } } $class_storage = $this->classlike_storage_provider->get($fq_class_name); if (isset($class_storage->declaring_property_ids[$property_name])) { $declaring_property_class = $class_storage->declaring_property_ids[$property_name]; if ($context && $context->calling_method_id) { $this->file_reference_provider->addMethodReferenceToClassMember( $context->calling_method_id, strtolower($declaring_property_class) . '::$' . $property_name ); } elseif ($source) { $this->file_reference_provider->addFileReferenceToClassMember( $source->getFilePath(), strtolower($declaring_property_class) . '::$' . $property_name ); } if ($this->collect_locations && $code_location) { $this->file_reference_provider->addCallingLocationForClassProperty( $code_location, strtolower($declaring_property_class) . '::$' . $property_name ); } return true; } if ($context && $context->calling_method_id) { $this->file_reference_provider->addMethodReferenceToMissingClassMember( $context->calling_method_id, strtolower($fq_class_name) . '::$' . $property_name ); } elseif ($source) { $this->file_reference_provider->addFileReferenceToMissingClassMember( $source->getFilePath(), strtolower($fq_class_name) . '::$' . $property_name ); } return false; }
[ "public", "function", "propertyExists", "(", "string", "$", "property_id", ",", "bool", "$", "read_mode", ",", "StatementsSource", "$", "source", "=", "null", ",", "Context", "$", "context", "=", "null", ",", "CodeLocation", "$", "code_location", "=", "null", ")", "{", "// remove trailing backslash if it exists", "$", "property_id", "=", "preg_replace", "(", "'/^\\\\\\\\/'", ",", "''", ",", "$", "property_id", ")", ";", "list", "(", "$", "fq_class_name", ",", "$", "property_name", ")", "=", "explode", "(", "'::$'", ",", "$", "property_id", ")", ";", "if", "(", "$", "this", "->", "property_existence_provider", "->", "has", "(", "$", "fq_class_name", ")", ")", "{", "$", "property_exists", "=", "$", "this", "->", "property_existence_provider", "->", "doesPropertyExist", "(", "$", "fq_class_name", ",", "$", "property_name", ",", "$", "read_mode", ",", "$", "source", ",", "$", "context", ",", "$", "code_location", ")", ";", "if", "(", "$", "property_exists", "!==", "null", ")", "{", "return", "$", "property_exists", ";", "}", "}", "$", "class_storage", "=", "$", "this", "->", "classlike_storage_provider", "->", "get", "(", "$", "fq_class_name", ")", ";", "if", "(", "isset", "(", "$", "class_storage", "->", "declaring_property_ids", "[", "$", "property_name", "]", ")", ")", "{", "$", "declaring_property_class", "=", "$", "class_storage", "->", "declaring_property_ids", "[", "$", "property_name", "]", ";", "if", "(", "$", "context", "&&", "$", "context", "->", "calling_method_id", ")", "{", "$", "this", "->", "file_reference_provider", "->", "addMethodReferenceToClassMember", "(", "$", "context", "->", "calling_method_id", ",", "strtolower", "(", "$", "declaring_property_class", ")", ".", "'::$'", ".", "$", "property_name", ")", ";", "}", "elseif", "(", "$", "source", ")", "{", "$", "this", "->", "file_reference_provider", "->", "addFileReferenceToClassMember", "(", "$", "source", "->", "getFilePath", "(", ")", ",", "strtolower", "(", "$", "declaring_property_class", ")", ".", "'::$'", ".", "$", "property_name", ")", ";", "}", "if", "(", "$", "this", "->", "collect_locations", "&&", "$", "code_location", ")", "{", "$", "this", "->", "file_reference_provider", "->", "addCallingLocationForClassProperty", "(", "$", "code_location", ",", "strtolower", "(", "$", "declaring_property_class", ")", ".", "'::$'", ".", "$", "property_name", ")", ";", "}", "return", "true", ";", "}", "if", "(", "$", "context", "&&", "$", "context", "->", "calling_method_id", ")", "{", "$", "this", "->", "file_reference_provider", "->", "addMethodReferenceToMissingClassMember", "(", "$", "context", "->", "calling_method_id", ",", "strtolower", "(", "$", "fq_class_name", ")", ".", "'::$'", ".", "$", "property_name", ")", ";", "}", "elseif", "(", "$", "source", ")", "{", "$", "this", "->", "file_reference_provider", "->", "addFileReferenceToMissingClassMember", "(", "$", "source", "->", "getFilePath", "(", ")", ",", "strtolower", "(", "$", "fq_class_name", ")", ".", "'::$'", ".", "$", "property_name", ")", ";", "}", "return", "false", ";", "}" ]
Whether or not a given property exists @return bool
[ "Whether", "or", "not", "a", "given", "property", "exists" ]
dd409871876fcafb4a85ac3901453fb05c46814c
https://github.com/vimeo/psalm/blob/dd409871876fcafb4a85ac3901453fb05c46814c/src/Psalm/Internal/Codebase/Properties.php#L69-L136
train
vimeo/psalm
src/Psalm/Context.php
Context.update
public function update( Context $start_context, Context $end_context, $has_leaving_statements, array $vars_to_update, array &$updated_vars ) { foreach ($start_context->vars_in_scope as $var_id => $old_type) { // this is only true if there was some sort of type negation if (in_array($var_id, $vars_to_update, true)) { // if we're leaving, we're effectively deleting the possibility of the if types $new_type = !$has_leaving_statements && $end_context->hasVariable($var_id) ? $end_context->vars_in_scope[$var_id] : null; $existing_type = isset($this->vars_in_scope[$var_id]) ? $this->vars_in_scope[$var_id] : null; if (!$existing_type) { if ($new_type) { $this->vars_in_scope[$var_id] = clone $new_type; $updated_vars[$var_id] = true; } continue; } // if the type changed within the block of statements, process the replacement // also never allow ourselves to remove all types from a union if ((!$new_type || !$old_type->equals($new_type)) && ($new_type || count($existing_type->getTypes()) > 1) ) { $existing_type->substitute($old_type, $new_type); if ($new_type && $new_type->from_docblock) { $existing_type->setFromDocblock(); } $updated_vars[$var_id] = true; } } } }
php
public function update( Context $start_context, Context $end_context, $has_leaving_statements, array $vars_to_update, array &$updated_vars ) { foreach ($start_context->vars_in_scope as $var_id => $old_type) { // this is only true if there was some sort of type negation if (in_array($var_id, $vars_to_update, true)) { // if we're leaving, we're effectively deleting the possibility of the if types $new_type = !$has_leaving_statements && $end_context->hasVariable($var_id) ? $end_context->vars_in_scope[$var_id] : null; $existing_type = isset($this->vars_in_scope[$var_id]) ? $this->vars_in_scope[$var_id] : null; if (!$existing_type) { if ($new_type) { $this->vars_in_scope[$var_id] = clone $new_type; $updated_vars[$var_id] = true; } continue; } // if the type changed within the block of statements, process the replacement // also never allow ourselves to remove all types from a union if ((!$new_type || !$old_type->equals($new_type)) && ($new_type || count($existing_type->getTypes()) > 1) ) { $existing_type->substitute($old_type, $new_type); if ($new_type && $new_type->from_docblock) { $existing_type->setFromDocblock(); } $updated_vars[$var_id] = true; } } } }
[ "public", "function", "update", "(", "Context", "$", "start_context", ",", "Context", "$", "end_context", ",", "$", "has_leaving_statements", ",", "array", "$", "vars_to_update", ",", "array", "&", "$", "updated_vars", ")", "{", "foreach", "(", "$", "start_context", "->", "vars_in_scope", "as", "$", "var_id", "=>", "$", "old_type", ")", "{", "// this is only true if there was some sort of type negation", "if", "(", "in_array", "(", "$", "var_id", ",", "$", "vars_to_update", ",", "true", ")", ")", "{", "// if we're leaving, we're effectively deleting the possibility of the if types", "$", "new_type", "=", "!", "$", "has_leaving_statements", "&&", "$", "end_context", "->", "hasVariable", "(", "$", "var_id", ")", "?", "$", "end_context", "->", "vars_in_scope", "[", "$", "var_id", "]", ":", "null", ";", "$", "existing_type", "=", "isset", "(", "$", "this", "->", "vars_in_scope", "[", "$", "var_id", "]", ")", "?", "$", "this", "->", "vars_in_scope", "[", "$", "var_id", "]", ":", "null", ";", "if", "(", "!", "$", "existing_type", ")", "{", "if", "(", "$", "new_type", ")", "{", "$", "this", "->", "vars_in_scope", "[", "$", "var_id", "]", "=", "clone", "$", "new_type", ";", "$", "updated_vars", "[", "$", "var_id", "]", "=", "true", ";", "}", "continue", ";", "}", "// if the type changed within the block of statements, process the replacement", "// also never allow ourselves to remove all types from a union", "if", "(", "(", "!", "$", "new_type", "||", "!", "$", "old_type", "->", "equals", "(", "$", "new_type", ")", ")", "&&", "(", "$", "new_type", "||", "count", "(", "$", "existing_type", "->", "getTypes", "(", ")", ")", ">", "1", ")", ")", "{", "$", "existing_type", "->", "substitute", "(", "$", "old_type", ",", "$", "new_type", ")", ";", "if", "(", "$", "new_type", "&&", "$", "new_type", "->", "from_docblock", ")", "{", "$", "existing_type", "->", "setFromDocblock", "(", ")", ";", "}", "$", "updated_vars", "[", "$", "var_id", "]", "=", "true", ";", "}", "}", "}", "}" ]
Updates the parent context, looking at the changes within a block and then applying those changes, where necessary, to the parent context @param Context $start_context @param Context $end_context @param bool $has_leaving_statements whether or not the parent scope is abandoned between $start_context and $end_context @param array $vars_to_update @param array $updated_vars @return void
[ "Updates", "the", "parent", "context", "looking", "at", "the", "changes", "within", "a", "block", "and", "then", "applying", "those", "changes", "where", "necessary", "to", "the", "parent", "context" ]
dd409871876fcafb4a85ac3901453fb05c46814c
https://github.com/vimeo/psalm/blob/dd409871876fcafb4a85ac3901453fb05c46814c/src/Psalm/Context.php#L328-L369
train
vimeo/psalm
src/Psalm/Config.php
Config.getConfigForPath
public static function getConfigForPath($path, $base_dir, $output_format) { $config_path = self::locateConfigFile($path); if (!$config_path) { if ($output_format === ProjectAnalyzer::TYPE_CONSOLE) { exit( 'Could not locate a config XML file in path ' . $path . '. Have you run \'psalm --init\' ?' . PHP_EOL ); } throw new ConfigException('Config not found for path ' . $path); } return self::loadFromXMLFile($config_path, $base_dir); }
php
public static function getConfigForPath($path, $base_dir, $output_format) { $config_path = self::locateConfigFile($path); if (!$config_path) { if ($output_format === ProjectAnalyzer::TYPE_CONSOLE) { exit( 'Could not locate a config XML file in path ' . $path . '. Have you run \'psalm --init\' ?' . PHP_EOL ); } throw new ConfigException('Config not found for path ' . $path); } return self::loadFromXMLFile($config_path, $base_dir); }
[ "public", "static", "function", "getConfigForPath", "(", "$", "path", ",", "$", "base_dir", ",", "$", "output_format", ")", "{", "$", "config_path", "=", "self", "::", "locateConfigFile", "(", "$", "path", ")", ";", "if", "(", "!", "$", "config_path", ")", "{", "if", "(", "$", "output_format", "===", "ProjectAnalyzer", "::", "TYPE_CONSOLE", ")", "{", "exit", "(", "'Could not locate a config XML file in path '", ".", "$", "path", ".", "'. Have you run \\'psalm --init\\' ?'", ".", "PHP_EOL", ")", ";", "}", "throw", "new", "ConfigException", "(", "'Config not found for path '", ".", "$", "path", ")", ";", "}", "return", "self", "::", "loadFromXMLFile", "(", "$", "config_path", ",", "$", "base_dir", ")", ";", "}" ]
Gets a Config object from an XML file. Searches up a folder hierarchy for the most immediate config. @param string $path @param string $base_dir @param string $output_format @throws ConfigException if a config path is not found @return Config @psalm-suppress MixedArgument
[ "Gets", "a", "Config", "object", "from", "an", "XML", "file", "." ]
dd409871876fcafb4a85ac3901453fb05c46814c
https://github.com/vimeo/psalm/blob/dd409871876fcafb4a85ac3901453fb05c46814c/src/Psalm/Config.php#L417-L432
train
vimeo/psalm
src/Psalm/Config.php
Config.locateConfigFile
public static function locateConfigFile(string $path) { $dir_path = realpath($path); if ($dir_path === false) { throw new ConfigException('Config not found for path ' . $path); } if (!is_dir($dir_path)) { $dir_path = dirname($dir_path); } do { $maybe_path = $dir_path . DIRECTORY_SEPARATOR . Config::DEFAULT_FILE_NAME; if (file_exists($maybe_path) || file_exists($maybe_path .= '.dist')) { return $maybe_path; } $dir_path = dirname($dir_path); } while (dirname($dir_path) !== $dir_path); return null; }
php
public static function locateConfigFile(string $path) { $dir_path = realpath($path); if ($dir_path === false) { throw new ConfigException('Config not found for path ' . $path); } if (!is_dir($dir_path)) { $dir_path = dirname($dir_path); } do { $maybe_path = $dir_path . DIRECTORY_SEPARATOR . Config::DEFAULT_FILE_NAME; if (file_exists($maybe_path) || file_exists($maybe_path .= '.dist')) { return $maybe_path; } $dir_path = dirname($dir_path); } while (dirname($dir_path) !== $dir_path); return null; }
[ "public", "static", "function", "locateConfigFile", "(", "string", "$", "path", ")", "{", "$", "dir_path", "=", "realpath", "(", "$", "path", ")", ";", "if", "(", "$", "dir_path", "===", "false", ")", "{", "throw", "new", "ConfigException", "(", "'Config not found for path '", ".", "$", "path", ")", ";", "}", "if", "(", "!", "is_dir", "(", "$", "dir_path", ")", ")", "{", "$", "dir_path", "=", "dirname", "(", "$", "dir_path", ")", ";", "}", "do", "{", "$", "maybe_path", "=", "$", "dir_path", ".", "DIRECTORY_SEPARATOR", ".", "Config", "::", "DEFAULT_FILE_NAME", ";", "if", "(", "file_exists", "(", "$", "maybe_path", ")", "||", "file_exists", "(", "$", "maybe_path", ".=", "'.dist'", ")", ")", "{", "return", "$", "maybe_path", ";", "}", "$", "dir_path", "=", "dirname", "(", "$", "dir_path", ")", ";", "}", "while", "(", "dirname", "(", "$", "dir_path", ")", "!==", "$", "dir_path", ")", ";", "return", "null", ";", "}" ]
Searches up a folder hierarchy for the most immediate config. @throws ConfigException @return ?string
[ "Searches", "up", "a", "folder", "hierarchy", "for", "the", "most", "immediate", "config", "." ]
dd409871876fcafb4a85ac3901453fb05c46814c
https://github.com/vimeo/psalm/blob/dd409871876fcafb4a85ac3901453fb05c46814c/src/Psalm/Config.php#L440-L462
train
vimeo/psalm
src/Psalm/Config.php
Config.loadFromXMLFile
public static function loadFromXMLFile($file_path, $base_dir) { $file_contents = file_get_contents($file_path); if ($file_contents === false) { throw new \InvalidArgumentException('Cannot open ' . $file_path); } try { $config = self::loadFromXML($base_dir, $file_contents); $config->hash = sha1($file_contents); } catch (ConfigException $e) { throw new ConfigException( 'Problem parsing ' . $file_path . ":\n" . ' ' . $e->getMessage() ); } return $config; }
php
public static function loadFromXMLFile($file_path, $base_dir) { $file_contents = file_get_contents($file_path); if ($file_contents === false) { throw new \InvalidArgumentException('Cannot open ' . $file_path); } try { $config = self::loadFromXML($base_dir, $file_contents); $config->hash = sha1($file_contents); } catch (ConfigException $e) { throw new ConfigException( 'Problem parsing ' . $file_path . ":\n" . ' ' . $e->getMessage() ); } return $config; }
[ "public", "static", "function", "loadFromXMLFile", "(", "$", "file_path", ",", "$", "base_dir", ")", "{", "$", "file_contents", "=", "file_get_contents", "(", "$", "file_path", ")", ";", "if", "(", "$", "file_contents", "===", "false", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Cannot open '", ".", "$", "file_path", ")", ";", "}", "try", "{", "$", "config", "=", "self", "::", "loadFromXML", "(", "$", "base_dir", ",", "$", "file_contents", ")", ";", "$", "config", "->", "hash", "=", "sha1", "(", "$", "file_contents", ")", ";", "}", "catch", "(", "ConfigException", "$", "e", ")", "{", "throw", "new", "ConfigException", "(", "'Problem parsing '", ".", "$", "file_path", ".", "\":\\n\"", ".", "' '", ".", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "return", "$", "config", ";", "}" ]
Creates a new config object from the file @param string $file_path @param string $base_dir @return self
[ "Creates", "a", "new", "config", "object", "from", "the", "file" ]
dd409871876fcafb4a85ac3901453fb05c46814c
https://github.com/vimeo/psalm/blob/dd409871876fcafb4a85ac3901453fb05c46814c/src/Psalm/Config.php#L472-L490
train
vimeo/psalm
src/Psalm/Internal/Diff/FileDiffer.php
FileDiffer.coalesceReplacements
private static function coalesceReplacements(array $diff) { $newDiff = []; $c = \count($diff); for ($i = 0; $i < $c; $i++) { $diffType = $diff[$i]->type; if ($diffType !== DiffElem::TYPE_REMOVE) { $newDiff[] = $diff[$i]; continue; } $j = $i; while ($j < $c && $diff[$j]->type === DiffElem::TYPE_REMOVE) { $j++; } $k = $j; while ($k < $c && $diff[$k]->type === DiffElem::TYPE_ADD) { $k++; } if ($j - $i === $k - $j) { $len = $j - $i; for ($n = 0; $n < $len; $n++) { $newDiff[] = new DiffElem( DiffElem::TYPE_REPLACE, $diff[$i + $n]->old, $diff[$j + $n]->new ); } } else { for (; $i < $k; $i++) { $newDiff[] = $diff[$i]; } } /** @psalm-suppress LoopInvalidation */ $i = $k - 1; } return $newDiff; }
php
private static function coalesceReplacements(array $diff) { $newDiff = []; $c = \count($diff); for ($i = 0; $i < $c; $i++) { $diffType = $diff[$i]->type; if ($diffType !== DiffElem::TYPE_REMOVE) { $newDiff[] = $diff[$i]; continue; } $j = $i; while ($j < $c && $diff[$j]->type === DiffElem::TYPE_REMOVE) { $j++; } $k = $j; while ($k < $c && $diff[$k]->type === DiffElem::TYPE_ADD) { $k++; } if ($j - $i === $k - $j) { $len = $j - $i; for ($n = 0; $n < $len; $n++) { $newDiff[] = new DiffElem( DiffElem::TYPE_REPLACE, $diff[$i + $n]->old, $diff[$j + $n]->new ); } } else { for (; $i < $k; $i++) { $newDiff[] = $diff[$i]; } } /** @psalm-suppress LoopInvalidation */ $i = $k - 1; } return $newDiff; }
[ "private", "static", "function", "coalesceReplacements", "(", "array", "$", "diff", ")", "{", "$", "newDiff", "=", "[", "]", ";", "$", "c", "=", "\\", "count", "(", "$", "diff", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "c", ";", "$", "i", "++", ")", "{", "$", "diffType", "=", "$", "diff", "[", "$", "i", "]", "->", "type", ";", "if", "(", "$", "diffType", "!==", "DiffElem", "::", "TYPE_REMOVE", ")", "{", "$", "newDiff", "[", "]", "=", "$", "diff", "[", "$", "i", "]", ";", "continue", ";", "}", "$", "j", "=", "$", "i", ";", "while", "(", "$", "j", "<", "$", "c", "&&", "$", "diff", "[", "$", "j", "]", "->", "type", "===", "DiffElem", "::", "TYPE_REMOVE", ")", "{", "$", "j", "++", ";", "}", "$", "k", "=", "$", "j", ";", "while", "(", "$", "k", "<", "$", "c", "&&", "$", "diff", "[", "$", "k", "]", "->", "type", "===", "DiffElem", "::", "TYPE_ADD", ")", "{", "$", "k", "++", ";", "}", "if", "(", "$", "j", "-", "$", "i", "===", "$", "k", "-", "$", "j", ")", "{", "$", "len", "=", "$", "j", "-", "$", "i", ";", "for", "(", "$", "n", "=", "0", ";", "$", "n", "<", "$", "len", ";", "$", "n", "++", ")", "{", "$", "newDiff", "[", "]", "=", "new", "DiffElem", "(", "DiffElem", "::", "TYPE_REPLACE", ",", "$", "diff", "[", "$", "i", "+", "$", "n", "]", "->", "old", ",", "$", "diff", "[", "$", "j", "+", "$", "n", "]", "->", "new", ")", ";", "}", "}", "else", "{", "for", "(", ";", "$", "i", "<", "$", "k", ";", "$", "i", "++", ")", "{", "$", "newDiff", "[", "]", "=", "$", "diff", "[", "$", "i", "]", ";", "}", "}", "/** @psalm-suppress LoopInvalidation */", "$", "i", "=", "$", "k", "-", "1", ";", "}", "return", "$", "newDiff", ";", "}" ]
Coalesce equal-length sequences of remove+add into a replace operation. @param DiffElem[] $diff @return DiffElem[]
[ "Coalesce", "equal", "-", "length", "sequences", "of", "remove", "+", "add", "into", "a", "replace", "operation", "." ]
dd409871876fcafb4a85ac3901453fb05c46814c
https://github.com/vimeo/psalm/blob/dd409871876fcafb4a85ac3901453fb05c46814c/src/Psalm/Internal/Diff/FileDiffer.php#L257-L297
train
vimeo/psalm
src/Psalm/Codebase.php
Codebase.scanFiles
public function scanFiles(int $threads = 1) { $has_changes = $this->scanner->scanFiles($this->classlikes, $threads); if ($has_changes) { $this->populator->populateCodebase($this); } }
php
public function scanFiles(int $threads = 1) { $has_changes = $this->scanner->scanFiles($this->classlikes, $threads); if ($has_changes) { $this->populator->populateCodebase($this); } }
[ "public", "function", "scanFiles", "(", "int", "$", "threads", "=", "1", ")", "{", "$", "has_changes", "=", "$", "this", "->", "scanner", "->", "scanFiles", "(", "$", "this", "->", "classlikes", ",", "$", "threads", ")", ";", "if", "(", "$", "has_changes", ")", "{", "$", "this", "->", "populator", "->", "populateCodebase", "(", "$", "this", ")", ";", "}", "}" ]
Scans all files their related files @return void
[ "Scans", "all", "files", "their", "related", "files" ]
dd409871876fcafb4a85ac3901453fb05c46814c
https://github.com/vimeo/psalm/blob/dd409871876fcafb4a85ac3901453fb05c46814c/src/Psalm/Codebase.php#L383-L390
train
vimeo/psalm
src/Psalm/Codebase.php
Codebase.isTypeContainedByType
public function isTypeContainedByType( Type\Union $input_type, Type\Union $container_type ): bool { return TypeAnalyzer::isContainedBy($this, $input_type, $container_type); }
php
public function isTypeContainedByType( Type\Union $input_type, Type\Union $container_type ): bool { return TypeAnalyzer::isContainedBy($this, $input_type, $container_type); }
[ "public", "function", "isTypeContainedByType", "(", "Type", "\\", "Union", "$", "input_type", ",", "Type", "\\", "Union", "$", "container_type", ")", ":", "bool", "{", "return", "TypeAnalyzer", "::", "isContainedBy", "(", "$", "this", ",", "$", "input_type", ",", "$", "container_type", ")", ";", "}" ]
Checks if type is a subtype of other Given two types, checks if `$input_type` is a subtype of `$container_type`. If you consider `Type\Union` as a set of types, this will tell you if `$input_type` is fully contained in `$container_type`, $input_type ⊆ $container_type Useful for emitting issues like InvalidArgument, where argument at the call site should be a subset of the function parameter type.
[ "Checks", "if", "type", "is", "a", "subtype", "of", "other" ]
dd409871876fcafb4a85ac3901453fb05c46814c
https://github.com/vimeo/psalm/blob/dd409871876fcafb4a85ac3901453fb05c46814c/src/Psalm/Codebase.php#L1151-L1156
train