Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
parameters:
paths:
- src
level: 6
level: 8
ignoreErrors:
- '#Call to static method user\(\) on an unknown class Exment.#'
- '#Call to static method transaction\(\) on an unknown class ExmentDB.#'
- '#Access to an undefined property Illuminate\\Database\\Eloquent\\Model::\$id.#'
- '#Access to an undefined property Illuminate\\Database\\Eloquent\\Model::\$password.#'
- '#Call to an undefined method Encore\\Admin\\Grid\\Column::pluck\(\).#'
- '#Cannot call method with\(\) on string.#'
- '#Cannot call method render\(\) on string.#'
Expand Down
3 changes: 3 additions & 0 deletions src/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ public static function extend($name, $class)
*/
public static function booting(callable $callback)
{
/** @phpstan-ignore-next-line */
static::$bootingCallbacks[] = $callback;
}

Expand All @@ -369,6 +370,7 @@ public static function booting(callable $callback)
*/
public static function registered(callable $callback)
{
/** @phpstan-ignore-next-line */
static::$registeredCallbacks[] = $callback;
}

Expand All @@ -378,6 +380,7 @@ public static function registered(callable $callback)
*/
public static function booted(callable $callback)
{
/** @phpstan-ignore-next-line */
static::$bootedCallbacks[] = $callback;
}

Expand Down
1 change: 1 addition & 0 deletions src/AdminServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function boot()

if (config('admin.https') || config('admin.secure')) {
\URL::forceScheme('https');
/** @phpstan-ignore-next-line */
$this->app['request']->server->set('HTTPS', true);
}

Expand Down
3 changes: 3 additions & 0 deletions src/Auth/Database/AdminTablesSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function run()
]);

// add role to user.
// @phpstan-ignore-next-line Administrator and Role are guaranteed to exist after create/truncate above
Administrator::first()->roles()->save(Role::first());

//create a permission
Expand Down Expand Up @@ -66,6 +67,7 @@ public function run()
],
]);

// @phpstan-ignore-next-line Role and Permission are guaranteed to exist after insert above
Role::first()->permissions()->save(Permission::first());

// add default menus.
Expand Down Expand Up @@ -123,6 +125,7 @@ public function run()
]);

// add role to menu.
// @phpstan-ignore-next-line Menu and Role are guaranteed to exist after insert above
Menu::find(2)->roles()->save(Role::first());
}
}
1 change: 1 addition & 0 deletions src/Auth/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public static function check($permission)
return;
}

// @phpstan-ignore-next-line User is guaranteed to be authenticated when this method is called
if (Auth::guard('admin')->user()->cannot($permission)) {
static::error();
}
Expand Down
2 changes: 2 additions & 0 deletions src/Console/AdminCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ private function getColumnWidth(array $commands)
$widths = [];

foreach ($commands as $command) {
/** @phpstan-ignore-next-line Cannot call method getName() on Illuminate\Console\Command|string. */
$widths[] = static::strlen($command->getName());
/** @phpstan-ignore-next-line Cannot call method getAliases() on Illuminate\Console\Command|string. */
foreach ($command->getAliases() as $alias) {
$widths[] = static::strlen($alias);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Console/CreateUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ public function handle()

$user = new $userModel(compact('username', 'password', 'name'));

/** @phpstan-ignore-next-line */
$user->save();

/** @phpstan-ignore-next-line */
$user->roles()->attach($roles);

$this->info("User [$name] created successfully.");
Expand Down
8 changes: 8 additions & 0 deletions src/Console/ExportSeedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function handle()
$exceptFields = [];
$exportUsers = $this->option('users');

/** @phpstan-ignore-next-line */
$seedFile = $this->laravel->databasePath().'/seeds/'.$name.'.php';
$contents = $this->getStub('AdminTablesSeeder');

Expand Down Expand Up @@ -68,11 +69,14 @@ public function handle()
$contents = preg_replace('/\/\/ users tables[\s\S]*?(?=\/\/ finish)/mu', '', $contents);
}

// @phpstan-ignore-next-line $contents is always string from preg_replace in practice
$contents = str_replace(array_keys($replaces), array_values($replaces), $contents);

/** @phpstan-ignore-next-line */
$this->laravel['files']->put($seedFile, $contents);

$this->line('<info>Admin tables seed file was created:</info> '.str_replace(base_path(), '', $seedFile));
/** @phpstan-ignore-next-line */
$this->line("Use: <info>php artisan db:seed --class={$name}</info>");
}

