@@ -55,19 +55,15 @@ public function __construct(array $attributes = [])
5555 public static function create (array $ attributes = [])
5656 {
5757 $ attributes ['guard_name ' ] = $ attributes ['guard_name ' ] ?? (new Guard ())->getDefaultName (static ::class);
58- $ helpers = new Helpers ();
58+ $ helpers = new Helpers ();
5959
6060 if (static ::where ('name ' , $ attributes ['name ' ])->where ('guard_name ' , $ attributes ['guard_name ' ])->first ()) {
61- $ name = (string ) $ attributes ['name ' ];
62- $ guardName = (string ) $ attributes ['guard_name ' ];
61+ $ name = (string )$ attributes ['name ' ];
62+ $ guardName = (string )$ attributes ['guard_name ' ];
6363 throw new RoleAlreadyExists ($ helpers ->getRoleAlreadyExistsMessage ($ name , $ guardName ));
6464 }
6565
66- if ($ helpers ->isNotLumen () && app ()::VERSION < '5.4 ' ) {
67- return parent ::create ($ attributes );
68- }
69-
70- return static ::query ()->create ($ attributes );
66+ return $ helpers ->checkVersion () ? parent ::create ($ attributes ) : static ::query ()->create ($ attributes );
7167 }
7268
7369 /**
@@ -85,10 +81,10 @@ public static function findOrCreate(string $name, $guardName = null): RoleInterf
8581 $ guardName = $ guardName ?? (new Guard ())->getDefaultName (static ::class);
8682
8783 $ role = static ::where ('name ' , $ name )
88- ->where ('guard_name ' , $ guardName )
89- ->first ();
84+ ->where ('guard_name ' , $ guardName )
85+ ->first ();
9086
91- if (! $ role ) {
87+ if (!$ role ) {
9288 $ role = static ::create (['name ' => $ name , 'guard_name ' => $ guardName ]);
9389 }
9490
@@ -110,10 +106,10 @@ public static function findByName(string $name, $guardName = null): RoleInterfac
110106 $ guardName = $ guardName ?? (new Guard ())->getDefaultName (static ::class);
111107
112108 $ role = static ::where ('name ' , $ name )
113- ->where ('guard_name ' , $ guardName )
114- ->first ();
109+ ->where ('guard_name ' , $ guardName )
110+ ->first ();
115111
116- if (! $ role ) {
112+ if (!$ role ) {
117113 $ helpers = new Helpers ();
118114 throw new RoleDoesNotExist ($ helpers ->getRoleDoesNotExistMessage ($ name , $ guardName ));
119115 }
@@ -137,9 +133,9 @@ public function hasPermissionTo($permission): bool
137133 $ permission = $ this ->getPermissionClass ()->findByName ($ permission , $ this ->getDefaultGuardName ());
138134 }
139135
140- if (! $ this ->getGuardNames ()->contains ($ permission ->guard_name )) {
136+ if (!$ this ->getGuardNames ()->contains ($ permission ->guard_name )) {
141137 $ expected = $ this ->getGuardNames ();
142- $ given = $ permission ->guard_name ;
138+ $ given = $ permission ->guard_name ;
143139
144140 throw new GuardDoesNotMatch ($ this ->helpers ->getGuardDoesNotMatchMessage ($ expected , $ given ));
145141 }
0 commit comments