<commit_before><?php

namespace Znck\Trust\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Znck\Trust\Models\Permission;

class InstallPermissionsCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'trust:permissions {--force}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Install permissions.';

    /**
     * @var \Illuminate\Filesystem\Filesystem
     */
    private $file;

    public function __construct(Filesystem $file)
    {
        parent::__construct();
        $this->file = $file;
    }

    /**
     * Execute the console command.
     *
     * @return void
     */
    public function handle()
    {
        $permissions = $this->file->getRequire(base_path(config('trust.permissions')));

        $create = 0;
        $update = 0;
        foreach ($permissions as $slug => $attributes) {
            $permission = $this->findPermission($slug);
            if ($permission) {
                if ($this->option('force')) {
                    ++$update;
                    $permission->update($attributes + compact('slug'));
                }
            } else {
                ++$create;
                Permission::create($attributes + compact('slug'));
            }
        }
        $total = $create + $update;
        $this->line("Installed ${total} permissions. <info>(${create} new permissions)</info>");
    }

    /**
     * @param string $slug
     *
     * @return Permission
     */
    protected function findPermission(string $slug)
    {
        return Permission::where('slug', $slug)->first();
    }
}<commit_msg>:construction: Use contracts instead of concrete<commit_after><?php

namespace Znck\Trust\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Znck\Trust\Contracts\Permission;

class InstallPermissionsCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'trust:permissions {--force}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Install permissions.';

    /**
     * @var \Illuminate\Filesystem\Filesystem
     */
    private $file;

    public function __construct(Filesystem $file)
    {
        parent::__construct();
        $this->file = $file;
    }

    /**
     * Execute the console command.
     *
     * @return void
     */
    public function handle()
    {
        $permissions = $this->file->getRequire(base_path(config('trust.permissions')));

        $create = 0;
        $update = 0;
        foreach ($permissions as $slug => $attributes) {
            $permission = $this->findPermission($slug);
            if ($permission) {
                if ($this->option('force')) {
                    ++$update;
                    $permission->update($attributes + compact('slug'));
                }
            } else {
                ++$create;
                $this->create($attributes + compact('slug'));
            }
        }
        $total = $create + $update;
        $this->line("Installed ${total} permissions. <info>(${create} new permissions)</info>");
    }

    /**
     * @param string $slug
     *
     * @return Permission
     */
    protected function findPermission(string $slug)
    {
        return app(Permission::class)->whereSlug($slug)->first();
    }

    protected function create(array $attributes)
    {
        return app(Permission::class)->create($attributes);
    }
}
{'fraction_non_alphanumeric': 0.13882097256180387, 'fraction_numerical': 0.0010866612333604998, 'mean_word_length': 2.0205086136177193, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6265609', 'n_tokens_mistral': 1014, 'n_tokens_neox': 1000, 'n_words': 214}