Fix for laravel 8 route file regression + psalm cleanup

This commit is contained in:
= 2020-11-01 16:09:09 +11:00
parent 39f084c030
commit 6479b2fd3e
32 changed files with 295 additions and 484 deletions

View File

@ -19,3 +19,4 @@ DB_HOST=127.0.0.1
NINJA_ENVIRONMENT=hosted
COMPOSER_AUTH='{"github-oauth": {"github.com": "${{ secrets.GITHUB_TOKEN }}"}}'
TRAVIS=true
API_SECRET=superdoopersecrethere

View File

@ -507,7 +507,7 @@ class CompanySettings extends BaseSettings
/**
* Provides class defaults on init.
* @return object
* @return stdClass
*/
public static function defaults(): stdClass
{

View File

@ -149,7 +149,7 @@ class FreeCompanySettings extends BaseSettings
/**
* Provides class defaults on init.
* @return object
* @return stdClass
*/
public static function defaults(): stdClass
{

View File

@ -34,12 +34,14 @@ class SetEmailDb
];
if ($request->input('email') && config('ninja.db.multi_db_enabled')) {
info("trying to find db");
if (! MultiDB::userFindAndSetDb($request->input('email'))) {
return response()->json($error, 403);
return response()->json($error, 400);
}
} else {
return response()->json($error, 403);
}
}
// else {
// return response()->json($error, 403);
// }
return $next($request);
}

View File

