Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Refactor) Code Quality and Style #1412

Merged
merged 13 commits into from
Jul 27, 2020
Merged

(Refactor) Code Quality and Style #1412

merged 13 commits into from
Jul 27, 2020

Conversation

HDVinnie
Copy link
Collaborator

Refactors Performed In This Pull Request

Use Identical Over Equal With Same Type Refactor

Use ===/!== over ==/!=, it values have the same type

 class SomeClass
 {
     public function run(int $firstValue, int $secondValue)
     {
-         $isSame = $firstValue == $secondValue;
-         $isDiffernt = $firstValue != $secondValue;
+         $isSame = $firstValue === $secondValue;
+         $isDiffernt = $firstValue !== $secondValue;
     }
 }

Callable This Array To Anonymous Function Refactor

Convert [$this, "method"] to proper anonymous function

 class SomeClass
 {
     public function run()
     {
         $values = [1, 5, 3];
-        usort($values, [$this, 'compareSize']);
+        usort($values, function ($first, $second) {
+            return $this->compareSize($first, $second);
+        });

         return $values;
     }

     private function compareSize($first, $second)
     {
         return $first <=> $second;
     }
 }

Rename Property To Match Type Refactor

Rename property and method param to match its type

 class SomeClass
 {
     /**
      * @var EntityManager
      */
-    private $eventManager;
+    private $entityManager;

-    public function __construct(EntityManager $eventManager)
+    public function __construct(EntityManager $entityManager)
     {
-        $this->eventManager = $eventManager;
+        $this->entityManager = $entityManager;
     }
 }

Preslash Simple Functions Refactor

Add pre-slash to short named functions to improve performance

 class SomeClass
 {
     public function shorten($value)
     {
-        return trim($value);
+        return \trim($value);
     }
 }

Recasting Removal Refactor

Removes recasting of the same type

 $string = '';
-$string = (string) $string;
+$string = $string;

 $array = [];
-$array = (array) $array;
+$array = $array;

@codecov
Copy link

codecov bot commented Jul 22, 2020

Codecov Report

Merging #1412 into master will decrease coverage by 1.26%.
The diff coverage is 23.13%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1412      +/-   ##
============================================
- Coverage     27.21%   25.95%   -1.27%     
- Complexity     4280     4283       +3     
============================================
  Files           306      306              
  Lines         13471    13479       +8     
============================================
- Hits           3666     3498     -168     
- Misses         9805     9981     +176     
Impacted Files Coverage Δ Complexity Δ
app/Bots/CasinoBot.php 0.00% <0.00%> (ø) 42.00 <9.00> (ø)
app/Bots/IRCAnnounceBot.php 0.00% <0.00%> (ø) 16.00 <0.00> (ø)
app/Bots/NerdBot.php 0.00% <0.00%> (ø) 93.00 <23.00> (ø)
app/Console/Commands/AutoBanDisposableUsers.php 0.00% <0.00%> (ø) 3.00 <0.00> (ø)
app/Console/Commands/AutoBonAllocation.php 76.47% <0.00%> (ø) 24.00 <0.00> (ø)
app/Console/Commands/AutoDeactivateWarning.php 38.46% <ø> (ø) 2.00 <0.00> (ø)
app/Console/Commands/AutoGroup.php 15.00% <0.00%> (ø) 37.00 <0.00> (ø)
app/Console/Commands/AutoRecycleFailedLogins.php 83.33% <ø> (ø) 2.00 <0.00> (ø)
app/Console/Commands/AutoRecycleInvites.php 83.33% <ø> (ø) 2.00 <0.00> (ø)
...p/Console/Commands/AutoRemovePersonalFreeleech.php 41.66% <ø> (ø) 2.00 <0.00> (ø)
... and 232 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c6511cf...10befaa. Read the comment docs.

@HDVinnie HDVinnie removed the WIP label Jul 23, 2020
@HDVinnie HDVinnie merged commit 7bbaa2e into master Jul 27, 2020
@HDVinnie HDVinnie deleted the Code-Refactor branch July 27, 2020 03:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant