77use Illuminate \Database \Eloquent \Model ;
88use Illuminate \Foundation \Application ;
99use Illuminate \Support \Collection ;
10+ use Illuminate \Support \Facades \Config ;
1011use Illuminate \Support \Facades \DB ;
1112use Illuminate \Support \Str ;
1213use Laravel \Tinker \ClassAliasAutoloader ;
1314use Psy \Configuration ;
1415use Psy \ExecutionLoopClosure ;
1516use Psy \Shell ;
1617use Symfony \Component \Console \Output \BufferedOutput ;
17- use Illuminate \Support \Facades \Config ;
1818
1919/**
2020 * Taken from https://github.com/spatie/laravel-web-tinker/blob/master/src/Tinker.php
@@ -52,7 +52,7 @@ public function execute(string $phpCode): string
5252 $ resultVars = $ this ->shell ->getScopeVariables ();
5353
5454 // Detect db write exception
55- if (!$ this ->lastExecSuccess () && isset ($ resultVars ['_e ' ])) {
55+ if (! $ this ->lastExecSuccess () && isset ($ resultVars ['_e ' ])) {
5656 $ lastException = $ resultVars ['_e ' ];
5757 if (get_class ($ lastException ) === 'Illuminate\Database\QueryException ' ) {
5858 if (Str::of ($ lastException ->getMessage ())->contains (self ::FAKE_WRITE_HOST )) {
@@ -72,18 +72,20 @@ public function execute(string $phpCode): string
7272 /**
7373 * Get the content of result variable
7474 */
75- public function getCustomCodeResult () {
76- if (!$ this ->lastExecSuccess ()) {
75+ public function getCustomCodeResult ()
76+ {
77+ if (! $ this ->lastExecSuccess ()) {
7778 return null ;
7879 }
7980
8081 try {
8182 $ result = $ this ->shell ->getScopeVariable ('result ' );
8283 } catch (\Exception $ exception ) {
8384 ray ($ exception );
85+
8486 return null ;
8587 }
86- if ($ result && !empty ($ result ) ) {
88+ if ($ result && ! empty ($ result )) {
8789 return $ result ;
8890 }
8991
@@ -93,26 +95,29 @@ public function getCustomCodeResult() {
9395 /**
9496 * Check if last execution worked without exceptions
9597 */
96- public function lastExecSuccess () {
98+ public function lastExecSuccess ()
99+ {
97100 return $ this ->shell ->getLastExecSuccess ();
98101 }
99102
100103 /**
101104 * Prevents unwanted database modifications by enabling creating and using a readonly connection.
102105 */
103- public function readonly () {
106+ public function readonly ()
107+ {
104108 $ defaultConnection = config ('database.default ' );
105109 $ databaseConnection = Config::get ('database.connections. ' .$ defaultConnection );
106110 $ host = $ databaseConnection ['host ' ];
107111 unset($ databaseConnection ['host ' ]);
108112 $ databaseConnection ['read ' ] = [
109- 'host ' => $ host
113+ 'host ' => $ host,
110114 ];
111115 $ databaseConnection ['write ' ] = [
112- 'host ' => self ::FAKE_WRITE_HOST
116+ 'host ' => self ::FAKE_WRITE_HOST ,
113117 ];
114- Config::set ('database.connections.readonly ' ,$ databaseConnection );
118+ Config::set ('database.connections.readonly ' , $ databaseConnection );
115119 DB ::setDefaultConnection ('readonly ' );
120+
116121 return $ this ;
117122 }
118123
0 commit comments