44
55namespace SolumDeSignum \Scenarios ;
66
7- use function config ;
87use Illuminate \Support \Facades \Route ;
8+ use function config ;
9+ use function is_bool ;
910
1011trait Scenarios
1112{
12- /**
13- * @var string
14- */
15- public $ scenario ;
13+ public string $ scenario ;
1614
17- /**
18- * @var string
19- */
20- public $ setMethodFromController ;
15+ public mixed $ setMethodFromController ;
2116
22- /**
23- * @var string
24- */
25- public $ setMethodFromUrl ;
17+ public mixed $ setMethodFromUrl ;
2618
2719 /**
2820 * Create a new rule instance.
@@ -58,18 +50,44 @@ public function __construct()
5850 }
5951 }
6052
53+ private function exceptionOneSetMethod (): void
54+ {
55+ if (
56+ !is_bool ($ this ->setMethodFromController ) ||
57+ !is_bool ($ this ->setMethodFromUrl ) ||
58+ ($ this ->setMethodFromController === false && $ this ->setMethodFromUrl === false )
59+ ) {
60+ throw new \Exception (
61+ 'Please enable at least one setMethod function, LIKE RIGHT NOW !!! '
62+ );
63+ }
64+ }
65+
66+ private function exceptionOnlyOneSetMethod (): void
67+ {
68+ if (
69+ !is_bool ($ this ->setMethodFromController ) ||
70+ !is_bool ($ this ->setMethodFromUrl ) ||
71+ ($ this ->setMethodFromController === true && $ this ->setMethodFromUrl === true )
72+ ) {
73+ throw new \Exception (
74+ 'Please enable only one setMethod function, LIKE RIGHT NOW !!! '
75+ );
76+ }
77+ }
78+
6179 /**
6280 * @param $method
6381 *
82+ * @return string
6483 * @throws \Exception
6584 *
66- * @return string
6785 */
6886 public function patternFilter ($ method ): string
6987 {
70- \ preg_match_all (
88+ preg_match_all (
7189 config ('scenarios.methods.pattern ' ),
72- \mb_strtolower ($ method ),
90+ strtolower ($ method ),
7391 $ matches
7492 );
7593
@@ -78,6 +96,20 @@ public function patternFilter($method): string
7896 return $ matches [0 ][0 ];
7997 }
8098
99+ /**
100+ * @param mixed $matches
101+ *
102+ * @throws \Exception
103+ */
104+ private function exceptionScenarioPattern ($ matches ): void
105+ {
106+ if (!isset ($ matches )) {
107+ throw new \Exception (
108+ 'Scenarios patternFilter failed finding match, check $scenarioPattern , LIKE RIGHT NOW !!! '
109+ );
110+ }
111+ }
112+
81113 /**
82114 * @return string|null
83115 */
@@ -97,44 +129,4 @@ public function currentRequestUri(): ?string
97129 Route::getCurrentRequest ()->getRequestUri () :
98130 null ;
99131 }
100-
101- /**
102- * @param mixed $matches
103- *
104- * @throws \Exception
105- */
106- private function exceptionScenarioPattern ($ matches ): void
107- {
108- if (isset ($ matches ) === false ) {
109- throw new \Exception (
110- 'Scenarios patternFilter failed finding match, check $scenarioPattern , LIKE RIGHT NOW !!! '
111- );
112- }
113- }
114-
115- private function exceptionOneSetMethod (): void
116- {
117- if (
118- \is_bool ($ this ->setMethodFromController ) === false ||
119- \is_bool ($ this ->setMethodFromUrl ) === false ||
120- ($ this ->setMethodFromController === false && $ this ->setMethodFromUrl === false )
121- ) {
122- throw new \Exception (
123- 'Please enable at least one setMethod function, LIKE RIGHT NOW !!! '
124- );
125- }
126- }
127-
128- private function exceptionOnlyOneSetMethod (): void
129- {
130- if (
131- \is_bool ($ this ->setMethodFromController ) === false ||
132- \is_bool ($ this ->setMethodFromUrl ) === false ||
133- ($ this ->setMethodFromController === true && $ this ->setMethodFromUrl === true )
134- ) {
135- throw new \Exception (
136- 'Please enable only one setMethod function, LIKE RIGHT NOW !!! '
137- );
138- }
139- }
140132}
0 commit comments