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

AxeWP / wp-graphql-rank-math / 6257663232

21 Sep 2023 05:40AM UTC coverage: 92.176% (+0.8%) from 91.344%
6257663232

push

github

web-flow
chore: Update dev-deps and lint (#59)

* chore: update dev deps

* chore: Lint for wp-graphql-cs:2.0.0-beta

* chore: lint access-functions

* chore: set wp-graphql-stubs to fixed version

27 of 27 new or added lines in 12 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

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

8
namespace WPGraphQL\RankMath\Model;
9

10
use GraphQL\Error\Error;
11
use GraphQL\Error\UserError;
12
use WPGraphQL;
13

14
/**
15
 * Class - ContentTypeSeo
16
 */
17
class ContentTypeSeo extends Seo {
18
        /**
19
         * Stores the incoming post type data.
20
         *
21
         * @var \WP_Post_Type $data
22
         */
23
        protected $data;
24

25
        /**
26
         * The settings prefix.
27
         *
28
         * @var string
29
         */
30
        protected string $prefix;
31

32
        /**
33
         * Constructor.
34
         *
35
         * @param string $post_type .
36
         * @throws \GraphQL\Error\Error .
37
         */
38
        public function __construct( string $post_type ) {
39
                $object = get_post_type_object( $post_type );
1✔
40
                if ( null === $object ) {
1✔
41
                        throw new Error(
×
42
                                sprintf(
×
43
                                        // translators: post type .
44
                                        esc_html__( 'Invalid post type %s passed to ContentTypeSeo model.', 'wp-graphql-rank-math' ),
×
45
                                        esc_html( $post_type ),
×
46
                                )
×
47
                        );
×
48
                }
49

50
                $capability = isset( $object->cap->edit_posts ) ? $object->cap->edit_posts : 'edit_posts';
1✔
51

52
                $allowed_fields = [ 'breadcrumbTitle' ];
1✔
53

54
                global $wp_query;
1✔
55

56
                $wp_query->parse_query( [ 'post_type' => $post_type ] );
1✔
57

58
                parent::__construct( $object, $capability, $allowed_fields );
1✔
59
        }
60

61
        /**
62
         * {@inheritDoc}
63
         */
64
        protected function init() {
65
                if ( empty( $this->fields ) ) {
1✔
66
                        parent::init();
1✔
67

68
                        $this->fields = array_merge(
1✔
69
                                $this->fields,
1✔
70
                                [
1✔
71
                                        'breadcrumbTitle' => fn (): ?string => ! empty( $this->data->labels->singular_name ) ? $this->data->labels->singular_name : null,
1✔
72

73
                                ]
1✔
74
                        );
1✔
75
                }
76
        }
77

78
        /**
79
         * {@inheritDoc}
80
         */
81
        public function get_object_type(): string {
82
                $post_types = WPGraphQL::get_allowed_post_types( 'objects' );
1✔
83

84
                return $post_types[ $this->data->name ]->graphql_single_name;
1✔
85
        }
86

87
        /**
88
         * {@inheritDoc}
89
         *
90
         * @throws \GraphQL\Error\UserError If no archive URI.
91
         */
92
        protected function get_object_url(): string {
93
                $term_link = get_post_type_archive_link( $this->data->name );
1✔
94

95
                if ( false === $term_link ) {
1✔
96
                        throw new UserError( esc_html__( 'There is no archive URI for the provided post type', 'wp-graphql-rank-math' ) );
×
97
                }
98

99
                return $term_link;
1✔
100
        }
101
}
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