@ -112,7 +112,7 @@ class UpdateClientRequest extends Request
* are saveable
*
* @param object $settings
* @return object $settings
* @return stdClass $settings
*/
private function filterSaveableSettings($settings)
{

View File

@ -76,7 +76,7 @@ class UpdateCompanyRequest extends Request
* are saveable
*
* @param object $settings
* @return object $settings
* @return stdClass $settings
*/
private function filterSaveableSettings($settings)
{

View File

@ -58,7 +58,7 @@ class UpdateGroupSettingRequest extends Request
* are saveable
*
* @param object $settings
* @return object $settings
* @return stdClass $settings
*/
private function filterSaveableSettings($settings)
{

View File

@ -285,7 +285,7 @@ class Client extends BaseModel implements HasLocalePreference
* of settings which have been merged from
* Client > Group > Company levels.
*
* @return object stdClass object of settings
* @return stdClass stdClass object of settings
*/
public function getMergedSettings() :object
{

View File

@ -324,32 +324,32 @@ class CompanyGateway extends BaseModel
* @param $invoice_count
* @return stdClass
*/
public function calcGatewayFeeObject($amount, $invoice_count)
{
$total_gateway_fee = $this->calcGatewayFee($amount);
// public function calcGatewayFeeObject($amount, $invoice_count)
// {
// $total_gateway_fee = $this->calcGatewayFee($amount);
$fee_object = new stdClass;
// $fee_object = new stdClass;
$fees_and_limits = $this->getFeesAndLimits();
// $fees_and_limits = $this->getFeesAndLimits();
if (! $fees_and_limits) {
return $fee_object;
}
// if (! $fees_and_limits) {
// return $fee_object;
// }
$fee_component_amount = $fees_and_limits->fee_amount ?: 0;
$fee_component_percent = $fees_and_limits->fee_percent ? ($amount * $fees_and_limits->fee_percent / 100) : 0;
// $fee_component_amount = $fees_and_limits->fee_amount ?: 0;
// $fee_component_percent = $fees_and_limits->fee_percent ? ($amount * $fees_and_limits->fee_percent / 100) : 0;
$combined_fee_component = $fee_component_amount + $fee_component_percent;
// $combined_fee_component = $fee_component_amount + $fee_component_percent;
$fee_component_tax_name1 = $fees_and_limits->fee_tax_name1 ?: '';
$fee_component_tax_rate1 = $fees_and_limits->fee_tax_rate1 ? ($combined_fee_component * $fees_and_limits->fee_tax_rate1 / 100) : 0;
// $fee_component_tax_name1 = $fees_and_limits->fee_tax_name1 ?: '';
// $fee_component_tax_rate1 = $fees_and_limits->fee_tax_rate1 ? ($combined_fee_component * $fees_and_limits->fee_tax_rate1 / 100) : 0;
$fee_component_tax_name2 = $fees_and_limits->fee_tax_name2 ?: '';
$fee_component_tax_rate2 = $fees_and_limits->fee_tax_rate2 ? ($combined_fee_component * $fees_and_limits->fee_tax_rate2 / 100) : 0;
// $fee_component_tax_name2 = $fees_and_limits->fee_tax_name2 ?: '';
// $fee_component_tax_rate2 = $fees_and_limits->fee_tax_rate2 ? ($combined_fee_component * $fees_and_limits->fee_tax_rate2 / 100) : 0;
$fee_component_tax_name3 = $fees_and_limits->fee_tax_name3 ?: '';
$fee_component_tax_rate3 = $fees_and_limits->fee_tax_rate3 ? ($combined_fee_component * $fees_and_limits->fee_tax_rate3 / 100) : 0;
}
// $fee_component_tax_name3 = $fees_and_limits->fee_tax_name3 ?: '';
// $fee_component_tax_rate3 = $fees_and_limits->fee_tax_rate3 ? ($combined_fee_component * $fees_and_limits->fee_tax_rate3 / 100) : 0;
// }
public function resolveRouteBinding($value, $field = NULL)
{

View File

@ -185,7 +185,7 @@ class Credit extends BaseModel
/**
* Access the invoice calculator object.
*
* @return object The invoice calculator object getters
* @return stdClass The invoice calculator object getters
*/
public function calc()
{

View File

@ -356,7 +356,7 @@ class Invoice extends BaseModel
/**
* Access the invoice calculator object.
*
* @return object The invoice calculator object getters
* @return stdClass The invoice calculator object getters
*/
public function calc()
{

View File

@ -159,7 +159,7 @@ class Quote extends BaseModel
/**
* Access the quote calculator object.
*
* @return object The quote calculator object getters
* @return stdClass The quote calculator object getters
*/
public function calc()
{

View File

@ -72,7 +72,7 @@ class BasePaymentDriver
/**
* Returns the Omnipay driver.
* @return object Omnipay initialized object
* @return stdClass Omnipay initialized object
*/
protected function gateway()
{

View File

@ -41,6 +41,10 @@ class PaymentRepository extends BaseRepository
$this->credit_repo = $credit_repo;
}
/**
* @return string
*/
public function getClassName()
{
return Payment::class;

View File

@ -31,7 +31,7 @@ class RecurringInvoiceRepository extends BaseRepository
$invoice->save();
$invoice_calc = new InvoiceSum($invoice, $invoice->settings);
$invoice_calc = new InvoiceSum($invoice);
$invoice->service()
->applyNumber()

View File

@ -30,9 +30,9 @@ class TaskRepository extends BaseRepository
/**
* Gets the class name.
*
* @return string The class name.
* @return string The class name.
*/
public function getClassName()
public function getClassName()
{
return Task::class;
}
@ -40,8 +40,8 @@ class TaskRepository extends BaseRepository
/**
* Saves the task and its contacts.
*
* @param array $data The data
* @param \App\Models\task $task The task
* @param array $data The data
* @param \App\Models\Task $task The task
*
* @return task|null task Object
*/

View File

@ -33,7 +33,7 @@ class SendEmail
*/
public function run()
{
$email_builder = (new PaymentEmail())->build($this->payment, $contact);
$email_builder = (new PaymentEmail())->build($this->payment, $this->contact);
$this->payment->client->contacts->each(function ($contact) use ($email_builder) {
if ($contact->send && $contact->email) {

View File

@ -54,7 +54,6 @@ class UserTransformer extends EntityTransformer
'created_at' => (int) $user->created_at,
'updated_at' => (int) $user->updated_at,
'archived_at' => (int) $user->deleted_at,
'created_at' => (int) $user->created_at,
'is_deleted' => (bool) $user->is_deleted,
'phone' => $user->phone ?: '',
'email_verified_at' => $user->getEmailVerifiedAt(),

View File

@ -57,7 +57,7 @@ class EmailStats
* Iterates through a list of companies
* and flushes the email sent data.
*
* @param string $companies The company key
* @param Collection $companies The company key
* @return void
*/
public static function clearCompanies($companies)

View File

@ -251,8 +251,8 @@ class HtmlEngine
$data['$contact.phone'] = ['value' => $this->contact->phone, 'label' => ctrans('texts.phone')];
$data['$contact.name'] = ['value' => isset($this->contact) ? $this->contact->present()->name() : 'no contact name on record', 'label' => ctrans('texts.contact_name')];
$data['$contact.first_name'] = ['value' => isset($contact) ? $contact->first_name : '', 'label' => ctrans('texts.first_name')];
$data['$contact.last_name'] = ['value' => isset($contact) ? $contact->last_name : '', 'label' => ctrans('texts.last_name')];
$data['$contact.first_name'] = ['value' => isset($this->contact) ? $this->contact->first_name : '', 'label' => ctrans('texts.first_name')];
$data['$contact.last_name'] = ['value' => isset($this->contact) ? $this->contact->last_name : '', 'label' => ctrans('texts.last_name')];
$data['$contact.custom1'] = ['value' => isset($this->contact) ? $this->contact->custom_value1 : ' ', 'label' => $this->makeCustomField('contact1')];
$data['$contact.custom2'] = ['value' => isset($this->contact) ? $this->contact->custom_value2 : ' ', 'label' => $this->makeCustomField('contact1')];
$data['$contact.custom3'] = ['value' => isset($this->contact) ? $this->contact->custom_value3 : ' ', 'label' => $this->makeCustomField('contact1')];

View File

@ -35,9 +35,8 @@ class Phantom
* Phantom JS API.
*
* @param $invitation
* @return pdf HTML to PDF conversion
*/
public function generate($invitation)
public function generate($invitation)
{
$entity = false;

View File

@ -139,7 +139,7 @@ trait ClientGroupSettingsSaver
* so that it can be saved cleanly
*
* @param array $settings The settings request() array
* @return object stdClass object
* @return stdClass stdClass object
*/
private function checkSettingType($settings) : stdClass
{
@ -214,8 +214,7 @@ trait ClientGroupSettingsSaver
case 'array':
return is_array($value);
case 'json':
json_decode($string);
json_decode($value);
return json_last_error() == JSON_ERROR_NONE;
default:
return false;

View File

@ -71,7 +71,7 @@ trait CompanyGatewayFeesAndLimitsSaver
case 'array':
return is_array($value);
case 'json':
json_decode($string);
json_decode($value);
return json_last_error() == JSON_ERROR_NONE;
default:

View File

@ -131,7 +131,7 @@ trait CompanySettingsSaver
* so that it can be saved cleanly
*
* @param array $settings The settings request() array
* @return object stdClass object
* @return stdClass stdClass object
*/
private function checkSettingType($settings) : stdClass
{
@ -224,7 +224,7 @@ trait CompanySettingsSaver
case 'array':
return is_array($value);
case 'json':
json_decode($string);
json_decode($value);
return json_last_error() == JSON_ERROR_NONE;
default:

View File

@ -442,7 +442,7 @@ trait GeneratesCounter
* check if we need to reset here.
*
* @param Client $client client entity
* @return false
* @return void
*/
private function resetCounters(Client $client)
{

View File

@ -44,13 +44,9 @@ trait Inviteable
public function getLink() :string
{
//$entity_type = strtolower(class_basename($this->entityType()));
$entity_type = Str::snake(class_basename($this->entityType()));
//$this->with('company','contact',$this->entity_type);
//$this->with('company');
$domain = isset($this->company->portal_domain) ?: $this->company->domain();
switch ($this->company->portal_mode) {
@ -65,6 +61,9 @@ trait Inviteable
return $domain.'client/'.$entity_type.'/'.$this->key;
break;
default:
return '';
break;
}
}

View File

@ -52,15 +52,17 @@ trait MakesDates
/**
* Formats a date.
* @param Carbon/String $date Carbon object or date string
* @param Carbon|string $date Carbon object or date string
* @param string $format The date display format
* @return string The formatted date
*/
public function formatDate($date, string $format) :string
{
if (! $date || strlen($date) < 1) {
if(!isset($date))
return '';
}
// if (!$date || strlen($date) < 1) {
// return '';
// }
if (is_string($date)) {
$date = $this->convertToDateObject($date);

View File

@ -67,7 +67,7 @@ trait MakesHash
$decoded_array = $hashids->decode($value);
if (! is_array($decoded_array)) {
throw new Exception("Invalid Primary Key");
throw new \Exception("Invalid Primary Key");
//response()->json(['error'=>'Invalid primary key'], 400);
}

622
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -51,7 +51,18 @@
<directory name="app" />
</errorLevel>
</InvalidScalarArgument>
<UndefinedMagicPropertyFetch>
<errorLevel type="suppress">
<directory name="app" />
</errorLevel>
</UndefinedMagicPropertyFetch>
<InvalidNullableReturnType>
<errorLevel type="suppress">
<directory name="app" />
</errorLevel>
</InvalidNullableReturnType>
</issueHandlers>

View File

@ -16,10 +16,9 @@ Route::group(['middleware' => ['api_secret_check']], function () {
Route::post('api/v1/oauth_login', 'Auth\LoginController@oauthApiLogin');
});
Route::group(['api_secret_check', 'email_db'], function () {
Route::group(['middleware' => ['api_secret_check', 'email_db']], function () {
Route::post('api/v1/login', 'Auth\LoginController@apiLogin')->name('login.submit');
Route::post('api/v1/reset_password', 'Auth\ForgotPasswordController@sendResetLinkEmail');
});
Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'api/v1', 'as' => 'api.'], function () {

View File

@ -24,6 +24,7 @@ use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Session;
use Tests\TestCase;
use Illuminate\Validation\ValidationException;
/**
* @test
@ -141,6 +142,10 @@ class LoginTest extends TestCase
public function testApiLogin()
{
Account::all()->each(function ($account){
$account->delete();
});
$account = Account::factory()->create();
$user = User::factory()->create([
'account_id' => $account->id,
@ -177,15 +182,28 @@ class LoginTest extends TestCase
$this->assertTrue($user->company_users->first() !== null);
$this->assertTrue($user->company_user->account !== null);
$this->assertEquals($user->email, 'test@example.com');
$this->assertTrue(\Hash::check('123456', $user->password));
$data = [
'email' => 'test@example.com',
'password' => '123456',
];
try{
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-SECRET' => config('ninja.api_secret'),
])->post('/api/v1/login', $data);
} catch (ValidationException $e) {
$message = json_decode($e->validator->getMessageBag(), 1);
info(print_r($message,1));
}
$arr = $response->json();
info(print_r($arr,1));
$response->assertStatus(200);
}
}