Code Duplication    Length = 14-15 lines in 2 locations

src/Models/Permission.php 1 location

@@ 81-95 (lines=15) @@
78
     * @return PermissionInterface
79
     * @throws \Maklad\Permission\Exceptions\PermissionAlreadyExists
80
     */
81
    public static function findOrCreate(string $name, $guardName = null): PermissionInterface
82
    {
83
        $guardName = $guardName ?? config('auth.defaults.guard');
84
85
        $permission = static::getPermissions()
86
                            ->where('name', $name)
87
                            ->where('guard_name', $guardName)
88
                            ->first();
89
90
        if (! $permission) {
91
            $permission = static::create(['name' => $name, 'guard_name' => $guardName]);
92
        }
93
94
        return $permission;
95
    }
96
97
    /**
98
     * A permission can be applied to roles.

src/Models/Role.php 1 location

@@ 80-93 (lines=14) @@
77
     * @return RoleInterface
78
     * @throws \Maklad\Permission\Exceptions\RoleAlreadyExists
79
     */
80
    public static function findOrCreate(string $name, $guardName = null): RoleInterface
81
    {
82
        $guardName = $guardName ?? config('auth.defaults.guard');
83
84
        $role = static::where('name', $name)
85
                      ->where('guard_name', $guardName)
86
                      ->first();
87
88
        if (! $role) {
89
            $role = static::create(['name' => $name, 'guard_name' => $guardName]);
90
        }
91
92
        return $role;
93
    }
94
95
    /**
96
     * A role may be given various permissions.