mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-04 03:47:36 -05:00 
			
		
		
		
	Fixes for static analysis
This commit is contained in:
		
							parent
							
								
									42733f2679
								
							
						
					
					
						commit
						002e4a7aab
					
				@ -1,143 +0,0 @@
 | 
				
			|||||||
<?php
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * Invoice Ninja (https://invoiceninja.com).
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @link https://github.com/invoiceninja/invoiceninja source repository
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @license https://www.elastic.co/licensing/elastic-license
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace App\Console\Commands;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
use App\Models\Account;
 | 
					 | 
				
			||||||
use App\Models\Activity;
 | 
					 | 
				
			||||||
use App\Models\Backup;
 | 
					 | 
				
			||||||
use App\Models\Client;
 | 
					 | 
				
			||||||
use App\Models\ClientContact;
 | 
					 | 
				
			||||||
use App\Models\ClientGatewayToken;
 | 
					 | 
				
			||||||
use App\Models\Company;
 | 
					 | 
				
			||||||
use App\Models\CompanyGateway;
 | 
					 | 
				
			||||||
use App\Models\CompanyLedger;
 | 
					 | 
				
			||||||
use App\Models\CompanyToken;
 | 
					 | 
				
			||||||
use App\Models\CompanyUser;
 | 
					 | 
				
			||||||
use App\Models\Credit;
 | 
					 | 
				
			||||||
use App\Models\CreditInvitation;
 | 
					 | 
				
			||||||
use App\Models\Design;
 | 
					 | 
				
			||||||
use App\Models\Document;
 | 
					 | 
				
			||||||
use App\Models\Expense;
 | 
					 | 
				
			||||||
use App\Models\ExpenseCategory;
 | 
					 | 
				
			||||||
use App\Models\Gateway;
 | 
					 | 
				
			||||||
use App\Models\GroupSetting;
 | 
					 | 
				
			||||||
use App\Models\Invoice;
 | 
					 | 
				
			||||||
use App\Models\InvoiceInvitation;
 | 
					 | 
				
			||||||
use App\Models\Payment;
 | 
					 | 
				
			||||||
use App\Models\Paymentable;
 | 
					 | 
				
			||||||
use App\Models\PaymentHash;
 | 
					 | 
				
			||||||
use App\Models\Product;
 | 
					 | 
				
			||||||
use App\Models\Project;
 | 
					 | 
				
			||||||
use App\Models\Quote;
 | 
					 | 
				
			||||||
use App\Models\QuoteInvitation;
 | 
					 | 
				
			||||||
use App\Models\RecurringInvoice;
 | 
					 | 
				
			||||||
use App\Models\RecurringInvoiceInvitation;
 | 
					 | 
				
			||||||
use App\Models\Subscription;
 | 
					 | 
				
			||||||
use App\Models\SystemLog;
 | 
					 | 
				
			||||||
use App\Models\Task;
 | 
					 | 
				
			||||||
use App\Models\TaskStatus;
 | 
					 | 
				
			||||||
use App\Models\TaxRate;
 | 
					 | 
				
			||||||
use App\Models\User;
 | 
					 | 
				
			||||||
use App\Models\Vendor;
 | 
					 | 
				
			||||||
use App\Models\VendorContact;
 | 
					 | 
				
			||||||
use App\Models\Webhook;
 | 
					 | 
				
			||||||
use Illuminate\Console\Command;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * Class CheckDb.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
class CheckDb extends Command
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    protected $signature = 'ninja:check-db';
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    protected $description = 'Check MultiDB';
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    protected $log = '';
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private $entities = [
 | 
					 | 
				
			||||||
        Account::class,
 | 
					 | 
				
			||||||
        Activity::class,
 | 
					 | 
				
			||||||
        Backup::class,
 | 
					 | 
				
			||||||
        Client::class,
 | 
					 | 
				
			||||||
        ClientContact::class,
 | 
					 | 
				
			||||||
        ClientGatewayToken::class,
 | 
					 | 
				
			||||||
        Company::class,
 | 
					 | 
				
			||||||
        CompanyGateway::class,
 | 
					 | 
				
			||||||
        CompanyLedger::class,
 | 
					 | 
				
			||||||
        CompanyToken::class,
 | 
					 | 
				
			||||||
        CompanyUser::class,
 | 
					 | 
				
			||||||
        Credit::class,
 | 
					 | 
				
			||||||
        CreditInvitation::class,
 | 
					 | 
				
			||||||
        Design::class,
 | 
					 | 
				
			||||||
        Document::class,
 | 
					 | 
				
			||||||
        Expense::class,
 | 
					 | 
				
			||||||
        ExpenseCategory::class,
 | 
					 | 
				
			||||||
        Gateway::class,
 | 
					 | 
				
			||||||
        GroupSetting::class,
 | 
					 | 
				
			||||||
        Invoice::class,
 | 
					 | 
				
			||||||
        InvoiceInvitation::class,
 | 
					 | 
				
			||||||
        Payment::class,
 | 
					 | 
				
			||||||
        Paymentable::class,
 | 
					 | 
				
			||||||
        PaymentHash::class,
 | 
					 | 
				
			||||||
        Product::class,
 | 
					 | 
				
			||||||
        Project::class,
 | 
					 | 
				
			||||||
        Quote::class,
 | 
					 | 
				
			||||||
        QuoteInvitation::class,
 | 
					 | 
				
			||||||
        RecurringInvoice::class,
 | 
					 | 
				
			||||||
        RecurringInvoiceInvitation::class,
 | 
					 | 
				
			||||||
        Subscription::class,
 | 
					 | 
				
			||||||
        SystemLog::class,
 | 
					 | 
				
			||||||
        Task::class,
 | 
					 | 
				
			||||||
        TaskStatus::class,
 | 
					 | 
				
			||||||
        TaxRate::class,
 | 
					 | 
				
			||||||
        User::class,
 | 
					 | 
				
			||||||
        Vendor::class,
 | 
					 | 
				
			||||||
        VendorContact::class,
 | 
					 | 
				
			||||||
        WebHook::class,
 | 
					 | 
				
			||||||
    ];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public function handle()
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        $this->LogMessage('Checking - V5_DB1');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        foreach ($this->entities as $entity) {
 | 
					 | 
				
			||||||
            $count_db_1 = $entity::on('db-ninja-01')->count();
 | 
					 | 
				
			||||||
            $count_db_2 = $entity::on('db-ninja-02a')->count();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            $diff = $count_db_1 - $count_db_2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if ($diff != 0) {
 | 
					 | 
				
			||||||
                $this->logMessage("{$entity} DB1: {$count_db_1} - DB2: {$count_db_2} - diff = {$diff}");
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $this->LogMessage('Checking - V5_DB2');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        foreach ($this->entities as $entity) {
 | 
					 | 
				
			||||||
            $count_db_1 = $entity::on('db-ninja-02')->count();
 | 
					 | 
				
			||||||
            $count_db_2 = $entity::on('db-ninja-01a')->count();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            $diff = $count_db_1 - $count_db_2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if ($diff != 0) {
 | 
					 | 
				
			||||||
                $this->logMessage("{$entity} DB1: {$count_db_1} - DB2: {$count_db_2} - diff = {$diff}");
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private function logMessage($str)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        $str = date('Y-m-d h:i:s').' '.$str;
 | 
					 | 
				
			||||||
        $this->info($str);
 | 
					 | 
				
			||||||
        $this->log .= $str."\n";
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@ -1,4 +1,13 @@
 | 
				
			|||||||
<?php
 | 
					<?php
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Invoice Ninja (https://invoiceninja.com).
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @link https://github.com/invoiceninja/invoiceninja source repository
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @license https://www.elastic.co/licensing/elastic-license
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace App\Http\Middleware;
 | 
					namespace App\Http\Middleware;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1,4 +1,13 @@
 | 
				
			|||||||
<?php
 | 
					<?php
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Invoice Ninja (https://invoiceninja.com).
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @link https://github.com/invoiceninja/invoiceninja source repository
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @license https://www.elastic.co/licensing/elastic-license
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace App\Http\Middleware;
 | 
					namespace App\Http\Middleware;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -14,7 +23,7 @@ class ThrottleRequestsWithPredis extends \Illuminate\Routing\Middleware\Throttle
 | 
				
			|||||||
     *
 | 
					     *
 | 
				
			||||||
     * @var \Illuminate\Contracts\Redis\Factory
 | 
					     * @var \Illuminate\Contracts\Redis\Factory
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    protected $redis;
 | 
					    protected $redis; /** @phpstan-ignore-line */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * The timestamp of the end of the current duration by key.
 | 
					     * The timestamp of the end of the current duration by key.
 | 
				
			||||||
@ -38,9 +47,12 @@ class ThrottleRequestsWithPredis extends \Illuminate\Routing\Middleware\Throttle
 | 
				
			|||||||
    /** @phpstan-ignore-next-line */
 | 
					    /** @phpstan-ignore-next-line */
 | 
				
			||||||
    public function __construct(RateLimiter $limiter, Redis $redis)
 | 
					    public function __construct(RateLimiter $limiter, Redis $redis)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        parent::__construct($limiter);
 | 
					        
 | 
				
			||||||
        /** @phpstan-ignore-next-line */
 | 
					        /** @phpstan-ignore-next-line */
 | 
				
			||||||
        $this->redis = \Illuminate\Support\Facades\Redis::connection('sentinel-cache');
 | 
					        parent::__construct($limiter); /** @phpstan-ignore-line */
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        /** @phpstan-ignore-next-line */
 | 
				
			||||||
 | 
					        $this->redis = \Illuminate\Support\Facades\Redis::connection('sentinel-cache'); /** @phpstan-ignore-line */
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 | 
				
			|||||||
@ -55,9 +55,9 @@ use Laracasts\Presenter\PresentableTrait;
 | 
				
			|||||||
 * @property string|null $referral_code
 | 
					 * @property string|null $referral_code
 | 
				
			||||||
 * @property int|null $created_at
 | 
					 * @property int|null $created_at
 | 
				
			||||||
 * @property int|null $updated_at
 | 
					 * @property int|null $updated_at
 | 
				
			||||||
 * @property int $is_scheduler_running
 | 
					 * @property bool $is_scheduler_running
 | 
				
			||||||
 * @property int|null $trial_duration
 | 
					 * @property int|null $trial_duration
 | 
				
			||||||
 * @property int $is_onboarding
 | 
					 * @property bool $is_onboarding
 | 
				
			||||||
 * @property object|null $onboarding
 | 
					 * @property object|null $onboarding
 | 
				
			||||||
 * @property bool $is_migrated
 | 
					 * @property bool $is_migrated
 | 
				
			||||||
 * @property string|null $platform
 | 
					 * @property string|null $platform
 | 
				
			||||||
 | 
				
			|||||||
@ -98,22 +98,6 @@ return [
 | 
				
			|||||||
            'options'        => [],
 | 
					            'options'        => [],
 | 
				
			||||||
        ],
 | 
					        ],
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        'db-ninja-01a' => [
 | 
					 | 
				
			||||||
            'driver'         => 'mysql',
 | 
					 | 
				
			||||||
            'host'           => env('DB_HOST1', env('DB_HOST', '127.0.0.1')),
 | 
					 | 
				
			||||||
            'database'       => env('DB_DATABASE2', env('DB_DATABASE', 'forge')),
 | 
					 | 
				
			||||||
            'username'       => env('DB_USERNAME2', env('DB_USERNAME', 'forge')),
 | 
					 | 
				
			||||||
            'password'       => env('DB_PASSWORD2', env('DB_PASSWORD', '')),
 | 
					 | 
				
			||||||
            'port'           => env('DB_PORT1', env('DB_PORT', '3306')),
 | 
					 | 
				
			||||||
            'charset'        => 'utf8mb4',
 | 
					 | 
				
			||||||
            'collation'      => 'utf8mb4_unicode_ci',
 | 
					 | 
				
			||||||
            'prefix'         => '',
 | 
					 | 
				
			||||||
            'prefix_indexes' => true,
 | 
					 | 
				
			||||||
            'strict'         => env('DB_STRICT', false),
 | 
					 | 
				
			||||||
            'engine'         => 'InnoDB ROW_FORMAT=DYNAMIC',
 | 
					 | 
				
			||||||
            'options'        => [],
 | 
					 | 
				
			||||||
        ],
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        'db-ninja-02' => [
 | 
					        'db-ninja-02' => [
 | 
				
			||||||
            'driver'         => 'mysql',
 | 
					            'driver'         => 'mysql',
 | 
				
			||||||
            'host'           => env('DB_HOST2', env('DB_HOST', '127.0.0.1')),
 | 
					            'host'           => env('DB_HOST2', env('DB_HOST', '127.0.0.1')),
 | 
				
			||||||
@ -130,13 +114,13 @@ return [
 | 
				
			|||||||
            'options'        => [],
 | 
					            'options'        => [],
 | 
				
			||||||
        ],
 | 
					        ],
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        'db-ninja-02a' => [
 | 
					        'db-ninja-03' => [
 | 
				
			||||||
            'driver'         => 'mysql',
 | 
					            'driver'         => 'mysql',
 | 
				
			||||||
            'host'           => env('DB_HOST2', env('DB_HOST', '127.0.0.1')),
 | 
					            'host'           => env('DB_HOST3', env('DB_HOST', '127.0.0.1')),
 | 
				
			||||||
            'database'       => env('DB_DATABASE1', env('DB_DATABASE', 'forge')),
 | 
					            'database'       => env('DB_DATABASE3', env('DB_DATABASE', 'forge')),
 | 
				
			||||||
            'username'       => env('DB_USERNAME1', env('DB_USERNAME', 'forge')),
 | 
					            'username'       => env('DB_USERNAME3', env('DB_USERNAME', 'forge')),
 | 
				
			||||||
            'password'       => env('DB_PASSWORD1', env('DB_PASSWORD', '')),
 | 
					            'password'       => env('DB_PASSWORD3', env('DB_PASSWORD', '')),
 | 
				
			||||||
            'port'           => env('DB_PORT2', env('DB_PORT', '3306')),
 | 
					            'port'           => env('DB_PORT3', env('DB_PORT', '3306')),
 | 
				
			||||||
            'charset'        => 'utf8mb4',
 | 
					            'charset'        => 'utf8mb4',
 | 
				
			||||||
            'collation'      => 'utf8mb4_unicode_ci',
 | 
					            'collation'      => 'utf8mb4_unicode_ci',
 | 
				
			||||||
            'prefix'         => '',
 | 
					            'prefix'         => '',
 | 
				
			||||||
 | 
				
			|||||||
@ -6,6 +6,7 @@ parameters:
 | 
				
			|||||||
    level: 5
 | 
					    level: 5
 | 
				
			||||||
    paths:
 | 
					    paths:
 | 
				
			||||||
        - app
 | 
					        - app
 | 
				
			||||||
 | 
					        - Modules
 | 
				
			||||||
    excludePaths:
 | 
					    excludePaths:
 | 
				
			||||||
        analyseAndScan:
 | 
					        analyseAndScan:
 | 
				
			||||||
            - 'vendor'
 | 
					            - 'vendor'
 | 
				
			||||||
@ -16,6 +17,7 @@ parameters:
 | 
				
			|||||||
            - 'app/DataMapper/Analytics/*'
 | 
					            - 'app/DataMapper/Analytics/*'
 | 
				
			||||||
            - 'app/PaymentDrivers/Authorize/*'
 | 
					            - 'app/PaymentDrivers/Authorize/*'
 | 
				
			||||||
            - 'app/PaymentDrivers/AuthorizePaymentDriver.php'
 | 
					            - 'app/PaymentDrivers/AuthorizePaymentDriver.php'
 | 
				
			||||||
 | 
					            - 'app/Http/Middleware/ThrottleRequestsWithPredis.php'
 | 
				
			||||||
            - 'app/Utils/Traits/*'
 | 
					            - 'app/Utils/Traits/*'
 | 
				
			||||||
    universalObjectCratesClasses:
 | 
					    universalObjectCratesClasses:
 | 
				
			||||||
        - App\DataMapper\Tax\RuleInterface
 | 
					        - App\DataMapper\Tax\RuleInterface
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user