Expand All @@ -93,6 +97,7 @@ protected function getTableDataArrayAsString($table, $exceptFields = [])
return (array) $item;
})->all();

/** @phpstan-ignore-next-line */
return $this->varExport($array, str_repeat(' ', 12));
}

Expand All @@ -105,6 +110,7 @@ protected function getTableDataArrayAsString($table, $exceptFields = [])
*/
protected function getStub($name)
{
/** @phpstan-ignore-next-line */
return $this->laravel['files']->get(__DIR__."/stubs/$name.stub");
}

Expand All @@ -129,7 +135,9 @@ protected function varExport($var, $indent = '')
$r = [];

foreach ($var as $key => $value) {
/** @phpstan-ignore-next-line */
$r[] = "$indent "
/** @phpstan-ignore-next-line */
.($indexed ? '' : $this->varExport($key).' => ')
.$this->varExport($value, "{$indent} ");
}
Expand Down
13 changes: 13 additions & 0 deletions src/Console/ExtendCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,13 @@ public function handle(Filesystem $filesystem)
$this->makeDir();
}

/** @phpstan-ignore-next-line */
$this->package = $this->argument('extension');

InputExtensionName:
/** @phpstan-ignore-next-line */
if (!$this->validateExtensionName($this->package)) {
/** @phpstan-ignore-next-line */
$this->package = $this->ask("[$this->package] is not a valid package name, please input a name like (<vendor>/<name>)");
goto InputExtensionName;
}
Expand Down Expand Up @@ -138,6 +141,7 @@ protected function showTree()
*/
protected function makeFiles()
{
/** @phpstan-ignore-next-line Property Encore\Admin\Console\ExtendCommand::$namespace (string) does not accept array|string|null. */
$this->namespace = $this->getRootNameSpace();

$this->className = $this->getClassName();
Expand All @@ -154,6 +158,7 @@ protected function makeFiles()
$composerContents = str_replace(
[':package', ':namespace', ':class_name'],
[$this->package, str_replace('\\', '\\\\', $this->namespace).'\\\\', $this->className],
/** @phpstan-ignore-next-line Parameter #3 $subject of function str_replace expects array|string, string|false given. */
file_get_contents(__DIR__.'/stubs/extension/composer.json.stub')
);
$this->putFile('composer.json', $composerContents);
Expand All @@ -162,6 +167,7 @@ protected function makeFiles()
$classContents = str_replace(
[':namespace', ':class_name', ':title', ':path', ':base_package'],
[$this->namespace, $this->className, Str::title($this->className), basename($this->package), basename($this->package)],
/** @phpstan-ignore-next-line Parameter #3 $subject of function str_replace expects array|string, string|false given. */
file_get_contents(__DIR__.'/stubs/extension/extension.stub')
);
$this->putFile("src/{$this->className}.php", $classContents);
Expand All @@ -170,6 +176,7 @@ protected function makeFiles()
$providerContents = str_replace(
[':namespace', ':class_name', ':base_package', ':package'],
[$this->namespace, $this->className, basename($this->package), $this->package],
/** @phpstan-ignore-next-line Parameter #3 $subject of function str_replace expects array|string, string|false given. */
file_get_contents(__DIR__.'/stubs/extension/service-provider.stub')
);
$this->putFile("src/{$this->className}ServiceProvider.php", $providerContents);
Expand All @@ -178,6 +185,7 @@ protected function makeFiles()
$controllerContent = str_replace(
[':namespace', ':class_name', ':base_package'],
[$this->namespace, $this->className, basename($this->package)],
/** @phpstan-ignore-next-line Parameter #3 $subject of function str_replace expects array|string, string|false given. */
file_get_contents(__DIR__.'/stubs/extension/controller.stub')
);
$this->putFile("src/Http/Controllers/{$this->className}Controller.php", $controllerContent);
Expand All @@ -186,6 +194,7 @@ protected function makeFiles()
$routesContent = str_replace(
[':namespace', ':class_name', ':path'],
[$this->namespace, $this->className, basename($this->package)],
/** @phpstan-ignore-next-line Parameter #3 $subject of function str_replace expects array|string, string|false given. */
file_get_contents(__DIR__.'/stubs/extension/routes.stub')
);
$this->putFile('routes/web.php', $routesContent);
Expand Down Expand Up @@ -240,6 +249,7 @@ protected function makeDirs()
*/
protected function validateExtensionName($name)
{
/** @phpstan-ignore-next-line Method Encore\Admin\Console\ExtendCommand::validateExtensionName() should return int but returns int|false. */
return preg_match('/^[\w\-_]+\/[\w\-_]+$/', $name);
}

Expand Down Expand Up @@ -294,12 +304,15 @@ protected function copy($from, $to = null)
return;
}

