@@ -35,7 +35,7 @@ class Adapter implements AdapterContract
3535 *
3636 * @param array $config
3737 */
38- public function __construct ($ config )
38+ public function __construct (array $ config )
3939 {
4040 $ database = new Medoo ($ config );
4141 $ this ->database = $ database ;
@@ -50,7 +50,7 @@ public function __construct($config)
5050 *
5151 * @return Adapter
5252 */
53- public static function newAdapter ($ config )
53+ public static function newAdapter (array $ config )
5454 {
5555 return new static ($ config );
5656 }
@@ -73,22 +73,32 @@ public function initTable()
7373 ]);
7474 }
7575
76- public function savePolicyLine ($ ptype , array $ rule )
76+ /**
77+ * savePolicyLine function.
78+ *
79+ * @param string $ptype
80+ * @param array $rule
81+ *
82+ * @return void
83+ */
84+ public function savePolicyLine (string $ ptype , array $ rule ): void
7785 {
7886 $ data = [];
7987 foreach ($ rule as $ key => $ value ) {
80- $ data ['v ' . strval ($ key )] = $ value ;
88+ $ data ['v ' . strval ($ key )] = $ value ;
8189 }
8290
83- return $ this ->database ->insert ($ this ->casbinRuleTableName , $ data );
91+ $ this ->database ->insert ($ this ->casbinRuleTableName , $ data );
8492 }
8593
8694 /**
8795 * loads all policy rules from the storage.
8896 *
8997 * @param Model $model
98+ *
99+ * @return void
90100 */
91- public function loadPolicy ($ model )
101+ public function loadPolicy (Model $ model ): void
92102 {
93103 $ data = $ this ->database ->select ($ this ->casbinRuleTableName , ['ptype ' , 'v0 ' , 'v1 ' , 'v2 ' , 'v3 ' , 'v4 ' , 'v5 ' ]);
94104 foreach ($ data as $ row ) {
@@ -104,22 +114,20 @@ public function loadPolicy($model)
104114 *
105115 * @param Model $model
106116 *
107- * @return bool
117+ * @return void
108118 */
109- public function savePolicy ($ model )
119+ public function savePolicy (Model $ model ): void
110120 {
111- foreach ($ model-> model ['p ' ] as $ ptype => $ ast ) {
121+ foreach ($ model ['p ' ] as $ ptype => $ ast ) {
112122 foreach ($ ast ->policy as $ rule ) {
113123 $ this ->savePolicyLine ($ ptype , $ rule );
114124 }
115125 }
116- foreach ($ model-> model ['g ' ] as $ ptype => $ ast ) {
126+ foreach ($ model ['g ' ] as $ ptype => $ ast ) {
117127 foreach ($ ast ->policy as $ rule ) {
118128 $ this ->savePolicyLine ($ ptype , $ rule );
119129 }
120130 }
121-
122- return true ;
123131 }
124132
125133 /**
@@ -130,11 +138,11 @@ public function savePolicy($model)
130138 * @param string $ptype
131139 * @param array $rule
132140 *
133- * @return mixed
141+ * @return void
134142 */
135- public function addPolicy ($ sec , $ ptype , $ rule )
143+ public function addPolicy (string $ sec , string $ ptype , array $ rule ): void
136144 {
137- return $ this ->savePolicyLine ($ ptype , $ rule );
145+ $ this ->savePolicyLine ($ ptype , $ rule );
138146 }
139147
140148 /**
@@ -144,17 +152,17 @@ public function addPolicy($sec, $ptype, $rule)
144152 * @param string $ptype
145153 * @param array $rule
146154 *
147- * @return mixed
155+ * @return void
148156 */
149- public function removePolicy ($ sec , $ ptype , $ rule )
157+ public function removePolicy (string $ sec , string $ ptype , array $ rule ): void
150158 {
151159 $ where ['ptype ' ] = $ ptype ;
152160
153161 foreach ($ rule as $ key => $ value ) {
154162 $ where ['v ' .strval ($ key )] = $ value ;
155163 }
156164
157- return $ this ->database ->delete ($ this ->casbinRuleTableName , ['AND ' => $ where ]);
165+ $ this ->database ->delete ($ this ->casbinRuleTableName , ['AND ' => $ where ]);
158166 }
159167
160168 /**
@@ -163,12 +171,12 @@ public function removePolicy($sec, $ptype, $rule)
163171 *
164172 * @param string $sec
165173 * @param string $ptype
166- * @param int $fieldIndex
167- * @param mixed ...$fieldValues
174+ * @param int $fieldIndex
175+ * @param string ...$fieldValues
168176 *
169- * @return mixed
177+ * @return void
170178 */
171- public function removeFilteredPolicy ($ sec , $ ptype , $ fieldIndex , ...$ fieldValues )
179+ public function removeFilteredPolicy (string $ sec , string $ ptype , int $ fieldIndex , string ...$ fieldValues ): void
172180 {
173181 $ where ['ptype ' ] = $ ptype ;
174182
@@ -180,7 +188,7 @@ public function removeFilteredPolicy($sec, $ptype, $fieldIndex, ...$fieldValues)
180188 }
181189 }
182190
183- return $ this ->database ->delete ($ this ->casbinRuleTableName , ['AND ' => $ where ]);
191+ $ this ->database ->delete ($ this ->casbinRuleTableName , ['AND ' => $ where ]);
184192 }
185193
186194 /**
0 commit comments