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

PES-2404: PHPStan level 6 #674

Merged
merged 2 commits into from
Dec 6, 2024
Merged
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
5 changes: 4 additions & 1 deletion phpstan/module.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ parameters:
- ../vendor/php-stubs/woocommerce-stubs/woocommerce-stubs.php
- ../vendor/php-stubs/woocommerce-stubs/woocommerce-packages-stubs.php
- ../constants.php
level: 5
level: 6
ignoreErrors:
- '#Method .*::.*\(\) has parameter \$\w+ with no value type specified in iterable type array#'
- '#Method .*::.*\(\) return type has no value type specified in iterable type array#'
paths:
- ../src/Packetery/Module
treatPhpDocTypesAsCertain: false
Expand Down
3 changes: 2 additions & 1 deletion src/Packetery/Core/Api/Soap/CreatePacketMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public function __construct( CoreHelper $coreHelper, CarrierOptionsFactory $carr
* Maps order data to CreatePacket structure.
*
* @param Entity\Order $order Order entity.
* @return array<string, mixed>
*
* @return array<string, array<int<0, max>|string, array<string, array<int, array<string, bool|float|int|string|null>>|float|string|null>|float|null>|float|int|string|null>
*/
public function fromOrderToArray( Entity\Order $order ): array {
$createPacketData = [
Expand Down
6 changes: 3 additions & 3 deletions src/Packetery/Core/Api/Soap/Request/PacketsLabelsPdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class PacketsLabelsPdf {
/**
* PacketsLabelsPdf constructor.
*
* @param array<string> $packetIds Packet ids.
* @param string $labelFormat Label format.
* @param int $offset Offset.
* @param string[] $packetIds Packet ids.
* @param string $labelFormat Label format.
* @param int $offset Offset.
*/
public function __construct( array $packetIds, string $labelFormat, int $offset ) {
$this->packetIds = $packetIds;
Expand Down
23 changes: 11 additions & 12 deletions src/Packetery/Module/Api/Internal/CheckoutController.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,38 +99,35 @@ public function registerRoutes(): void {
}

/**
* Save selected pickup point.
*
* @param WP_REST_Request $request Full data about the request.
* @param WP_REST_Request<string[]> $request
*
* @return WP_REST_Response
*/
// phpcs:ignore Squiz.Commenting.FunctionComment.IncorrectTypeHint
public function saveSelectedPickupPoint( WP_REST_Request $request ): WP_REST_Response {
$this->save( $request, Attribute::$pickupPointAttrs );

return new WP_REST_Response( [], 200 );
}

/**
* Save validated address.
*
* @param WP_REST_Request $request Full data about the request.
* @param WP_REST_Request<string[]> $request
*
* @return WP_REST_Response
*/
// phpcs:ignore Squiz.Commenting.FunctionComment.IncorrectTypeHint
public function saveValidatedAddress( WP_REST_Request $request ): WP_REST_Response {
$this->save( $request, Attribute::$homeDeliveryAttrs );

return new WP_REST_Response( [], 200 );
}

/**
* Save car delivery details.
*
* @param WP_REST_Request $request Full data about the request.
* @param WP_REST_Request<string[]> $request
*
* @return WP_REST_Response
*/
// phpcs:ignore Squiz.Commenting.FunctionComment.IncorrectTypeHint
public function saveCarDeliveryDetails( WP_REST_Request $request ): WP_REST_Response {
$this->save( $request, Attribute::$carDeliveryAttrs );

Expand All @@ -140,10 +137,11 @@ public function saveCarDeliveryDetails( WP_REST_Request $request ): WP_REST_Resp
/**
* Removes saved selected pickup point or validated address.
*
* @param WP_REST_Request $request Full data about the request.
* @param WP_REST_Request<string[]> $request
*
* @return WP_REST_Response
*/
// phpcs:ignore Squiz.Commenting.FunctionComment.IncorrectTypeHint
public function removeSavedData( WP_REST_Request $request ): WP_REST_Response {
$params = $request->get_params();
if ( ! isset( $params['carrierId'] ) || '' === $params['carrierId'] ) {
Expand Down Expand Up @@ -173,11 +171,12 @@ public function removeSavedData( WP_REST_Request $request ): WP_REST_Response {
/**
* Saves carrier data.
*
* @param WP_REST_Request $request Full data about the request.
* @param array $carrierAttrs Carrier attributes.
* @param WP_REST_Request<string[]> $request
* @param array $carrierAttrs
*
* @return void
*/
// phpcs:ignore Squiz.Commenting.FunctionComment.IncorrectTypeHint
private function save( WP_REST_Request $request, array $carrierAttrs ): void {
$parameters = $request->get_body_params();
$savedData = get_transient( $this->checkout->getTransientNamePacketaCheckoutData() );
Expand Down
10 changes: 4 additions & 6 deletions src/Packetery/Module/Api/Internal/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,11 @@ public function registerRoutes(): void {
}

/**
* Update one item from the collection
*
* @param WP_REST_Request $request Full data about the request.
* @param WP_REST_Request<string[]> $request
*
* @return WP_REST_Response|WP_Error
*/
// phpcs:ignore Squiz.Commenting.FunctionComment.IncorrectTypeHint
public function saveModal( WP_REST_Request $request ) {
$data = [];
$parameters = $request->get_body_params();
Expand Down Expand Up @@ -238,12 +237,11 @@ public function saveModal( WP_REST_Request $request ) {
}

/**
* Update one item from the collection
*
* @param WP_REST_Request $request Full data about the request.
* @param WP_REST_Request<string[]> $request
*
* @return WP_REST_Response|WP_Error
*/
// phpcs:ignore Squiz.Commenting.FunctionComment.IncorrectTypeHint
public function saveStoredUntil( WP_REST_Request $request ) {
$data = [];
$parameters = $request->get_body_params();
Expand Down
4 changes: 2 additions & 2 deletions src/Packetery/Module/Blocks/WidgetIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class WidgetIntegration implements IntegrationInterface {
/**
* Settings.
*
* @var array
* @var array<string, mixed>
*/
public $settings;

Expand Down Expand Up @@ -96,7 +96,7 @@ public function get_editor_script_handles(): array {
/**
* Gets script data.
*
* @return array
* @return array<string, mixed>
*/
public function get_script_data(): array {
return $this->settings;
Expand Down
6 changes: 3 additions & 3 deletions src/Packetery/Module/Carrier/CountryListingTemplateParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ class CountryListingTemplateParams {
/**
* Carriers Update params.
*
* @var array
* @var array<string, string|array<string, string>>
*/
public $carriersUpdate;

/**
* Countries.
*
* @var array
* @var mixed[]
*/
public $countries;

Expand Down Expand Up @@ -54,7 +54,7 @@ class CountryListingTemplateParams {
/**
* Translations.
*
* @var array
* @var array<string, string>
*/
public $translations;

Expand Down
6 changes: 3 additions & 3 deletions src/Packetery/Module/Carrier/Downloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function __construct(
/**
* Runs update and returns result.
*
* @return array
* @return string[]
*/
public function run(): array {
try {
Expand Down Expand Up @@ -123,7 +123,7 @@ public function runAndRender(): void {
/**
* Downloads carriers and returns in array.
*
* @return array|null
* @return array<int, array<string, string>>|null
* @throws WebRequestException DownloadException.
*/
private function fetch_as_array(): ?array {
Expand All @@ -147,7 +147,7 @@ private function download_json(): string {
*
* @param string $json JSON.
*
* @return array|null
* @return array<int, array<string, string>>|null
*/
private function get_from_json( string $json ): ?array {
$carriersData = json_decode( $json, true );
Expand Down
10 changes: 2 additions & 8 deletions src/Packetery/Module/Carrier/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Options {
/**
* Options.
*
* @var array
* @var array<string, string|bool|array<string, string|bool>>
*/
private $options;

Expand Down Expand Up @@ -82,13 +82,7 @@ public function getAgeVerificationFee(): ?float {
* @return string
*/
public function getAddressValidation(): string {
$none = 'none';
$value = $this->options['address_validation'] ?? $none;
if ( $value ) {
return $value;
}

return $none;
return $this->options['address_validation'] ?? 'none';
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Packetery/Module/Carrier/PacketaPickupPointsConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function getCompoundCarriers(): array {
*
* @param string $carrierId Carrier id.
*
* @return array
* @return string[]
*/
public function getCompoundCarrierVendorGroups( string $carrierId ): array {
$vendorGroups = [];
Expand Down Expand Up @@ -196,7 +196,7 @@ public function isInternalPickupPointCarrier( string $carrierId ): bool {
*
* @param string $country Country.
*
* @return array
* @return array<int<0, max>, BaseProvider>
*/
public function getNonFeedCarriersByCountry( string $country ): array {
$filteredCarriers = [];
Expand Down
4 changes: 2 additions & 2 deletions src/Packetery/Module/Carrier/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function hasPickupPoints( int $carrierId ): bool {
*
* @param int $carrierId Carrier id.
*
* @return array|null
* @return array<string, string>|null
*/
public function getById( int $carrierId ): ?array {
return $this->wpdbAdapter->get_row(
Expand Down Expand Up @@ -153,7 +153,7 @@ public function getActiveCarriers(): ?array {
/**
* Gets all carriers.
*
* @return array[]
* @return array<int, array<string, string|float|bool>>
*/
public function getAllRawIndexed(): array {
$unIndexedResult = $this->wpdbAdapter->get_results(
Expand Down
20 changes: 10 additions & 10 deletions src/Packetery/Module/Carrier/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Updater {
/**
* Log messages.
*
* @var array
* @var string[]
*/
private $logMessages = [];

Expand Down Expand Up @@ -54,7 +54,7 @@ public function __construct( Repository $carrierRepository, ILogger $logger ) {
/**
* Validates data from API.
*
* @param array $carriers Data retrieved from API.
* @param non-empty-array<int, array<string, string>> $carriers
*
* @return bool
*/
Expand Down Expand Up @@ -85,9 +85,9 @@ public function validate_carrier_data( array $carriers ): bool {
/**
* Maps input data to storage structure.
*
* @param array $carriers Validated data retrieved from API.
* @param array<int, array<string, string>> $carriers $carriers Validated data retrieved from API.
*
* @return array data to store in db
* @return array<int, array<string, string|float|bool>> data to store in db
*/
private function carriers_mapper( array $carriers ): array {
$mappedData = array();
Expand Down Expand Up @@ -124,14 +124,14 @@ private function carriers_mapper( array $carriers ): array {
/**
* Saves carriers.
*
* @param array $carriers Validated data retrieved from API.
* @param array<int, array<string, string>> $carriers Validated data retrieved from API.
*/
public function save( array $carriers ): void {
$mappedData = $this->carriers_mapper( $carriers );
$carriersInDb = $this->carrierRepository->getAllRawIndexed();
foreach ( $mappedData as $carrierId => $carrier ) {
if ( isset( $carriersInDb[ $carrierId ] ) ) {
$this->carrierRepository->update( $carrier, (int) $carrierId );
$this->carrierRepository->update( $carrier, $carrierId );
$differences = $this->getArrayDifferences( $carriersInDb[ $carrierId ], $carrier );
if ( count( $differences ) > 0 ) {
$this->addLogEntry(
Expand Down Expand Up @@ -175,10 +175,10 @@ public function save( array $carriers ): void {
/**
* Gets array changes as array of strings.
*
* @param array $oldData Previous version.
* @param array $newData New version.
* @param array<string, string> $oldData Previous version.
* @param array<string, string|float|bool> $newData New version.
*
* @return string[]
* @return array<string, string>
*/
private function getArrayDifferences( array $oldData, array $newData ): array {
$differences = [];
Expand Down Expand Up @@ -236,7 +236,7 @@ private function addLogEntry( string $message ): void {
/**
* Gets translations and isBoolean properties for column names.
*
* @return array[]
* @return array<string, array<string, string|bool>>
*/
private function getColumnSettings(): array {
return [
Expand Down
14 changes: 5 additions & 9 deletions src/Packetery/Module/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,11 +464,7 @@ public function validateCheckoutData(): void {

if ( $this->isPickupPointOrder() ) {
$error = false;
/**
* Returns array always.
*
* @var array $requiredAttrs
*/

$requiredAttrs = array_filter(
array_combine(
array_column( Order\Attribute::$pickupPointAttrs, 'name' ),
Expand Down Expand Up @@ -1238,10 +1234,10 @@ private function removeShippingMethodPrefix( string $chosenMethod ): string {
/**
* Create shipping rate.
*
* @param string $name Name.
* @param string $optionId Option ID.
* @param float $taxExclusiveCost Cost.
* @param array<float>|null $taxes Taxes. If NULL than it is going to be calculated.
* @param string $name Name.
* @param string $optionId Option ID.
* @param float $taxExclusiveCost Cost.
* @param float[]|null $taxes Taxes. If NULL than it is going to be calculated.
*
* @return array
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Packetery/Module/CustomsDeclaration/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function getItemsByCustomsDeclarationId( ?string $customsDeclarationId ):
if ( null === $customsDeclarationId ) {
return [];
}
/** @var null|array $customsDeclarationItemRows */
/** @var null|array<string, string[]> $customsDeclarationItemRows */
$customsDeclarationItemRows = $this->wpdbAdapter->get_results(
sprintf(
'SELECT
Expand Down
2 changes: 1 addition & 1 deletion src/Packetery/Module/DashboardWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class DashboardWidget {
/**
* Survey config.
*
* @var array
* @var array<string, bool|string>
*/
private $surveyConfig;

Expand Down
2 changes: 1 addition & 1 deletion src/Packetery/Module/EntityFactory/Carrier.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Carrier {
/**
* Carrier factory.
*
* @param array $dbResult Data from db.
* @param array<string, string> $dbResult Data from db.
*
* @return Entity\Carrier
*/
Expand Down
Loading