22
33namespace Akaunting \Menu ;
44
5+ use Akaunting \Menu \MenuBuilder ;
56use Closure ;
67use Countable ;
78use Illuminate \Contracts \Config \Repository ;
89use Illuminate \View \Factory ;
910
1011class Menu implements Countable
1112{
12- /**
13- * The menu collections.
14- *
15- * @var array
16- */
17- protected $ menu = [];
18- /**
19- * @var Repository
20- */
21- private $ config ;
22- /**
23- * @var Factory
24- */
25- private $ views ;
13+ protected array $ menu = [];
14+
15+ protected Repository $ config ;
16+
17+ protected Factory $ views ;
2618
27- /**
28- * The constructor.
29- *
30- * @param Factory $views
31- * @param Repository $config
32- */
3319 public function __construct (Factory $ views , Repository $ config )
3420 {
3521 $ this ->views = $ views ;
@@ -38,26 +24,16 @@ public function __construct(Factory $views, Repository $config)
3824
3925 /**
4026 * Make new menu.
41- *
42- * @param string $name
43- * @param Closure $callback
44- *
45- * @return \Akaunting\Menu\MenuBuilder
4627 */
47- public function make ($ name , \ Closure $ callback )
28+ public function make (string $ name , Closure $ callback ): mixed
4829 {
4930 return $ this ->create ($ name , $ callback );
5031 }
5132
5233 /**
5334 * Create new menu.
54- *
55- * @param string $name
56- * @param Callable $resolver
57- *
58- * @return \Akaunting\Menu\MenuBuilder
5935 */
60- public function create ($ name , Closure $ resolver )
36+ public function create (string $ name , Closure $ resolver ): mixed
6137 {
6238 $ builder = new MenuBuilder ($ name , $ this ->config );
6339
@@ -70,36 +46,24 @@ public function create($name, Closure $resolver)
7046
7147 /**
7248 * Check if the menu exists.
73- *
74- * @param string $name
75- *
76- * @return bool
7749 */
78- public function has ($ name )
50+ public function has (string $ name ): bool
7951 {
8052 return array_key_exists ($ name , $ this ->menu );
8153 }
8254
8355 /**
8456 * Get instance of the given menu if exists.
85- *
86- * @param string $name
87- *
88- * @return string|null
8957 */
90- public function instance ($ name )
58+ public function instance (string $ name ): ? MenuBuilder
9159 {
9260 return $ this ->has ($ name ) ? $ this ->menu [$ name ] : null ;
9361 }
9462
9563 /**
9664 * Modify a specific menu.
97- *
98- * @param string $name
99- * @param Closure $callback
100- * @return void
10165 */
102- public function modify ($ name , Closure $ callback )
66+ public function modify (string $ name , Closure $ callback ): void
10367 {
10468 $ menu = collect ($ this ->menu )->filter (function ($ menu ) use ($ name ) {
10569 return $ menu ->getName () == $ name ;
@@ -110,55 +74,39 @@ public function modify($name, Closure $callback)
11074
11175 /**
11276 * Render the menu tag by given name.
113- *
114- * @param string $name
115- * @param string $presenter
116- *
117- * @return string|null
11877 */
119- public function get ($ name , $ presenter = null , $ bindings = [])
78+ public function get (string $ name , ? string $ presenter = null , array $ bindings = []): ? string
12079 {
12180 return $ this ->has ($ name ) ?
12281 $ this ->menu [$ name ]->setBindings ($ bindings )->render ($ presenter ) : null ;
12382 }
12483
12584 /**
12685 * Render the menu tag by given name.
127- *
128- * @param $name
129- * @param null $presenter
130- *
131- * @return string
13286 */
133- public function render ($ name , $ presenter = null , $ bindings = [])
87+ public function render (string $ name , ? string $ presenter = null , array $ bindings = []): ? string
13488 {
13589 return $ this ->get ($ name , $ presenter , $ bindings );
13690 }
13791
13892 /**
13993 * Get a stylesheet for enable multilevel menu.
140- *
141- * @return mixed
14294 */
143- public function style ()
95+ public function style (): mixed
14496 {
14597 return $ this ->views ->make ('menu::bootstrap3.style ' )->render ();
14698 }
14799
148100 /**
149101 * Get all menus.
150- *
151- * @return array
152102 */
153- public function all ()
103+ public function all (): array
154104 {
155105 return $ this ->menu ;
156106 }
157107
158108 /**
159109 * Count menus.
160- *
161- * @return int
162110 */
163111 public function count (): int
164112 {
@@ -168,7 +116,7 @@ public function count(): int
168116 /**
169117 * Empty the current menus.
170118 */
171- public function destroy ()
119+ public function destroy (): void
172120 {
173121 $ this ->menu = [];
174122 }
0 commit comments