Conditions | 4 |
Paths | 6 |
Total Lines | 73 |
Code Lines | 46 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 1 | 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 |
||
49 | public function handle() |
||
50 | { |
||
51 | $cid = $this->cid; |
||
52 | $config = $this->config; |
||
53 | $accessToken = Str::random(32); |
||
54 | |||
55 | Cache::tags(['contest', 'pdfViewAccess', $cid])->put($accessToken, $config); |
||
56 | |||
57 | if (!is_dir(storage_path("app/contest/pdf/"))) { |
||
58 | mkdir(storage_path("app/contest/pdf/"), 0777, true); |
||
59 | } |
||
60 | |||
61 | $record = Contest::find($cid); |
||
62 | |||
63 | $puppeteer = new Puppeteer; |
||
64 | $browser = $puppeteer->launch([ |
||
65 | 'args' => ['--no-sandbox', '--disable-setuid-sandbox'], |
||
66 | ]); |
||
67 | |||
68 | $page = $browser->newPage(); |
||
69 | |||
70 | $response = $page->goto(route('contest.board.admin.pdf.view', [ |
||
71 | 'cid' => $cid, |
||
72 | 'accessToken' => $accessToken, |
||
73 | ]), [ |
||
74 | 'waitUntil' => 'networkidle0' |
||
75 | ]); |
||
76 | |||
77 | if($response->status() != '200') { |
||
78 | throw new Exception('Cannot Access PDF Generated View Stream'); |
||
79 | } |
||
80 | |||
81 | $page->waitForSelector('body.rendered', [ |
||
82 | 'timeout' => 120000 |
||
83 | ]); |
||
84 | |||
85 | if($config['renderer'] == 'blink') { |
||
86 | $page->pdf([ |
||
87 | 'format' => 'A4', |
||
88 | 'path' => storage_path("app/contest/pdf/$cid.pdf"), |
||
89 | 'printBackground' => true |
||
90 | ]); |
||
91 | |||
92 | $browser->close(); |
||
93 | |||
94 | $record->pdf = 1; |
||
95 | $record->save(); |
||
96 | return; |
||
97 | } |
||
98 | |||
99 | $parsedHTML = $page->content(); |
||
100 | |||
101 | $browser->close(); |
||
102 | |||
103 | $pdf=PDF::setOptions([ |
||
104 | 'dpi' => 96, |
||
105 | 'isPhpEnabled' => true, |
||
106 | 'isHtml5ParserEnabled' => true, |
||
107 | 'isRemoteEnabled' => true |
||
108 | ])->setWarnings(false)->loadHTML($parsedHTML); |
||
109 | |||
110 | $pdf->output(); |
||
111 | |||
112 | $pdf->addInfo([ |
||
113 | 'Subject' => "$record->name ProblemSet", |
||
114 | 'Producer' => config('app.displayName'), |
||
115 | 'Creator' => config('app.name').' Contest PDF Auto-Generater', |
||
116 | 'CreatorTool' => config('app.url'), |
||
117 | 'BaseURL' => route('contest.detail', ['cid' => $cid]), |
||
118 | ])->save(storage_path("app/contest/pdf/$cid.pdf")); |
||
119 | |||
120 | $record->pdf = 1; |
||
121 | $record->save(); |
||
122 | } |
||
128 |