Skip to content

Commit

Permalink
composer update add phpstan-phpunit and phpstan-strict-rules libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
smajti1 committed Dec 26, 2024
1 parent a5272e2 commit b19b965
Show file tree
Hide file tree
Showing 23 changed files with 643 additions and 484 deletions.
18 changes: 9 additions & 9 deletions app/Http/Controllers/AccountWizardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Smajti1\Laravel\Exceptions\StepNotFoundException;
use Smajti1\Laravel\Step;
use Smajti1\Laravel\Wizard;
use Illuminate\Support\Facades\Auth;

class AccountWizardController extends Controller
{
/**
* @var array<int|string, class-string<Step>>
*/
/**
* @var array<int|string, class-string<Step>>
*/
public array $steps = [
SetUserEmailAndPassword::class,
SetCompanyBasicData::class,
Expand All @@ -39,9 +39,9 @@ public function __construct()
}

public function wizard(Step|string|null $step = null): View
{
{
try {
if (!$step) {
if ($step === null || $step === '') {
$step = $this->wizard->firstOrLastProcessed();
} else {
$step = $step instanceof Step ? $step : $this->wizard->getBySlug($step);
Expand All @@ -56,15 +56,15 @@ public function wizard(Step|string|null $step = null): View
}

public function wizardPost(Request $request, Step|string|null $step = null): RedirectResponse
{
try {
{
try {
$step_by_slug = $step instanceof Step ? $step : $this->wizard->getBySlug($step ?? '');
} catch (StepNotFoundException $e) {
abort(404);
}

$this->validate($request, $step_by_slug->rules($request));
$step_by_slug->process($request);
$step_by_slug->process($request);

if ($step_by_slug->index === ($this->wizard->limit() - 1)) {

Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/Api/InvoiceToPdfController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use HeadlessChromium\BrowserFactory;
use Illuminate\Http\Response;
use Illuminate\View\View;
use LogicException;

class InvoiceToPdfController extends Controller
{
Expand Down Expand Up @@ -40,7 +41,7 @@ public function toPdf(Invoice $invoice): Response
'headerTemplate' => '<div></div>',
'footerTemplate' => $html_footer,
];
$pdf = base64_decode($page->pdf($pdf_options)->getBase64());
$pdf = base64_decode($page->pdf($pdf_options)->getBase64(), true) ?: throw new LogicException('Cannot generate PDF');
} finally {
$browser->close();
}
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/CompanyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class CompanyController extends Controller
{

private const JSON_LIST_LIMIT = 20;
private const int JSON_LIST_LIMIT = 20;

/**
* @return Collection<int, Company>
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class ProductController extends Controller
{
private const JSON_LIST_LIMIT = 10;
private const int JSON_LIST_LIMIT = 10;
protected Request $request;

public function __construct(Request $request)
Expand Down Expand Up @@ -51,7 +51,7 @@ public function jsonList(): Collection
->where('name', 'ILIKE', $search . '%')
->limit(self::JSON_LIST_LIMIT)
->get();
if (!$list->count()) {
if ($list->count() === 0) {
$list = $user
->products()
->limit(self::JSON_LIST_LIMIT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public function update(Request $request): RedirectResponse
{
$this->validate($request, $this->rules());
$input = $request->all();
$input['autoincrement_number'] = $request->get('autoincrement_number') ? 1 : 0;
$input['show_number'] = $request->get('show_number') ? 1 : 0;
$input['show_month'] = $request->get('show_month') ? 1 : 0;
$input['show_year'] = $request->get('show_year') ? 1 : 0;
$input['autoincrement_number'] = $request->get('autoincrement_number') === true ? 1 : 0;
$input['show_number'] = $request->get('show_number') === true ? 1 : 0;
$input['show_month'] = $request->get('show_month') === true ? 1 : 0;
$input['show_year'] = $request->get('show_year') === true ? 1 : 0;
/** @var User $user */
$user = Auth::user();

Expand Down
6 changes: 3 additions & 3 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Kernel extends HttpKernel
*
* These middleware are run during every request to your application.
*
* @var array<int, class-string>
* @var array<int, class-string|string>
*/
protected $middleware = [
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
Expand All @@ -24,7 +24,7 @@ class Kernel extends HttpKernel
/**
* The application's route middleware groups.
*
* @var array<string, array<int, class-string|string>>
* @var array<string, array<int, class-string|string>>
*/
protected $middlewareGroups = [
'web' => [
Expand All @@ -48,7 +48,7 @@ class Kernel extends HttpKernel
*
* These middleware may be assigned to groups or used individually.
*
* @var array<string, class-string>
* @var array<string, class-string|string>
*/
protected $routeMiddleware = [
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
Expand Down
4 changes: 2 additions & 2 deletions app/Models/Buyer.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ public function getAddressString(): string
public function getAddress(): array
{
$address = [];
if ($this->street) {
if ($this->street !== '') {
$address[] = $this->street;
}
if ($this->city || $this->zip_code) {
if ($this->city !== '' || $this->zip_code !== '') {
$address[] = implode(' ', [$this->city, $this->zip_code]);
}

Expand Down
5 changes: 3 additions & 2 deletions app/Models/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ public function getRouteKeyName(): string
public function getAddress(): array
{
$address = [];
if ($street = $this->street) {
$street = $this->street;
if ($street !== '') {
if (
strpos($street, 'ul.') === false &&
strpos($street, 'Aleje') !== false
Expand All @@ -138,7 +139,7 @@ public function getAddress(): array
}
$address[] = $street;
}
if ($this->city || $this->zip_code) {
if ($this->city !== '' || $this->zip_code !== '') {
$address[] = implode(' ', [$this->zip_code, $this->city]);
}

Expand Down
4 changes: 1 addition & 3 deletions app/Models/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,7 @@ public function getTotalSum(): array
foreach ($this->invoice_products as $product) {
$totalSum['gross'] += $product->grossPrice();
$totalSum['net'] += $product->netPrice();
if (is_numeric($product->taxAmount())) {
$totalSum['tax'] += $product->taxAmount();
}
$totalSum['tax'] += $product->taxAmount();
}

return $totalSum;
Expand Down
5 changes: 1 addition & 4 deletions app/Models/InvoiceProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@ public function formattedPriceWithVat(): float
{
$price = $this->price;
$vat = $this->calculateVat();
if (is_numeric($vat)) {
$price *= $vat;
}
return (float) $price;
return $price * $vat;
}
}
2 changes: 1 addition & 1 deletion app/Models/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function formattedPriceWithVat(): float
if (is_numeric($vat)) {
$price *= $vat;
}
return (float) $price;
return $price;
}

public function calculateVat(): string
Expand Down
2 changes: 1 addition & 1 deletion app/Providers/DropboxServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function register(): void
public function boot(): void
{
Storage::extend('dropbox', static function ($app, $config) {
$client = new Client(env('DROPBOX_ACCESS_TOKEN'));
$client = new Client((string) env('DROPBOX_ACCESS_TOKEN'));
$dropboxAdapter = new DropboxAdapter($client);
$filesystem = new Filesystem($dropboxAdapter, ['case_sensitive' => false]);

Expand Down
30 changes: 16 additions & 14 deletions app/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Providers;

use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
Expand All @@ -12,7 +14,7 @@ class RouteServiceProvider extends ServiceProvider
*
* In addition, it is set as the URL generator's root namespace.
*
* @var string
* @var string|null
*/
protected $namespace;

Expand All @@ -31,31 +33,31 @@ public function map()
}

/**
* Define the "web" routes for the application.
* Define the "api" routes for the application.
*
* These routes all receive session state, CSRF protection, etc.
* These routes are typically stateless.
*
* @return void
*/
protected function mapWebRoutes()
protected function mapApiRoutes()
{
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
}

/**
* Define the "api" routes for the application.
* Define the "web" routes for the application.
*
* These routes are typically stateless.
* These routes all receive session state, CSRF protection, etc.
*
* @return void
*/
protected function mapApiRoutes()
protected function mapWebRoutes()
{
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
}
}
8 changes: 4 additions & 4 deletions app/Steps/Account/SetAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public function process(Request $request)
{
/** @var User|null $user */
$user = Auth::user();
if ($user && $this->wizard->dataHas('company_id')) {
if ($user !== null && $this->wizard->dataHas('company_id')) {
$company = $this->wizard->dataGet('company_id');
$company = Company::whereId($company)->first() ?? throw new LogicException('Can not find company');

$company->update(
$request->only(['city', 'zip_code', 'street'])
$request->only(['city', 'zip_code', 'street']),
);

$this->saveProgress($request);
Expand All @@ -37,9 +37,9 @@ public function process(Request $request)
public function rules(Request $request = null): array
{
return [
'city' => 'max:255',
'city' => 'max:255',
'zip_code' => 'max:255',
'street' => 'max:255',
'street' => 'max:255',
];
}
}
45 changes: 23 additions & 22 deletions app/Steps/Account/SetCompanyBasicData.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,39 @@ public function process(Request $request): void
$company = Company::whereId($company)->first();
}

if ($user) {
if ($company) {
$company->update([
'name' => $data['company_name'],
'tax_id_number' => $data['tax_id_number'],
'regon' => $data['regon'],
'bank_account' => $data['bank_account'],
]);
} else {
$company = new Company();
$company->fill([
'name' => $data['company_name'],
'tax_id_number' => $data['tax_id_number'],
'regon' => $data['regon'],
'bank_account' => $data['bank_account'],
]);

$company->user()->associate($user);
$company->save();
}
if ($user === null) {
return;
}
if ($company !== null) {
$company->update([
'name' => $data['company_name'],
'tax_id_number' => $data['tax_id_number'],
'regon' => $data['regon'],
'bank_account' => $data['bank_account'],
]);
} else {
$company = new Company();
$company->fill([
'name' => $data['company_name'],
'tax_id_number' => $data['tax_id_number'],
'regon' => $data['regon'],
'bank_account' => $data['bank_account'],
]);

$this->saveProgress($request, ['company_id' => $company->id]);
$company->user()->associate($user);
$company->save();
}

$this->saveProgress($request, ['company_id' => $company->id]);

}

public function rules(Request $request = null): array
{
$company_unique_id = '';
/** @var User $user */
$user = Auth::user();
if ($user->company) {
if ($user->company !== null) {
$company_unique_id = ',' . $user->company->id;
}
return [
Expand Down
6 changes: 3 additions & 3 deletions app/Steps/Account/SetCompanySecondaryData.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function process(Request $request)
$user = Auth::user();
$data = $request->all();

if ($user && $this->wizard->dataHas('company_id')) {
if ($user !== null && $this->wizard->dataHas('company_id')) {
$company = $this->wizard->dataGet('company_id');
$company = Company::whereId($company)->first();
$company?->update([
Expand All @@ -39,9 +39,9 @@ public function process(Request $request)
public function rules(Request $request = null): array
{
return [
'email' => 'max:255',
'email' => 'max:255',
'website' => 'max:255',
'phone' => 'max:255',
'phone' => 'max:255',
];
}
}
Loading

0 comments on commit b19b965

Please sign in to comment.