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

AxeWP / wp-graphql-rank-math / 6257335822

21 Sep 2023 04:53AM UTC coverage: 92.176%. First build
6257335822

Pull #59

github

web-flow
Merge e6916cad3 into a7f39383c
Pull Request #59: chore: Update dev-deps and lint

24 of 24 new or added lines in 11 files covered. (100.0%)

2533 of 2748 relevant lines covered (92.18%)

11.22 hits per line

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

84.78
/src/Model/UserSeo.php
1
<?php
2
/**
3
 * The SEO model for User objects.
4
 *
5
 * @package \WPGraphQL\RankMath\Model
6
 */
7

8
namespace WPGraphQL\RankMath\Model;
9

10
use GraphQL\Error\Error;
11

12
/**
13
 * Class - UserSeo
14
 *
15
 * @property int $ID the database ID.
16
 */
17
class UserSeo extends Seo {
18
        /**
19
         * Stores the incoming post data
20
         *
21
         * @var \WP_User $data
22
         */
23
        protected $data;
24

25
        /**
26
         * The global authordata at time of Model generation
27
         *
28
         * @var ?\WP_User
29
         */
30
        protected $global_authordata;
31

32
        /**
33
         * The settings prefix
34
         *
35
         * @var string
36
         */
37
        protected string $prefix;
38

39
        /**
40
         * Constructor.
41
         *
42
         * @param int $user_id .
43
         * @throws \GraphQL\Error\Error .
44
         */
45
        public function __construct( int $user_id ) {
46
                $object = get_user_by( 'id', $user_id );
1✔
47
                if ( false === $object ) {
1✔
48
                        throw new Error(
×
49
                                sprintf(
×
50
                                        // translators: post id .
51
                                        esc_html__( 'Invalid user id %d passed to UserSeo model.', 'wp-graphql-rank-math' ),
×
52
                                        absint( $user_id ),
×
53
                                )
×
54
                        );
×
55
                }
56

57
                $this->database_id = $object->ID;
1✔
58

59
                parent::__construct( $object );
1✔
60
        }
61

62
        /**
63
         * {@inheritDoc}
64
         */
65
        public function setup(): void {
66
                global $wp_query, $post, $author, $authordata;
1✔
67

68
                // Store variables for resetting at tear down.
69
                $this->global_post       = $post;
1✔
70
                $this->global_authordata = $authordata;
1✔
71

72
                if ( $this->data instanceof \WP_User ) {
1✔
73

74
                        // Reset postdata.
75
                        $wp_query->reset_postdata();
1✔
76

77
                        // Parse the query to setup global state.
78
                        $wp_query->parse_query(
1✔
79
                                [
1✔
80
                                        'author_name' => $this->data->user_nicename,
1✔
81
                                ]
1✔
82
                        );
1✔
83

84
                        // Setup globals.
85
                        $wp_query->is_author         = true;
1✔
86
                        $GLOBALS['authordata']       = $this->data; // phpcs:ignore WordPress.WP.GlobalVariablesOverride
1✔
87
                        $author                      = $this->data->ID; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound,SlevomatCodingStandard.Variables.UnusedVariable.UnusedVariable
1✔
88
                        $wp_query->queried_object    = $this->data;
1✔
89
                        $wp_query->queried_object_id = $this->data->ID;
1✔
90
                }
91

92
                parent::setup();
1✔
93
        }
94

95
        /**
96
         * Reset global state after the model fields
97
         * have been generated
98
         *
99
         * @return void
100
         */
101
        public function tear_down() {
102
                global $author;
1✔
103
                if ( $this->data instanceof \WP_User ) {
1✔
104
                        $author                = isset( $this->global_authordata ) ? $this->global_authordata->ID : null; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
1✔
105
                        $GLOBALS['authordata'] = $this->global_authordata; // phpcs:ignore WordPress.WP.GlobalVariablesOverride
1✔
106
                        $GLOBALS['post']       = $this->global_post; // phpcs:ignore WordPress.WP.GlobalVariablesOverride
1✔
107
                }
108

109
                wp_reset_postdata();
1✔
110
        }
111

112
        /**
113
         * {@inheritDoc}
114
         */
115
        protected function init() {
116
                if ( empty( $this->fields ) ) {
1✔
117
                        parent::init();
1✔
118

119
                        $this->fields = array_merge(
1✔
120
                                $this->fields,
1✔
121
                                [
1✔
122
                                        'breadcrumbTitle' => function (): ?string {
1✔
123
                                                $title = $this->get_meta( 'breadcrumb_title', '', $this->data->display_name );
1✔
124

125
                                                return ! empty( $title ) ? html_entity_decode( $title, ENT_QUOTES ) : null;
1✔
126
                                        },
1✔
127
                                        'ID'              => fn (): int => $this->database_id,
1✔
128
                                ]
1✔
129
                        );
1✔
130
                }
131
        }
132

133
        /**
134
         * {@inheritDoc}
135
         */
136
        public function get_object_type(): string {
137
                return 'User';
×
138
        }
139

140
        /**
141
         * {@inheritDoc}
142
         *
143
         * @throws \GraphQL\Error\UserError If no valid term link.
144
         */
145
        protected function get_object_url(): string {
146
                return get_author_posts_url( $this->database_id );
1✔
147
        }
148
}
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

© 2025 Coveralls, Inc