Skip to content

Commit

Permalink
refactor: implement pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianSDV committed Sep 23, 2024
1 parent 12dae8a commit ee702fd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/Migration/Pdk/SettingsMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,20 +194,20 @@ private function convertShippingMethodId(string $shippingMethod, Collection $wcS

if ($termId) {
$match = $wcShippingMethods
->filter(function ($shippingMethod) use ($termId, $shippingMethodName) {
return $shippingMethod->id === $shippingMethodName && (int) $shippingMethod->instance_id === (int) $termId;
->filter(function ($wcShippingMethod) use ($termId, $shippingMethodName) {
return $wcShippingMethod->id === $shippingMethodName && (int) $wcShippingMethod->instance_id === (int) $termId;
})
->first();

if (! $match) {
/** @var WP_Term|null $foundShippingClass */
$foundShippingClass = $wcShippingMethods
->filter(function ($shippingMethod) use ($termId) {
if (! $shippingMethod instanceof WP_Term) {
->filter(function ($wcShippingMethod) use ($termId) {
if (! $wcShippingMethod instanceof WP_Term) {
return false;
}

return $shippingMethod->term_id === (int) $termId;
return $wcShippingMethod->term_id === (int) $termId;
})
->first();

Expand Down
6 changes: 3 additions & 3 deletions src/Pdk/Plugin/WcShippingMethodRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function __construct(WcShippingRepositoryInterface $wcShippingRepository)
*/
public function all(): PdkShippingMethodCollection
{
// The "0" zone is the "Rest of the World" zone in WooCommerce.
$wcShippingMethods = $this->wcShippingRepository->getShippingMethods();
$wcShippingClasses = $this->wcShippingRepository->getShippingClasses();

Expand Down Expand Up @@ -78,10 +77,11 @@ public function createFromWcShippingClass(WP_Term $shippingClass): PdkShippingMe
*/
private function createFromWcShippingMethod(WC_Shipping_Method $method): PdkShippingMethod
{
$id = $method->get_rate_id();
return new PdkShippingMethod([
'id' => $method->get_rate_id(),
'id' => $id,
'name' => $this->getShippingMethodTitle($method),
'description' => "ID: {$method->get_rate_id()}",
'description' => "ID: $id",
'isEnabled' => 'yes' === $method->enabled && ! $method instanceof WC_Shipping_Local_Pickup,
]);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/mock_wp_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ function get_term_by($field, $value, $taxonomy = '', $output = 'OBJECT', $filter
*
* @return false|mixed|\WP_Term
*/
function get_term($term, $taxonomy = '', $output = OBJECT, $filter = 'raw')
function get_term($term, $taxonomy = '', $output = 'OBJECT', $filter = 'raw')
{
if ($term instanceof WP_Term) {
return MockWpTerm::get_instance($term->term_id, $taxonomy);
Expand Down

0 comments on commit ee702fd

Please sign in to comment.