From 667e1bc0e70a09ca25cd78d4183302d2a3e5b62f Mon Sep 17 00:00:00 2001 From: HDVinnie Date: Thu, 13 Feb 2020 10:06:41 -0500 Subject: [PATCH 1/2] refactor: simplify useless variables --- app/Console/Commands/DemoSeed.php | 4 +-- app/Helpers/Markdown.php | 48 ++++++++--------------------- app/Helpers/MediaInfo.php | 3 +- app/Models/Post.php | 3 +- app/Models/Torrent.php | 3 +- app/Models/UserNotification.php | 8 ++--- app/Models/UserPrivacy.php | 8 ++--- app/Services/Clients/OmdbClient.php | 4 +-- app/Services/Clients/TmdbClient.php | 4 +-- app/Traits/Encryptable.php | 4 +-- app/Traits/TwoStep.php | 4 +-- 11 files changed, 24 insertions(+), 69 deletions(-) diff --git a/app/Console/Commands/DemoSeed.php b/app/Console/Commands/DemoSeed.php index 4ef46b8e49..b52cf25ae8 100644 --- a/app/Console/Commands/DemoSeed.php +++ b/app/Console/Commands/DemoSeed.php @@ -121,9 +121,7 @@ private function search($id) $client = new \App\Services\MovieScrapper(config('api-keys.tmdb'), config('api-keys.tvdb'), config('api-keys.omdb')); - $meta = $client->scrape('movie', null, $id); - - return $meta; + return $client->scrape('movie', null, $id); } private function ids() diff --git a/app/Helpers/Markdown.php b/app/Helpers/Markdown.php index 7d7f74cff1..8dbbf56373 100644 --- a/app/Helpers/Markdown.php +++ b/app/Helpers/Markdown.php @@ -267,11 +267,9 @@ protected function lines(array $lines) $markup .= isset($Block['markup']) ? $Block['markup'] : $this->element($Block['element']); } - $markup .= "\n"; - // ~ - return $markup; + return $markup . "\n"; } protected function isBlockContinuable($Type) @@ -296,7 +294,7 @@ protected function blockCode($Line, $Block = null) if ($Line['indent'] >= 4) { $text = substr($Line['body'], 4); - $Block = [ + return [ 'element' => [ 'name' => 'pre', 'handler' => 'element', @@ -306,8 +304,6 @@ protected function blockCode($Line, $Block = null) ], ], ]; - - return $Block; } } @@ -395,7 +391,7 @@ protected function blockFencedCode($Line) ]; } - $Block = [ + return [ 'char' => $Line['text'][0], 'element' => [ 'name' => 'pre', @@ -403,8 +399,6 @@ protected function blockFencedCode($Line) 'text' => $Element, ], ]; - - return $Block; } } @@ -460,15 +454,13 @@ protected function blockHeader($Line) $text = trim($Line['text'], '# '); - $Block = [ + return [ 'element' => [ 'name' => 'h'.min(6, $level), 'text' => $text, 'handler' => 'line', ], ]; - - return $Block; } } @@ -583,15 +575,13 @@ protected function blockListComplete(array $Block) protected function blockQuote($Line) { if (preg_match('/^>[ ]?(.*)/', $Line['text'], $matches)) { - $Block = [ + return [ 'element' => [ 'name' => 'blockquote', 'handler' => 'lines', 'text' => (array) $matches[1], ], ]; - - return $Block; } } @@ -622,13 +612,11 @@ protected function blockQuoteContinue($Line, array $Block) protected function blockRule($Line) { if (preg_match('/^(['.$Line['text'][0].'])([ ]*\1){2,}[ ]*$/', $Line['text'])) { - $Block = [ + return [ 'element' => [ 'name' => 'hr', ], ]; - - return $Block; } } @@ -742,11 +730,9 @@ protected function blockReference($Line) $this->DefinitionData['Reference'][$id] = $Data; - $Block = [ + return [ 'hidden' => true, ]; - - return $Block; } } @@ -904,15 +890,13 @@ protected function blockTableContinue($Line, array $Block) protected function paragraph($Line) { - $Block = [ + return [ 'element' => [ 'name' => 'p', 'text' => $Line['text'], 'handler' => 'line', ], ]; - - return $Block; } // @@ -1010,9 +994,7 @@ public function line($text, $nonNestables = []) $text = substr($text, $markerPosition + 1); } - $markup .= $this->unmarkedText($text); - - return $markup; + return $markup . $this->unmarkedText($text); } // @@ -1262,7 +1244,7 @@ protected function inlineUrl($Excerpt) if (preg_match('/\bhttps?:[\/]{2}[^\s<]+\b\/*/ui', $Excerpt['context'], $matches, PREG_OFFSET_CAPTURE)) { $url = $matches[0][0]; - $Inline = [ + return [ 'extent' => strlen($matches[0][0]), 'position' => $matches[0][1], 'element' => [ @@ -1273,8 +1255,6 @@ protected function inlineUrl($Excerpt) ], ], ]; - - return $Inline; } } @@ -1359,9 +1339,7 @@ protected function elements(array $Elements) $markup .= "\n".$this->element($Element); } - $markup .= "\n"; - - return $markup; + return $markup . "\n"; } // ~ @@ -1390,9 +1368,7 @@ protected function li($lines) public function parse($text) { - $markup = $this->text($text); - - return $markup; + return $this->text($text); } protected function sanitiseElement(array $Element) diff --git a/app/Helpers/MediaInfo.php b/app/Helpers/MediaInfo.php index f754e2598f..053994b84f 100755 --- a/app/Helpers/MediaInfo.php +++ b/app/Helpers/MediaInfo.php @@ -303,9 +303,8 @@ private function parseFileSize($string) private function parseBitRate($string) { $string = str_replace(' ', '', strtolower($string)); - $string = str_replace('kbps', ' kbps', $string); - return $string; + return str_replace('kbps', ' kbps', $string); } private function parseWidthHeight($string) diff --git a/app/Models/Post.php b/app/Models/Post.php index 72b5390c74..0ab8e16575 100644 --- a/app/Models/Post.php +++ b/app/Models/Post.php @@ -173,8 +173,7 @@ public function getPostNumber() public function getPageNumber() { $result = ($this->getPostNumber() - 1) / 25 + 1; - $result = floor($result); - return $result; + return floor($result); } } diff --git a/app/Models/Torrent.php b/app/Models/Torrent.php index 3a67dfc1d4..600e94b737 100644 --- a/app/Models/Torrent.php +++ b/app/Models/Torrent.php @@ -383,9 +383,8 @@ public function setMediaInfoAttribute($value) public function getMediaInfo() { $parser = new MediaInfo(); - $parsed = $parser->parse($this->mediaInfo); - return $parsed; + return $parser->parse($this->mediaInfo); } /** diff --git a/app/Models/UserNotification.php b/app/Models/UserNotification.php index 22d5b4b902..a8c86d344d 100644 --- a/app/Models/UserNotification.php +++ b/app/Models/UserNotification.php @@ -137,9 +137,7 @@ public function user() */ public function getExpectedGroupsAttribute() { - $expected_groups = ['default_groups' => ['1' => 0]]; - - return $expected_groups; + return ['default_groups' => ['1' => 0]]; } /** @@ -149,9 +147,7 @@ public function getExpectedGroupsAttribute() */ public function getExpectedFieldsAttribute() { - $expected_fields = []; - - return $expected_fields; + return []; } /** diff --git a/app/Models/UserPrivacy.php b/app/Models/UserPrivacy.php index 8fe6e87230..3794f7a9cd 100644 --- a/app/Models/UserPrivacy.php +++ b/app/Models/UserPrivacy.php @@ -167,9 +167,7 @@ public function user() */ public function getExpectedGroupsAttribute() { - $expected_groups = ['default_groups' => ['1' => 0]]; - - return $expected_groups; + return ['default_groups' => ['1' => 0]]; } /** @@ -179,9 +177,7 @@ public function getExpectedGroupsAttribute() */ public function getExpectedFieldsAttribute() { - $expected_fields = []; - - return $expected_fields; + return []; } /** diff --git a/app/Services/Clients/OmdbClient.php b/app/Services/Clients/OmdbClient.php index 308687e988..865daeefba 100755 --- a/app/Services/Clients/OmdbClient.php +++ b/app/Services/Clients/OmdbClient.php @@ -36,15 +36,13 @@ public function find($keys, $type = null) $result = $this->toArray($this->request($url)); if (isset($result['Response']) && $result['Response'] == 'True') { - $result = array_map(function ($value) { + return array_map(function ($value) { if ($value == 'N/A') { return; } return $value; }, $result); - - return $result; } } diff --git a/app/Services/Clients/TmdbClient.php b/app/Services/Clients/TmdbClient.php index d5e1f79b07..fe5b002145 100755 --- a/app/Services/Clients/TmdbClient.php +++ b/app/Services/Clients/TmdbClient.php @@ -354,15 +354,13 @@ private function formatImages($images, $path, $image) return $path.$item['file_path']; }, $images); - $images = array_filter($images, function ($item) use ($path, $image) { + return array_filter($images, function ($item) use ($path, $image) { if ($item == $path.$image) { return false; } return true; }); - - return $images; } private function formatCasts($credits, $role) diff --git a/app/Traits/Encryptable.php b/app/Traits/Encryptable.php index 80ac830f9d..19ee5fc948 100644 --- a/app/Traits/Encryptable.php +++ b/app/Traits/Encryptable.php @@ -22,9 +22,7 @@ public function getAttribute($key) $value = parent::getAttribute($key); if (in_array($key, $this->encryptable)) { - $value = Crypt::decrypt($value); - - return $value; + return Crypt::decrypt($value); } return $value; diff --git a/app/Traits/TwoStep.php b/app/Traits/TwoStep.php index 9b53890d4c..1d053fb82d 100644 --- a/app/Traits/TwoStep.php +++ b/app/Traits/TwoStep.php @@ -114,7 +114,7 @@ private function generateCode(int $length = 4, string $prefix = '', string $suff */ private function checkTwoStepAuthStatus(int $userId) { - $twoStepAuth = TwoStepAuth::firstOrCreate( + return TwoStepAuth::firstOrCreate( [ 'userId' => $userId, ], @@ -124,8 +124,6 @@ private function checkTwoStepAuthStatus(int $userId) 'authCount' => 0, ] ); - - return $twoStepAuth; } /** From d41e7da5e3f7d98b843c1625cf1ec8a580ae2171 Mon Sep 17 00:00:00 2001 From: HDVinnie Date: Thu, 13 Feb 2020 10:16:34 -0500 Subject: [PATCH 2/2] chore: styleci --- app/Helpers/Markdown.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Helpers/Markdown.php b/app/Helpers/Markdown.php index 8dbbf56373..e8a384eed0 100644 --- a/app/Helpers/Markdown.php +++ b/app/Helpers/Markdown.php @@ -269,7 +269,7 @@ protected function lines(array $lines) // ~ - return $markup . "\n"; + return $markup."\n"; } protected function isBlockContinuable($Type) @@ -994,7 +994,7 @@ public function line($text, $nonNestables = []) $text = substr($text, $markerPosition + 1); } - return $markup . $this->unmarkedText($text); + return $markup.$this->unmarkedText($text); } // @@ -1339,7 +1339,7 @@ protected function elements(array $Elements) $markup .= "\n".$this->element($Element); } - return $markup . "\n"; + return $markup."\n"; } // ~