/** @phpstan-ignore-next-line Parameter #1 $filename of function file_exists expects string, array|string given. */
if (!file_exists($from)) {
return;
}

// @phpstan-ignore-next-line $to from argument() may be string|null but is validated by caller
$to = $this->extensionPath($to);

/** @phpstan-ignore-next-line Parameter #1 $path of method Illuminate\Filesystem\Filesystem::copy() expects string, array|string given. */
$this->filesystem->copy($from, $to);
}

Expand Down
3 changes: 3 additions & 0 deletions src/Console/FormCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ protected function replaceClass($stub, $name)
{
$stub = parent::replaceClass($stub, $name);

/** @phpstan-ignore-next-line */
return str_replace('DummyTitle', $this->option('title'), $stub);
}

Expand Down Expand Up @@ -62,6 +63,7 @@ protected function getStub()
protected function getDefaultNamespace($rootNamespace)
{
if ($namespace = $this->option('namespace')) {
/** @phpstan-ignore-next-line Method Encore\Admin\Console\FormCommand::getDefaultNamespace() should return string but returns array|string|true. */
return $namespace;
}

Expand All @@ -75,6 +77,7 @@ protected function getDefaultNamespace($rootNamespace)
*/
protected function getNameInput()
{
/** @phpstan-ignore-next-line */
$name = trim($this->argument('name'));

$this->type = $this->qualifyClass($name);
Expand Down
2 changes: 2 additions & 0 deletions src/Console/ImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ public function handle()
{
$extension = $this->argument('extension');

/** @phpstan-ignore-next-line */
if (empty($extension) || !Arr::has(Admin::$extensions, $extension)) {
$extension = $this->choice('Please choose a extension to import', array_keys(Admin::$extensions));
}

/** @phpstan-ignore-next-line */
$className = Arr::get(Admin::$extensions, $extension);

if (!class_exists($className) || !method_exists($className, 'import')) {
Expand Down
7 changes: 7 additions & 0 deletions src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public function createHomeController()
$homeController = $this->directory.'/Controllers/HomeController.php';
$contents = $this->getStub('HomeController');

/** @phpstan-ignore-next-line */
$this->laravel['files']->put(
$homeController,
str_replace('DummyNamespace', config('admin.route.namespace'), $contents)
Expand All @@ -110,6 +111,7 @@ public function createAuthController()
$authController = $this->directory.'/Controllers/AuthController.php';
$contents = $this->getStub('AuthController');

/** @phpstan-ignore-next-line */
$this->laravel['files']->put(
$authController,
str_replace('DummyNamespace', config('admin.route.namespace'), $contents)
Expand All @@ -127,6 +129,7 @@ public function createExampleController()
$exampleController = $this->directory.'/Controllers/ExampleController.php';
$contents = $this->getStub('ExampleController');

/** @phpstan-ignore-next-line */
$this->laravel['files']->put(
$exampleController,
str_replace('DummyNamespace', config('admin.route.namespace'), $contents)
Expand All @@ -144,6 +147,7 @@ protected function createBootstrapFile()
$file = $this->directory.'/bootstrap.php';

$contents = $this->getStub('bootstrap');
/** @phpstan-ignore-next-line */
$this->laravel['files']->put($file, $contents);
$this->line('<info>Bootstrap file was created:</info> '.str_replace(base_path(), '', $file));
}
Expand All @@ -158,6 +162,7 @@ protected function createRoutesFile()
$file = $this->directory.'/routes.php';

$contents = $this->getStub('routes');
/** @phpstan-ignore-next-line */
$this->laravel['files']->put($file, str_replace('DummyNamespace', config('admin.route.namespace'), $contents));
$this->line('<info>Routes file was created:</info> '.str_replace(base_path(), '', $file));
}
Expand All @@ -171,6 +176,7 @@ protected function createRoutesFile()
*/
protected function getStub($name)
{
/** @phpstan-ignore-next-line */
return $this->laravel['files']->get(__DIR__."/stubs/$name.stub");
}

Expand All @@ -183,6 +189,7 @@ protected function getStub($name)
*/
protected function makeDir($path = '')
{
/** @phpstan-ignore-next-line */
$this->laravel['files']->makeDirectory("{$this->directory}/$path", 0755, true, true);
}
}
10 changes: 9 additions & 1 deletion src/Console/MakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function handle()

$stub = $this->option('stub');

/** @phpstan-ignore-next-line */
if ($stub and !is_file($stub)) {
$this->error('The stub file dose not exist.');

Expand All @@ -62,11 +63,13 @@ public function handle()

if (parent::handle() !== false) {
$name = $this->argument('name');
/** @phpstan-ignore-next-line */
$path = Str::plural(Str::kebab(class_basename($this->option('model'))));

$this->line('');
$this->comment('Add the following route to app/Admin/routes.php:');
$this->line('');
/** @phpstan-ignore-next-line */
$this->info(" \$router->resource('{$path}', {$name}::class);");
$this->line('');
}
Expand Down Expand Up @@ -99,6 +102,7 @@ protected function modelExists()
return true;
}

/** @phpstan-ignore-next-line */
return class_exists($model) && is_subclass_of($model, Model::class);
}

Expand Down Expand Up @@ -126,8 +130,9 @@ protected function replaceClass($stub, $name)
[
$this->option('model'),
$this->option('title') ?: $this->option('model'),
/** @phpstan-ignore-next-line */
class_basename($this->option('model')),
$this->indentCodes($this->generator->generateGrid()),
$this->indentCodes($this->generator->generateGrid()),
$this->indentCodes($this->generator->generateShow()),
$this->indentCodes($this->generator->generateForm()),
],
Expand Down Expand Up @@ -155,6 +160,7 @@ protected function indentCodes($code)
protected function getStub()
{
if ($stub = $this->option('stub')) {
/** @phpstan-ignore-next-line */
return $stub;
}

Expand All @@ -175,6 +181,7 @@ protected function getStub()
protected function getDefaultNamespace($rootNamespace)
{
if ($namespace = $this->option('namespace')) {
/** @phpstan-ignore-next-line */
return $namespace;
}

Expand All @@ -188,6 +195,7 @@ protected function getDefaultNamespace($rootNamespace)
*/
protected function getNameInput()
{
/** @phpstan-ignore-next-line */
$name = trim($this->argument('name'));

$this->type = $this->qualifyClass($name);
Expand Down
Loading