• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wp-graphql / wp-graphql-woocommerce / 9122748207

17 May 2024 04:03AM UTC coverage: 85.048% (+0.4%) from 84.647%
9122748207

push

github

web-flow
feat: Queries and mutations for shipping zones, tax classes, and tax rates. (#856)

* fix: General bugfixes and improvements

* devops: New mutations and types tested and compliance with Linter and PHPStan

* chore: hooks added to the mutation resolvers

* feat: permission checks added

* chore: Linter and compliance met

* chore: Linter and compliance met

1252 of 1399 new or added lines in 39 files covered. (89.49%)

9 existing lines in 2 files now uncovered.

12423 of 14607 relevant lines covered (85.05%)

70.56 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.24
/includes/model/class-shipping-method.php
1
<?php
2
/**
3
 * Model - Shipping_Method
4
 *
5
 * Resolves shipping method object model
6
 *
7
 * @package WPGraphQL\WooCommerce\Model
8
 * @since 0.0.2
9
 */
10

11
namespace WPGraphQL\WooCommerce\Model;
12

13
use GraphQLRelay\Relay;
14
use WPGraphQL\Model\Model;
15

16
/**
17
 * Class Shipping_Method
18
 *
19
 * @property \WC_Shipping_Method $data
20
 *
21
 * @property int    $ID
22
 * @property string $id
23
 * @property int    $databaseId
24
 * @property string $title
25
 * @property string $description
26
 *
27
 * @package WPGraphQL\WooCommerce\Model
28
 */
29
class Shipping_Method extends Model {
30
        /**
31
         * Shipping_Method constructor
32
         *
33
         * @param \WC_Shipping_Method $method - Shipping method object.
34
         */
35
        public function __construct( $method ) {
36
                $this->data                = $method;
6✔
37
                $allowed_restricted_fields = [
6✔
38
                        'isRestricted',
6✔
39
                        'isPrivate',
6✔
40
                        'isPublic',
6✔
41
                        'id',
6✔
42
                        'databaseId',
6✔
43
                ];
6✔
44

45
                // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
46
                $restricted_cap = apply_filters( 'shipping_method_restricted_cap', '' );
6✔
47

48
                parent::__construct( $restricted_cap, $allowed_restricted_fields, null );
6✔
49
        }
50

51
        /**
52
         * Determines if the order item should be considered private.
53
         *
54
         * @return bool
55
         */
56
        protected function is_private() {
57
                return false;
6✔
58
        }
59

60
        /**
61
         * Initializes the Order field resolvers.
62
         */
63
        protected function init() {
64
                if ( empty( $this->fields ) ) {
6✔
65
                        $this->fields = [
6✔
66
                                'ID'          => function () {
6✔
67
                                        return $this->data->id;
2✔
68
                                },
6✔
69
                                'id'          => function () {
6✔
70
                                        return ! empty( $this->data->id ) ? Relay::toGlobalId( 'shipping_method', $this->data->id ) : null;
6✔
71
                                },
6✔
72
                                'databaseId'  => function () {
6✔
73
                                        return ! empty( $this->ID ) ? $this->ID : null;
2✔
74
                                },
6✔
75
                                'title'       => function () {
6✔
76
                                        return ! empty( $this->data->method_title ) ? $this->data->method_title : null;
4✔
77
                                },
6✔
78
                                'description' => function () {
6✔
79
                                        return ! empty( $this->data->method_description ) ? $this->data->method_description : null;
4✔
80
                                },
6✔
81
                        ];
6✔
82
                }
83
        }
84

85
        /**
86
         * Forwards function calls to WC_Data sub-class instance.
87
         *
88
         * @param string $method - function name.
89
         * @param array  $args  - function call arguments.
90
         *
91
         * @return mixed
92
         *
93
         * @throws \BadMethodCallException Method not found on WC data object.
94
         */
95
        public function __call( $method, $args ) {
NEW
96
                if ( \is_callable( [ $this->data, $method ] ) ) {
×
NEW
97
                        return $this->data->$method( ...$args );
×
98
                }
99

NEW
100
                $class = self::class;
×
NEW
101
                throw new \BadMethodCallException( "Call to undefined method {$method} on the {$class}" );
×
102
        }
103

104
        /**
105
         * Returns the source WC_Data instance
106
         *
107
         * @return \WC_Shipping_Method
108
         */
109
        public function as_WC_Data() {
110
                return $this->data;
4✔
111
        }
112
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc