Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/php 81 #178

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 0 additions & 77 deletions Vagrantfile

This file was deleted.

2 changes: 1 addition & 1 deletion api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM cgsmith105/yii2-php:8.0-apache
FROM yiisoftware/yii2-php:8.1-apache

# Change document root for Apache
RUN sed -i -e 's|/app/web|/app/api/web|g' /etc/apache2/sites-available/000-default.conf
15 changes: 4 additions & 11 deletions api/modules/v1/components/ControllerEx.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected function orderCreate(OrderForm $orderForm)
$order->requested_ship_date = $orderForm->requestedShipDate;
$order->must_arrive_by_date = $orderForm->mustArriveByDate;
$order->notes = $orderForm->notes;
$order->status_id = isset($orderForm->status) ? $orderForm->status : null;
$order->status_id = $orderForm->status ?? null;
$order->address_id = $address->id;
$order->transit = $orderForm->transit;
$order->packagingNotes = $orderForm->packagingNotes;
Expand Down Expand Up @@ -198,11 +198,7 @@ protected function orderCreate(OrderForm $orderForm)
// Commit DB transaction
$transaction->commit();

} catch (\Exception $e) {
$transaction->rollBack();

return $this->errorMessage(400, 'Could not save order');
} catch (\Throwable $e) {
} catch (\Exception|\Throwable $e) {
$transaction->rollBack();

return $this->errorMessage(400, 'Could not save order');
Expand Down Expand Up @@ -439,10 +435,7 @@ public function orderUpdate(OrderForm $orderForm, $id)
// Commit DB transaction
$transaction->commit();

} catch (\Exception $e) {
$transaction->rollBack();
return $this->errorMessage(400, 'Could not save order', $e);
} catch (\Throwable $e) {
} catch (\Exception|\Throwable $e) {
$transaction->rollBack();
return $this->errorMessage(400, 'Could not save order', $e);
}
Expand Down Expand Up @@ -515,12 +508,12 @@ public function success($response, $code = 200)
*
* @param int $code HTTP code
* @param string $message Error message
* @param \Exception $exception
*
* @return array
*/
public function errorMessage($code, string $message = 'Unknown Error', \Exception $exception = null)
{
$return = [];
$this->response->setStatusCode($code);
$return['message'] = $message;

Expand Down
8 changes: 4 additions & 4 deletions api/modules/v1/components/parameters/Pagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
class Pagination extends Behavior
{

const PAGE_NUMBER = 0;
const PAGE_SIZE = 10;
final const PAGE_NUMBER = 0;
final const PAGE_SIZE = 10;
Comment on lines +21 to +22
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
final const PAGE_NUMBER = 0;
final const PAGE_SIZE = 10;
private const PAGE_NUMBER = 0;
private const PAGE_SIZE = 10;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But please ensure that it's not used externally.


CONST PAGE_SIZE_MIN = 0;
const PAGE_SIZE_MAX = 1000;
final CONST PAGE_SIZE_MIN = 0;
final const PAGE_SIZE_MAX = 1000;
Comment on lines +24 to +25
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
final CONST PAGE_SIZE_MIN = 0;
final const PAGE_SIZE_MAX = 1000;
private CONST PAGE_SIZE_MIN = 0;
private const PAGE_SIZE_MAX = 1000;


/** @var pagination */
public $pagination;
Expand Down
6 changes: 3 additions & 3 deletions api/modules/v1/controllers/CustomerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function actionIndex()
* @throws \yii\base\InvalidConfigException
* @throws ForbiddenHttpException
*/
public function actionCreate()
public function actionCreate(): array|\api\modules\v1\models\customer\CustomerEx
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return type is wrong.

{
// Check permissions
if (!$this->apiConsumer->isSuperuser()) {
Expand Down Expand Up @@ -238,7 +238,7 @@ public function actionCreate()
* @return array|\api\modules\v1\models\customer\CustomerEx
* @throws ForbiddenHttpException
*/
public function actionView($id)
public function actionView($id): array|\api\modules\v1\models\customer\CustomerEx
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return type is wrong.

{
// Check permissions
if (!$this->apiConsumer->isSuperuser()) {
Expand Down Expand Up @@ -325,7 +325,7 @@ public function actionView($id)
* @throws \yii\base\InvalidConfigException
* @throws ForbiddenHttpException
*/
public function actionUpdate($id)
public function actionUpdate($id): array|\api\modules\v1\models\customer\CustomerEx
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return type is wrong.

{

// Check permissions
Expand Down
2 changes: 1 addition & 1 deletion api/modules/v1/controllers/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DefaultController extends Controller
/**
* Renders the index view for the module
*/
public function actionIndex()
public function actionIndex(): never
{
throw new NotFoundHttpException('Unsupported action request.');
}
Expand Down
20 changes: 7 additions & 13 deletions api/modules/v1/controllers/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public function actionIndex()
* @throws \yii\base\InvalidConfigException
* @throws \yii\db\Exception
*/
public function actionCreate()
public function actionCreate(): array|\api\modules\v1\models\order\OrderEx
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return type is wrong. Same in similar cases.

{
// Build the Order Form with the attributes sent in request
$orderForm = new OrderForm();
Expand Down Expand Up @@ -267,7 +267,7 @@ public function actionCreate()
*
* @return array|\api\modules\v1\models\order\OrderEx
*/
public function actionView($id)
public function actionView($id): array|\api\modules\v1\models\order\OrderEx
{
if (($order = OrderEx::find()
->byId($id)
Expand Down Expand Up @@ -353,7 +353,7 @@ public function actionView($id)
* @throws \yii\base\InvalidConfigException
* @throws \yii\db\Exception
*/
public function actionUpdate($id)
public function actionUpdate($id): array|\api\modules\v1\models\order\OrderEx
{
// Build the Order Form with the attributes sent in request
$orderForm = new OrderForm();
Expand Down Expand Up @@ -455,11 +455,7 @@ public function actionDelete($id)

$transaction->commit();

} catch (\Exception $e) {
$transaction->rollBack();

return $this->errorMessage(400, 'Could not delete order');
} catch (\Throwable $e) {
} catch (\Exception|\Throwable $e) {
$transaction->rollBack();

return $this->errorMessage(400, 'Could not delete order');
Expand Down Expand Up @@ -515,15 +511,14 @@ public function actionDelete($id)
* }}
* )
*/

/**
* Get items of a specific order
*
* @param int $id Order ID
*
* @return array|\api\modules\v1\models\order\ItemEx
*/
public function actionItems($id)
public function actionItems($id): array|\api\modules\v1\models\order\ItemEx
{
if (($order = OrderEx::find()
->byId($id)
Expand All @@ -543,7 +538,7 @@ public function actionItems($id)
*
* @return array|\api\modules\v1\models\order\PackageEx
*/
public function actionPackages($id)
public function actionPackages($id): array|\api\modules\v1\models\order\PackageEx
{
if (($order = OrderEx::find()
->byId($id)
Expand Down Expand Up @@ -902,7 +897,6 @@ public function actionStatus(int $id)
* }}
* )
*/

/**
* Find order by criteria
*
Expand All @@ -911,7 +905,7 @@ public function actionStatus(int $id)
*
* @return array|\api\modules\v1\models\order\OrderEx
*/
public function actionFind()
public function actionFind(): array|\api\modules\v1\models\order\OrderEx
{
$customerReference = $this->request->get('customer-reference', null);

Expand Down
2 changes: 1 addition & 1 deletion api/modules/v1/controllers/SkuController.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public function actionDelete($id)
*
* @return array|\api\modules\v1\models\sku\SkuEx
*/
public function actionFind()
public function actionFind(): array|\api\modules\v1\models\sku\SkuEx
{
$customerReference = $this->request->get('sku', null);

Expand Down
6 changes: 3 additions & 3 deletions api/modules/v1/models/core/ApiConsumerEx.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
class ApiConsumerEx extends ApiConsumer implements IdentityInterface
{

const DATETIME_FORMAT = 'Y-m-d H:i:s';
const EXPIRE_TOKEN_AFTER = 15; // Time in minutes after which the auth token will expire
final const DATETIME_FORMAT = 'Y-m-d H:i:s';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to add visibility modifier here and in similar case such as private.

final const EXPIRE_TOKEN_AFTER = 15; // Time in minutes after which the auth token will expire

/** @inheritdoc */
public static function findIdentity($id)
Expand Down Expand Up @@ -99,7 +99,7 @@ public function isSuperuser()
* @return string|\DateTime
* @throws \Exception
*/
public function getTokenExpiration($formatted = true)
public function getTokenExpiration($formatted = true): string|\DateTime
{
$lastActivity = new \DateTime($this->last_activity, new \DateTimeZone("UTC"));
$expiresOn = $lastActivity->add(
Expand Down
4 changes: 2 additions & 2 deletions api/modules/v1/models/forms/AddressForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@
*/
class AddressForm extends Model
{
const SCENARIO_DEFAULT = 'default'; // ship to address
const SCENARIO_FROM = 'from'; // ship from address
final const SCENARIO_DEFAULT = 'default'; // ship to address
final const SCENARIO_FROM = 'from'; // ship from address

/** @var string */
public $name;
Expand Down
6 changes: 3 additions & 3 deletions api/modules/v1/models/forms/OrderForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@
class OrderForm extends Model
{

const SCENARIO_DEFAULT = 'default'; // the create scenario
const SCENARIO_UPDATE = 'update'; // the update scenario
const SCENARIO_DELETE = 'delete'; // the delete scenario
final const SCENARIO_DEFAULT = 'default'; // the create scenario
final const SCENARIO_UPDATE = 'update'; // the update scenario
final const SCENARIO_DELETE = 'delete'; // the delete scenario

/** @var string */
public $uuid;
Expand Down
8 changes: 2 additions & 6 deletions api/modules/v1/models/forms/ShippingRateForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,13 @@ public function rules()
[
'carrier',
'required',
'when' => function ($model) {
return (empty($this->carrier) && empty($this->service));
},
'when' => fn($model) => empty($this->carrier) && empty($this->service),
'message' => "Carrier code is required when service code is not set. Set the carrier to get all available services. Or set the service code to get rates for that specific service.",
],
[
'service',
'required',
'when' => function ($model) {
return (empty($this->carrier) && empty($this->service));
},
'when' => fn($model) => empty($this->carrier) && empty($this->service),
'message' => "Service code is required when carrier code is not set. Set the carrier to get all available services. Or set the service code to get rates for that specific service.",
],
[
Expand Down
2 changes: 1 addition & 1 deletion api/modules/v1/models/forms/StatusForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
class StatusForm extends Model
{

const SCENARIO_DEFAULT = 'default'; // the create scenario
final const SCENARIO_DEFAULT = 'default'; // the create scenario


/** @var string */
Expand Down
4 changes: 2 additions & 2 deletions api/modules/v1/models/forms/shipment/Dimensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
class Dimensions extends Model
{

const UNITS_IN = 'IN';
const UNITS_CM = 'CM';
final const UNITS_IN = 'IN';
final const UNITS_CM = 'CM';

protected static $unitsTypes = [
self::UNITS_IN => self::UNITS_IN,
Expand Down
4 changes: 1 addition & 3 deletions api/modules/v1/models/forms/shipment/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ public function rules()
[
['weight', 'dimensions'],
'required',
'when' => function ($model) {
return $model->type == PackageType::MY_PACKAGE;
},
'when' => fn($model) => $model->type == PackageType::MY_PACKAGE,
'message' => 'Package {attribute} is required.',
],
[
Expand Down
4 changes: 2 additions & 2 deletions api/modules/v1/models/forms/shipment/Weight.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
class Weight extends Model
{

const UNITS_LB = 'LB';
const UNITS_KG = 'KG';
final const UNITS_LB = 'LB';
final const UNITS_KG = 'KG';

protected static $unitsTypes = [
self::UNITS_LB => self::UNITS_LB,
Expand Down
8 changes: 2 additions & 6 deletions api/modules/v1/models/order/OrderEx.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,9 @@ public function fields()
'status' => 'status',
'customer' => 'customer',
'carrier_id' => 'carrier_id',
'carrier_name' => function () {
return isset($this->carrier) ? $this->carrier['name'] : '';
},
'carrier_name' => fn() => isset($this->carrier) ? $this->carrier['name'] : '',
'service_id' => 'service_id',
'service_name' => function () {
return isset($this->service) ? $this->service['name'] : '';
},
'service_name' => fn() => isset($this->service) ? $this->service['name'] : '',
'poNumber' => 'po_number',
'uuid' => 'uuid',
'notes' => 'notes',
Expand Down
Loading