Skip to content

Commit

Permalink
- Removed TODOs that had been completed
Browse files Browse the repository at this point in the history
- Added TODO where we need to convert to querybuilder
- Converted to switch statement.
- Removed unnecessary local variable
- Replaced Qualifiers with imports
- Replaced isset() call with null coalescing operator
- Replaced strpos function calls in if statements with str_contains calls
- Removed unnecessary leading \ in use statement
- Replaced deprecated functions
- Updated PHPdocs to match function signature
- Added missing type declarations
- Made class variables private.
- Explicitly declared dynamic properties
- use https:// links instead of http://
- Fixed type error from sending null when editing transactions
- Fixed Search Suggestion function name in Employees, Persons, Suppliers controller
- Fixed function name on Receivings Controller

Signed-off-by: objecttothis <[email protected]>
  • Loading branch information
objecttothis committed May 6, 2024
1 parent 3dbf15e commit fafa6af
Show file tree
Hide file tree
Showing 64 changed files with 463 additions and 460 deletions.
11 changes: 6 additions & 5 deletions app/Config/Mimes.php
Original file line number Diff line number Diff line change
Expand Up @@ -490,11 +490,12 @@ class Mimes
*
* @return string|null The mime type found, or none if unable to determine.
*/
public static function guessTypeFromExtension(string $extension)
{
public static function guessTypeFromExtension(string $extension): array|string|null
{
$extension = trim(strtolower($extension), '. ');

if (! array_key_exists($extension, static::$mimes)) {
if (!array_key_exists($extension, static::$mimes))
{
return null;
}

Expand All @@ -508,8 +509,8 @@ public static function guessTypeFromExtension(string $extension)
*
* @return string|null The extension determined, or null if unable to match.
*/
public static function guessExtensionFromType(string $type, ?string $proposedExtension = null)
{
public static function guessExtensionFromType(string $type, ?string $proposedExtension = null): ?string
{
$type = trim(strtolower($type), '. ');

$proposedExtension = trim(strtolower($proposedExtension ?? ''));
Expand Down
4 changes: 2 additions & 2 deletions app/Controllers/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ public function postSaveLocations(): void
$not_to_delete = [];
foreach($this->request->getPost() as $key => $value)
{
if(strstr($key, 'stock_location'))
if(str_contains($key, 'stock_location'))
{
// save or update
foreach ($value as $location_id => $location_name)
Expand Down Expand Up @@ -854,7 +854,7 @@ public function postSaveRewards(): void
$not_to_delete[] = $customer_reward_id;
$array_save[$customer_reward_id]['package_name'] = $value;
}
elseif(strstr($key, 'reward_points'))
elseif(str_contains($key, 'reward_points'))
{
$customer_reward_id = preg_replace("/.*?_(\d+)$/", "$1", $key);
$array_save[$customer_reward_id]['points_percent'] = $value;
Expand Down
2 changes: 1 addition & 1 deletion app/Controllers/Employees.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function getSearch(): void
*
* @return void
*/
public function suggest(): void
public function getSuggest(): void
{
$suggestions = $this->employee->get_search_suggestions($this->request->getGet('term', FILTER_SANITIZE_FULL_SPECIAL_CHARS), 25, true);

Expand Down
4 changes: 1 addition & 3 deletions app/Controllers/Items.php
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,6 @@ public function postBulkUpdate(): void
}

/**
* @throws ReflectionException
*/
public function postDelete(): void
{
Expand All @@ -1008,8 +1007,7 @@ public function postDelete(): void

/**
* Generates a template CSV file for item import/update containing headers for current stock locations and attributes
* @return void
* @noinspection PhpUnused
* @return DownloadResponse
*/
public function getGenerateCsvFile(): DownloadResponse
{
Expand Down
2 changes: 1 addition & 1 deletion app/Controllers/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Login extends BaseController
/**
* @return RedirectResponse|string
*/
public function index()
public function index(): string|RedirectResponse
{
$this->employee = model(Employee::class);
if(!$this->employee->is_logged_in())
Expand Down
4 changes: 3 additions & 1 deletion app/Controllers/No_access.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
*/
class No_access extends BaseController
{
private Module $module;

public function __construct()
{
$this->module = model('Module');
$this->module = model(Module::class);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions app/Controllers/Persons.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace App\Controllers;

use App\Models\Person;
use function \Tamtamchik\NameCase\str_name_case;
use function Tamtamchik\NameCase\str_name_case;

abstract class Persons extends Secure_Controller
{
Expand Down Expand Up @@ -32,7 +32,7 @@ public function getIndex(): void
/**
* Gives search suggestions based on what is being searched for
*/
public function suggest(): void
public function getSuggest(): void
{
$suggestions = $this->person->get_search_suggestions($this->request->getPost('term', FILTER_SANITIZE_FULL_SPECIAL_CHARS));

Expand Down
6 changes: 3 additions & 3 deletions app/Controllers/Receivings.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function getStockItemSearch(): void
* Called in the view.
* @return void
*/
public function select_supplier(): void
public function postSelect_supplier(): void
{
$supplier_id = $this->request->getPost('supplier', FILTER_SANITIZE_NUMBER_INT);
if($this->supplier->exists($supplier_id))
Expand Down Expand Up @@ -427,10 +427,10 @@ public function receipt($receiving_id): void
}

/**
* @param $data
* @param array $data
* @return void
*/
private function _reload($data = []): void //TODO: Hungarian notation
private function _reload(array $data = []): void //TODO: Hungarian notation
{
$data['cart'] = $this->receiving_lib->get_cart();
$data['modes'] = ['receive' => lang('Receivings.receiving'), 'return' => lang('Receivings.return')];
Expand Down
48 changes: 18 additions & 30 deletions app/Controllers/Sales.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use CodeIgniter\Config\Services;
use Config\OSPOS;
use ReflectionException;
use stdClass;

class Sales extends Secure_Controller
{
Expand Down Expand Up @@ -282,26 +283,13 @@ public function postChangeMode(): void
*/
public function change_register_mode(int $sale_type): void
{
switch ($sale_type) {
case SALE_TYPE_POS:
$mode = 'sale';
break;
case SALE_TYPE_QUOTE:
$mode = 'sale_quote';
break;
case SALE_TYPE_WORK_ORDER:
$mode = 'sale_work_order';
break;
case SALE_TYPE_INVOICE:
$mode = 'sale_invoice';
break;
case SALE_TYPE_RETURN:
$mode = 'return';
break;
default:
$mode = 'sale';
break;
}
$mode = match($sale_type) {
SALE_TYPE_QUOTE => 'sale_quote',
SALE_TYPE_WORK_ORDER => 'sale_work_order',
SALE_TYPE_INVOICE => 'sale_invoice',
SALE_TYPE_RETURN => 'return',
default => 'sale' //SALE_TYPE_POS
};

$this->sale_lib->set_mode($mode);
}
Expand Down Expand Up @@ -394,7 +382,7 @@ public function postAddPayment(): void
//In the case of giftcard payment the register input amount_tendered becomes the giftcard number
$amount_tendered = prepare_decimal($this->request->getPost('amount_tendered'));
$giftcard_num = filter_var($amount_tendered, FILTER_SANITIZE_FULL_SPECIAL_CHARS, FILTER_FLAG_ALLOW_FRACTION);

$payments = $this->sale_lib->get_payments();
$payment_type = $payment_type . ':' . $giftcard_num;
$current_payments_with_giftcard = isset($payments[$payment_type]) ? $payments[$payment_type]['payment_amount'] : 0;
Expand Down Expand Up @@ -1018,9 +1006,9 @@ public function send_receipt(int $sale_id): bool
* @param int $customer_id
* @param array $data
* @param bool $stats
* @return array|object|\stdClass|string|null
* @return array|stdClass|string|null
*/
private function _load_customer_data(int $customer_id, array &$data, bool $stats = false) //TODO: Hungarian notation
private function _load_customer_data(int $customer_id, array &$data, bool $stats = false): array|string|stdClass|null //TODO: Hungarian notation
{
$customer_info = '';

Expand Down Expand Up @@ -1204,10 +1192,10 @@ private function _load_sale_data($sale_id): array //TODO: Hungarian notation
}

/**
* @param $data
* @param array $data
* @return void
*/
private function _reload($data = []): void //TODO: Hungarian notation
private function _reload(array $data = []): void //TODO: Hungarian notation
{
$sale_id = $this->session->get('sale_id'); //TODO: This variable is never used

Expand Down Expand Up @@ -1811,15 +1799,15 @@ public function change_item_description(): void
}

/**
* @param int $id
* @param array $array
* @param int $search_item_id
* @param array $shopping_cart
* @return int|string|null
*/
public function getSearch_cart_for_item_id(int $id, array $array) //TODO: The second parameter should not be named array perhaps int $needle_item_id, array $shopping_cart
public function getSearch_cart_for_item_id(int $search_item_id, array $shopping_cart): int|string|null
{
foreach($array as $key => $val) //TODO: key and val are not reflective of the contents of the array and should be replaced with descriptive variable names. Perhaps $cart_haystack => $item_details
foreach($shopping_cart as $key => $val)
{
if($val['item_id'] === $id) //TODO: Then this becomes more readable $item_details['item_id'] === $needle_item_id
if($val['item_id'] === $search_item_id)
{
return $key;
}
Expand Down
2 changes: 1 addition & 1 deletion app/Controllers/Suppliers.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function getSearch(): void
/**
* Gives search suggestions based on what is being searched for
**/
public function suggest(): void
public function getSuggest(): void
{
$suggestions = $this->supplier->get_search_suggestions($this->request->getGet('term', FILTER_SANITIZE_FULL_SPECIAL_CHARS), true);

Expand Down
4 changes: 3 additions & 1 deletion app/Controllers/Tax_categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
*/
class Tax_categories extends Secure_Controller
{
private Tax_category $tax_category;

public function __construct()
{
parent::__construct('tax_categories');

$this->tax_category = model('Tax_category');
$this->tax_category = model(Tax_category::class);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion app/Controllers/Tax_codes.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
*/
class Tax_codes extends Secure_Controller
{
private Tax_code $tax_code;

public function __construct()
{
parent::__construct('tax_codes');

$this->tax_code = model('Tax_code');
$this->tax_code = model(Tax_code::class);
helper('tax_helper');
}

Expand Down
4 changes: 3 additions & 1 deletion app/Controllers/Tax_jurisdictions.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
*/
class Tax_jurisdictions extends Secure_Controller
{
private Tax_jurisdiction $tax_jurisdiction;

public function __construct()
{
parent::__construct('tax_jurisdictions');

$this->tax_jurisdiction = model('Tax_jurisdiction');
$this->tax_jurisdiction = model(Tax_jurisdiction::class);

helper('tax_helper');
}
Expand Down
9 changes: 5 additions & 4 deletions app/Database/Migrations/20170502221506_sales_tax_data.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ class Migration_Sales_Tax_Data extends Migration
public const YES = '1';
public const VAT_TAX = '0';
public const SALES_TAX = '1';
private Appconfig $appconfig;

public function __construct()
{
parent::__construct();
$this->appconfig = model('Appconfig');
$this->appconfig = model(Appconfig::class);
}
//TODO: we need to figure out why we get a server error when uncommented portions of this migration run

Expand Down Expand Up @@ -361,9 +362,9 @@ public function apply_invoice_taxing(array &$sales_taxes): void
{
$sort = [];

foreach($sales_taxes as $k => $v) //TODO: Refactor $k and $v to proper variable names
foreach($sales_taxes as $key => $value)
{
$sort['print_sequence'][$k] = $v['print_sequence'];
$sort['print_sequence'][$key] = $value['print_sequence'];
}

array_multisort($sort['print_sequence'], SORT_ASC, $sales_taxes);
Expand Down Expand Up @@ -401,7 +402,7 @@ public function round_sales_taxes(array &$sales_taxes): void
$rounding_code = $sales_tax['rounding_code'];
$rounded_sale_tax_amount = $sale_tax_amount;

if ($rounding_code == PHP_ROUND_HALF_UP //TODO: This block of if/elseif statements should be replaced by a switch
if ($rounding_code == PHP_ROUND_HALF_UP
|| $rounding_code == PHP_ROUND_HALF_DOWN
|| $rounding_code == PHP_ROUND_HALF_EVEN
|| $rounding_code == PHP_ROUND_HALF_ODD)
Expand Down
3 changes: 2 additions & 1 deletion app/Database/Migrations/20200202000000_taxamount.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ class Migration_TaxAmount extends Migration
public const YES = '1';
public const VAT_TAX = '0';
public const SALES_TAX = '1'; //TODO: It appears that this constant is never used
private Appconfig $appconfig;

public function __construct()
{
parent::__construct();

$this->appconfig = model('Appconfig');
$this->appconfig = model(Appconfig::class);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private function migrate_duplicate_attribute_values($attribute_type): void
* @param ResultInterface $attribute_ids_to_fix All attribute_ids that need to parsed
* @param array $attribute_value The attribute value in question.
*/
private function reassign_duplicate_attribute_values(ResultInterface $attribute_ids_to_fix, array $attribute_value)
private function reassign_duplicate_attribute_values(ResultInterface $attribute_ids_to_fix, array $attribute_value): void
{
foreach($attribute_ids_to_fix->getResultArray() as $attribute_id)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function up(): void
*
* @property attribute $attribute
*/
private function migrate_duplicate_attribute_links()
private function migrate_duplicate_attribute_links(): void
{
$attribute = model(Attribute::class);

Expand Down
3 changes: 2 additions & 1 deletion app/Database/Migrations/20220127000000_convert_to_ci4.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use CodeIgniter\HTTP\Exceptions\RedirectException;
use Config\Encryption;
use Config\Services;
use ReflectionException;

class Convert_to_ci4 extends Migration
{
Expand Down Expand Up @@ -55,7 +56,7 @@ public function down(): void

/**
* @return RedirectResponse|void
* @throws \ReflectionException
* @throws ReflectionException
*/
private function convert_ci3_encrypted_data()
{
Expand Down
2 changes: 1 addition & 1 deletion app/Database/Migrations/20230307000000_int_to_tinyint.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function up(): void
/**
* Revert a migration step.
*/
public function down()
public function down(): void
{
$this->db->query('ALTER TABLE ' . $this->db->prefixTable('customers') . ' MODIFY `consent` int NOT NULL DEFAULT 0');
$this->db->query('ALTER TABLE ' . $this->db->prefixTable('cash_up') . ' MODIFY `note` int NOT NULL DEFAULT 0');
Expand Down
2 changes: 1 addition & 1 deletion app/Events/Method.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Method
/**
* @return void
*/
public static function validate_method()
public static function validate_method(): void
{
$url = $_SERVER['REQUEST_URI'];

Expand Down
Loading

0 comments on commit fafa6af

Please sign in to comment.