| Conditions | 8 |
| Paths | 85 |
| Total Lines | 90 |
| Code Lines | 51 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 41 | public function handle(): int |
||
| 42 | { |
||
| 43 | $this->colorCli = new ColorCLI; |
||
| 44 | |||
| 45 | try { |
||
| 46 | $this->colorCli->header('Starting Tmux Processing'); |
||
| 47 | |||
| 48 | // Get session name |
||
| 49 | $sessionName = $this->option('session') |
||
| 50 | ?? Settings::settingValue('tmux_session') |
||
| 51 | ?? config('tmux.session.default_name', 'nntmux'); |
||
| 52 | |||
| 53 | // Initialize services |
||
| 54 | $this->sessionManager = new TmuxSessionManager($sessionName); |
||
| 55 | $this->layoutBuilder = new TmuxLayoutBuilder($this->sessionManager); |
||
| 56 | |||
| 57 | // Check if tmux is installed |
||
| 58 | if (! $this->checkTmuxInstalled()) { |
||
| 59 | $this->error('❌ tmux is not installed'); |
||
| 60 | |||
| 61 | return Command::FAILURE; |
||
| 62 | } |
||
| 63 | |||
| 64 | // Check if session already exists |
||
| 65 | if ($this->sessionManager->sessionExists()) { |
||
| 66 | if (! $this->option('force')) { |
||
| 67 | $this->error("❌ Session '{$sessionName}' already exists"); |
||
| 68 | if ($this->confirm('Would you like to restart it?', false)) { |
||
| 69 | $this->call('tmux:stop', ['--session' => $sessionName]); |
||
| 70 | sleep(2); |
||
| 71 | } else { |
||
| 72 | return Command::FAILURE; |
||
| 73 | } |
||
| 74 | } else { |
||
| 75 | $this->call('tmux:stop', ['--session' => $sessionName]); |
||
| 76 | sleep(2); |
||
| 77 | } |
||
| 78 | } |
||
| 79 | |||
| 80 | // Reset old collections |
||
| 81 | $this->info('🔄 Resetting old collections...'); |
||
| 82 | $this->resetOldCollections(); |
||
| 83 | |||
| 84 | // Get sequential mode |
||
| 85 | $sequential = (int) (Settings::settingValue('sequential') ?? 0); |
||
| 86 | $this->info("📐 Building layout (mode: {$sequential})"); |
||
| 87 | |||
| 88 | // Build the tmux layout |
||
| 89 | if (! $this->layoutBuilder->buildLayout($sequential)) { |
||
| 90 | $this->error('❌ Failed to build tmux layout'); |
||
| 91 | |||
| 92 | return Command::FAILURE; |
||
| 93 | } |
||
| 94 | |||
| 95 | $this->info('✅ Tmux layout created'); |
||
| 96 | |||
| 97 | // Set running flag |
||
| 98 | Settings::query()->where('name', 'running')->update(['value' => 1]); |
||
| 99 | $this->info('✅ Running flag set'); |
||
| 100 | |||
| 101 | // Start monitor in background |
||
| 102 | $this->info('🚀 Starting monitor...'); |
||
| 103 | $this->startMonitor($sessionName); |
||
| 104 | |||
| 105 | // Select monitor pane (0.0) so attach lands there |
||
| 106 | $paneManager = new \App\Services\Tmux\TmuxPaneManager($sessionName); |
||
| 107 | $paneManager->selectWindow(0); |
||
| 108 | $paneManager->selectPane('0.0'); |
||
| 109 | |||
| 110 | $this->info("✅ Tmux session '{$sessionName}' started successfully"); |
||
| 111 | |||
| 112 | // Attach if requested |
||
| 113 | if ($this->option('attach')) { |
||
| 114 | $this->info('📎 Attaching to session...'); |
||
| 115 | $this->sessionManager->attachSession(); |
||
| 116 | } else { |
||
| 117 | $this->info("💡 To attach to the session, run: tmux attach -t {$sessionName}"); |
||
| 118 | $this->info('💡 Or use: php artisan tmux:attach'); |
||
| 119 | } |
||
| 120 | |||
| 121 | return Command::SUCCESS; |
||
| 122 | |||
| 123 | } catch (\Exception $e) { |
||
| 124 | $this->error('❌ Failed to start tmux: '.$e->getMessage()); |
||
| 125 | logger()->error('Tmux start error', [ |
||
| 126 | 'message' => $e->getMessage(), |
||
| 127 | 'trace' => $e->getTraceAsString(), |
||
| 128 | ]); |
||
| 129 | |||
| 130 | return Command::FAILURE; |
||
| 131 | } |
||
| 200 |