From 13a00fc8971841a6d0e17d0b345752210f059ae3 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 4 Nov 2020 00:27:41 +1100 Subject: [PATCH] Redundant code cleanup --- app/Repositories/BaseRepository.php | 37 ------------------- app/Repositories/ClientRepository.php | 12 +----- app/Repositories/CompanyRepository.php | 10 ----- app/Repositories/CreditRepository.php | 9 ----- app/Repositories/DesignRepository.php | 22 +---------- app/Repositories/DocumentRepository.php | 9 ----- app/Repositories/ExpenseRepository.php | 13 ------- app/Repositories/GroupSettingRepository.php | 12 ------ app/Repositories/InvoiceRepository.php | 15 ++------ .../Migration/PaymentMigrationRepository.php | 5 --- app/Repositories/PaymentRepository.php | 9 ----- app/Repositories/ProductRepository.php | 5 --- app/Repositories/ProjectRepository.php | 9 ----- app/Repositories/QuoteRepository.php | 5 --- .../RecurringInvoiceRepository.php | 4 -- app/Repositories/RecurringQuoteRepository.php | 10 +---- app/Repositories/TaskRepository.php | 13 ------- app/Repositories/TokenRepository.php | 10 +---- app/Repositories/UserRepository.php | 13 +------ app/Repositories/VendorRepository.php | 25 +++---------- app/Services/Credit/CreateInvitations.php | 2 +- psalm.xml | 5 +++ 22 files changed, 22 insertions(+), 232 deletions(-) diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index 553b869e51..54ec44405f 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -34,24 +34,6 @@ class BaseRepository use MakesHash; use SavesDocuments; - /** - * @return null - */ - public function getClassName() - { - return null; - } - - /** - * @return mixed - */ - private function getInstance() - { - $className = $this->getClassName(); - - return new $className(); - } - /** * @param $entity * @param $type @@ -153,25 +135,6 @@ class BaseRepository return count($entities); } - /** - * @param $ids - * - * @return mixed - */ - public function findByPublicIds($ids) - { - return $this->getInstance()->scope($ids)->get(); - } - - /** - * @param $ids - * - * @return mixed - */ - public function findByPublicIdsWithTrashed($ids) - { - return $this->getInstance()->scope($ids)->withTrashed()->get(); - } public function getInvitation($invitation, $resource) { diff --git a/app/Repositories/ClientRepository.php b/app/Repositories/ClientRepository.php index 806fa4ba55..e4924f387f 100644 --- a/app/Repositories/ClientRepository.php +++ b/app/Repositories/ClientRepository.php @@ -39,17 +39,7 @@ class ClientRepository extends BaseRepository { $this->contact_repo = $contact_repo; } - - /** - * Gets the class name. - * - * @return string The class name. - */ - public function getClassName() - { - return Client::class; - } - + /** * Saves the client and its contacts. * diff --git a/app/Repositories/CompanyRepository.php b/app/Repositories/CompanyRepository.php index 296e3fba29..b68df6b6e3 100644 --- a/app/Repositories/CompanyRepository.php +++ b/app/Repositories/CompanyRepository.php @@ -23,16 +23,6 @@ class CompanyRepository extends BaseRepository { } - /** - * Gets the class name. - * - * @return string The class name. - */ - public function getClassName() - { - return Company::class; - } - /** * Saves the client and its contacts. * diff --git a/app/Repositories/CreditRepository.php b/app/Repositories/CreditRepository.php index dd2963a316..5092fc8881 100644 --- a/app/Repositories/CreditRepository.php +++ b/app/Repositories/CreditRepository.php @@ -30,15 +30,6 @@ class CreditRepository extends BaseRepository { } - /** - * Gets the class name. - * - * @return string The class name. - */ - public function getClassName() - { - return Credit::class; - } /** * Saves the client and its contacts. diff --git a/app/Repositories/DesignRepository.php b/app/Repositories/DesignRepository.php index 353774e999..97a53dd873 100644 --- a/app/Repositories/DesignRepository.php +++ b/app/Repositories/DesignRepository.php @@ -11,30 +11,10 @@ namespace App\Repositories; -use App\Libraries\MultiDB; -use App\Models\Activity; -use App\Models\Backup; -use App\Models\Client; -use App\Models\Design; -use App\Models\Invoice; -use App\Models\User; -use App\Utils\Traits\MakesInvoiceHtml; -use Illuminate\Support\Facades\Log; - /** - * Class for activity repository. + * Class for DesignRepository . */ class DesignRepository extends BaseRepository { - use MakesInvoiceHtml; - /** - * Gets the class name. - * - * @return string The class name. - */ - public function getClassName() - { - return Design::class; - } } diff --git a/app/Repositories/DocumentRepository.php b/app/Repositories/DocumentRepository.php index 595fcc732d..1c60366f61 100644 --- a/app/Repositories/DocumentRepository.php +++ b/app/Repositories/DocumentRepository.php @@ -19,15 +19,6 @@ use App\Utils\Ninja; */ class DocumentRepository extends BaseRepository { - /** - * Gets the class name. - * - * @return string The class name. - */ - public function getClassName() - { - return Document::class; - } public function delete($document) { diff --git a/app/Repositories/ExpenseRepository.php b/app/Repositories/ExpenseRepository.php index 0044514ffb..310a9315aa 100644 --- a/app/Repositories/ExpenseRepository.php +++ b/app/Repositories/ExpenseRepository.php @@ -24,19 +24,6 @@ class ExpenseRepository extends BaseRepository { use GeneratesCounter; - public function __construct() - { - } - - /** - * Gets the class name. - * - * @return string The class name. - */ - public function getClassName() - { - return Expense::class; - } /** * Saves the expense and its contacts. diff --git a/app/Repositories/GroupSettingRepository.php b/app/Repositories/GroupSettingRepository.php index fd0ebb4d9c..d1aac1dda4 100644 --- a/app/Repositories/GroupSettingRepository.php +++ b/app/Repositories/GroupSettingRepository.php @@ -12,21 +12,9 @@ namespace App\Repositories; use App\Models\GroupSetting; -use App\Utils\Traits\MakesHash; class GroupSettingRepository extends BaseRepository { - use MakesHash; - - /** - * Gets the class name. - * - * @return string The class name. - */ - public function getClassName() - { - return GroupSetting::class; - } public function save($data, GroupSetting $group_setting) :?GroupSetting { diff --git a/app/Repositories/InvoiceRepository.php b/app/Repositories/InvoiceRepository.php index a6d0063680..8a28690291 100644 --- a/app/Repositories/InvoiceRepository.php +++ b/app/Repositories/InvoiceRepository.php @@ -27,23 +27,14 @@ class InvoiceRepository extends BaseRepository { use MakesHash; - /** - * Gets the class name. - * - * @return string The class name. - */ - public function getClassName() - { - return Invoice::class; - } /** * Saves the invoices. * - * @param array. $data The invoice data - * @param InvoiceSum|Invoice $invoice The invoice + * @param array $data The invoice data + * @param Invoice $invoice The invoice * - * @return Invoice|InvoiceSum|null Returns the invoice object + * @return Invoice|null Returns the invoice object */ public function save($data, Invoice $invoice):?Invoice { diff --git a/app/Repositories/Migration/PaymentMigrationRepository.php b/app/Repositories/Migration/PaymentMigrationRepository.php index 632c5ef479..197e4eaac9 100644 --- a/app/Repositories/Migration/PaymentMigrationRepository.php +++ b/app/Repositories/Migration/PaymentMigrationRepository.php @@ -48,11 +48,6 @@ class PaymentMigrationRepository extends BaseRepository $this->activity_repo = new ActivityRepository(); } - public function getClassName() - { - return Payment::class; - } - /** * Saves and updates a payment. //todo refactor to handle refunds and payments. * diff --git a/app/Repositories/PaymentRepository.php b/app/Repositories/PaymentRepository.php index b83851a1ea..de63f2472b 100644 --- a/app/Repositories/PaymentRepository.php +++ b/app/Repositories/PaymentRepository.php @@ -41,15 +41,6 @@ class PaymentRepository extends BaseRepository $this->credit_repo = $credit_repo; } - /** - * @return string - */ - - public function getClassName() - { - return Payment::class; - } - /** * Saves and updates a payment. //todo refactor to handle refunds and payments. * diff --git a/app/Repositories/ProductRepository.php b/app/Repositories/ProductRepository.php index 350c7ebc39..c5c8a1e7c0 100644 --- a/app/Repositories/ProductRepository.php +++ b/app/Repositories/ProductRepository.php @@ -19,11 +19,6 @@ class ProductRepository extends BaseRepository { use SavesDocuments; - public function getClassName() - { - return Product::class; - } - /** * @param array $data * @param Product $product diff --git a/app/Repositories/ProjectRepository.php b/app/Repositories/ProjectRepository.php index b1010bf71d..136ecadf9e 100644 --- a/app/Repositories/ProjectRepository.php +++ b/app/Repositories/ProjectRepository.php @@ -19,13 +19,4 @@ use App\Models\Project; class ProjectRepository extends BaseRepository { - /** - * Gets the class name. - * - * @return string The class name. - */ - public function getClassName() - { - return Project::class; - } } diff --git a/app/Repositories/QuoteRepository.php b/app/Repositories/QuoteRepository.php index e0e70424fd..33aa4e34e5 100644 --- a/app/Repositories/QuoteRepository.php +++ b/app/Repositories/QuoteRepository.php @@ -27,12 +27,7 @@ use Illuminate\Http\Request; */ class QuoteRepository extends BaseRepository { - use MakesHash; - public function getClassName() - { - return Quote::class; - } public function save($data, Quote $quote) : ?Quote { diff --git a/app/Repositories/RecurringInvoiceRepository.php b/app/Repositories/RecurringInvoiceRepository.php index 7ef4d778ab..9658caaaa5 100644 --- a/app/Repositories/RecurringInvoiceRepository.php +++ b/app/Repositories/RecurringInvoiceRepository.php @@ -20,10 +20,6 @@ use Illuminate\Http\Request; */ class RecurringInvoiceRepository extends BaseRepository { - public function getClassName() - { - return RecurringInvoice::class; - } public function save($data, RecurringInvoice $invoice) : ?RecurringInvoice { diff --git a/app/Repositories/RecurringQuoteRepository.php b/app/Repositories/RecurringQuoteRepository.php index 65e218e28d..a0894e8f3a 100644 --- a/app/Repositories/RecurringQuoteRepository.php +++ b/app/Repositories/RecurringQuoteRepository.php @@ -20,10 +20,7 @@ use Illuminate\Http\Request; */ class RecurringQuoteRepository extends BaseRepository { - public function getClassName() - { - return RecurringQuote::class; - } + public function save(Request $request, RecurringQuote $quote) : ?RecurringQuote { @@ -31,13 +28,10 @@ class RecurringQuoteRepository extends BaseRepository $quote->save(); - $quote_calc = new InvoiceSum($quote, $quote->settings); + $quote_calc = new InvoiceSum($quote); $quote = $quote_calc->build()->getQuote(); - //fire events here that cascading from the saving of an Quote - //ie. client balance update... - return $quote; } } diff --git a/app/Repositories/TaskRepository.php b/app/Repositories/TaskRepository.php index 639567c256..75f0e78175 100644 --- a/app/Repositories/TaskRepository.php +++ b/app/Repositories/TaskRepository.php @@ -23,19 +23,6 @@ class TaskRepository extends BaseRepository { use GeneratesCounter; - public function __construct() - { - } - - /** - * Gets the class name. - * - * @return string The class name. - */ - public function getClassName() - { - return Task::class; - } /** * Saves the task and its contacts. diff --git a/app/Repositories/TokenRepository.php b/app/Repositories/TokenRepository.php index 39a559f376..aef6e1e20f 100644 --- a/app/Repositories/TokenRepository.php +++ b/app/Repositories/TokenRepository.php @@ -15,15 +15,7 @@ use App\Models\CompanyToken; class TokenRepository extends BaseRepository { - /** - * Gets the class name. - * - * @return string The class name. - */ - public function getClassName() - { - return CompanyToken::class; - } + /** * Saves the companytoken. diff --git a/app/Repositories/UserRepository.php b/app/Repositories/UserRepository.php index dfa0c531a1..6a55bd1aa5 100644 --- a/app/Repositories/UserRepository.php +++ b/app/Repositories/UserRepository.php @@ -27,24 +27,15 @@ class UserRepository extends BaseRepository { use MakesHash; - /** - * Gets the class name. - * - * @return string The class name. - */ - public function getClassName() - { - return User::class; - } /** * Saves the user and its contacts. * * @param array $data The data - * @param \App\Models\user $user The user + * @param \App\Models\User $user The user * * @param bool $unset_company_user - * @return user|\App\Models\user|null user Object + * @return \App\Models\User user Object */ public function save(array $data, User $user, $unset_company_user = false) { diff --git a/app/Repositories/VendorRepository.php b/app/Repositories/VendorRepository.php index 165478c7e5..9b15eb5a3f 100644 --- a/app/Repositories/VendorRepository.php +++ b/app/Repositories/VendorRepository.php @@ -13,7 +13,7 @@ namespace App\Repositories; use App\Factory\VendorFactory; use App\Models\Vendor; -use App\Repositories\VSendorContactRepository; +use App\Repositories\VendorContactRepository; use App\Utils\Traits\GeneratesCounter; use Illuminate\Http\Request; @@ -23,37 +23,24 @@ use Illuminate\Http\Request; class VendorRepository extends BaseRepository { use GeneratesCounter; - /** - * @var vendorContactRepository - */ + protected $contact_repo; /** - * vendorController constructor. - * @param vendorContactRepository $contact_repo + * VendorContactRepository constructor. */ public function __construct(VendorContactRepository $contact_repo) { $this->contact_repo = $contact_repo; } - /** - * Gets the class name. - * - * @return string The class name. - */ - public function getClassName() - { - return Vendor::class; - } - /** * Saves the vendor and its contacts. * * @param array $data The data - * @param \App\Models\vendor $vendor The vendor + * @param \App\Models\Vendor $vendor The vendor * - * @return vendor|\App\Models\vendor|null vendor Object + * @return vendor|\App\Models\Vendor|null Vendor Object * @throws \Laracasts\Presenter\Exceptions\PresenterException */ public function save(array $data, Vendor $vendor) : ?Vendor @@ -70,7 +57,7 @@ class VendorRepository extends BaseRepository $vendor->save(); if (isset($data['contacts'])) { - $contacts = $this->contact_repo->save($data, $vendor); + $this->contact_repo->save($data, $vendor); } if (empty($data['name'])) { diff --git a/app/Services/Credit/CreateInvitations.php b/app/Services/Credit/CreateInvitations.php index 4a742effd2..45c7b1bff7 100644 --- a/app/Services/Credit/CreateInvitations.php +++ b/app/Services/Credit/CreateInvitations.php @@ -40,7 +40,7 @@ class CreateInvitations extends AbstractService $ii->credit_id = $this->credit->id; $ii->client_contact_id = $contact->id; $ii->save(); - } elseif ($invitation && ! $contact->send_email) { + } elseif (! $contact->send_email) { $invitation->delete(); } }); diff --git a/psalm.xml b/psalm.xml index 73bb3b38d9..ba56482e2e 100644 --- a/psalm.xml +++ b/psalm.xml @@ -61,6 +61,11 @@ + + + + +