Conditions | 5 |
Paths | 9 |
Total Lines | 67 |
Code Lines | 41 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
67 | public function handle() |
||
68 | { |
||
69 | if (!$this->verifyAccessToken()) { |
||
70 | $this->error('Invalid access token.'); |
||
71 | |||
72 | return 1; |
||
73 | } |
||
74 | $this->line('Full export is running...'); |
||
75 | // make repositories |
||
76 | /** @var UserRepositoryInterface $userRepository */ |
||
77 | $userRepository = app(UserRepositoryInterface::class); |
||
78 | /** @var ExportJobRepositoryInterface $jobRepository */ |
||
79 | $jobRepository = app(ExportJobRepositoryInterface::class); |
||
80 | /** @var AccountRepositoryInterface $accountRepository */ |
||
81 | $accountRepository = app(AccountRepositoryInterface::class); |
||
82 | /** @var JournalRepositoryInterface $journalRepository */ |
||
83 | $journalRepository = app(JournalRepositoryInterface::class); |
||
84 | |||
85 | // set user |
||
86 | $user = $userRepository->findNull((int)$this->option('user')); |
||
87 | $jobRepository->setUser($user); |
||
88 | $journalRepository->setUser($user); |
||
89 | $accountRepository->setUser($user); |
||
90 | |||
91 | // first date |
||
92 | $firstJournal = $journalRepository->first(); |
||
93 | $first = new Carbon; |
||
94 | if (null !== $firstJournal->id) { |
||
95 | $first = $firstJournal->date; |
||
96 | } |
||
97 | |||
98 | // create job and settings. |
||
99 | $job = $jobRepository->create(); |
||
100 | $settings = [ |
||
101 | 'accounts' => $accountRepository->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT]), |
||
102 | 'startDate' => $first, |
||
103 | 'endDate' => new Carbon, |
||
104 | 'exportFormat' => 'csv', |
||
105 | 'includeAttachments' => $this->option('with_attachments'), |
||
106 | 'includeOldUploads' => $this->option('with_uploads'), |
||
107 | 'job' => $job, |
||
108 | ]; |
||
109 | |||
110 | /** @var ProcessorInterface $processor */ |
||
111 | $processor = app(ProcessorInterface::class); |
||
112 | $processor->setSettings($settings); |
||
113 | |||
114 | $processor->collectJournals(); |
||
115 | $processor->convertJournals(); |
||
116 | $processor->exportJournals(); |
||
117 | if ($settings['includeAttachments']) { |
||
118 | $processor->collectAttachments(); |
||
119 | } |
||
120 | |||
121 | if ($settings['includeOldUploads']) { |
||
122 | $processor->collectOldUploads(); |
||
123 | } |
||
124 | |||
125 | $processor->createZipFile(); |
||
126 | $disk = Storage::disk('export'); |
||
127 | $fileName = sprintf('export-%s.zip', date('Y-m-d_H-i-s')); |
||
128 | $disk->move($job->key . '.zip', $fileName); |
||
129 | |||
130 | $this->line('The export has finished! You can find the ZIP file in this location:'); |
||
131 | $this->line(storage_path(sprintf('export/%s', $fileName))); |
||
132 | |||
133 | return 0; |
||
134 | } |
||
136 |