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

wp-graphql / wp-graphql / 14716683875

28 Apr 2025 07:58PM UTC coverage: 84.287% (+1.6%) from 82.648%
14716683875

push

github

actions-user
release: merge develop into master for v2.3.0

15905 of 18870 relevant lines covered (84.29%)

257.23 hits per line

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

92.86
/src/Model/UserRole.php
1
<?php
2

3
namespace WPGraphQL\Model;
4

5
use GraphQLRelay\Relay;
6

7
/**
8
 * Class UserRole - Models data for user roles
9
 *
10
 * @property ?string[] $capabilities
11
 * @property ?string   $displayName
12
 * @property string    $id
13
 * @property ?string   $name
14
 *
15
 * @package WPGraphQL\Model
16
 */
17
class UserRole extends Model {
18

19
        /**
20
         * Stores the incoming user role to be modeled
21
         *
22
         * @var array<string,mixed> $data
23
         */
24
        protected $data;
25

26
        /**
27
         * UserRole constructor.
28
         *
29
         * @param array<string,mixed> $user_role The incoming user role to be modeled
30
         *
31
         * @return void
32
         * @throws \Exception
33
         */
34
        public function __construct( $user_role ) {
18✔
35
                $this->data = $user_role;
18✔
36
                parent::__construct();
18✔
37
        }
38

39
        /**
40
         * {@inheritDoc}
41
         */
42
        protected function is_private() {
18✔
43
                if ( current_user_can( 'list_users' ) ) {
18✔
44
                        return false;
11✔
45
                }
46

47
                $current_user_roles = wp_get_current_user()->roles;
7✔
48

49
                if ( in_array( $this->data['slug'], $current_user_roles, true ) ) {
7✔
50
                        return false;
7✔
51
                }
52

53
                return true;
×
54
        }
55

56
        /**
57
         * {@inheritDoc}
58
         */
59
        protected function init() {
18✔
60
                if ( empty( $this->fields ) ) {
18✔
61
                        $this->fields = [
18✔
62
                                'capabilities' => function () {
18✔
63
                                        if ( empty( $this->data['capabilities'] ) || ! is_array( $this->data['capabilities'] ) ) {
2✔
64
                                                return null;
×
65
                                        }
66

67
                                        return array_keys( $this->data['capabilities'] );
2✔
68
                                },
18✔
69
                                'displayName'  => function () {
18✔
70
                                        return ! empty( $this->data['displayName'] ) ? esc_html( $this->data['displayName'] ) : null;
2✔
71
                                },
18✔
72
                                'id'           => function () {
18✔
73
                                        return Relay::toGlobalId( 'user_role', $this->data['id'] );
18✔
74
                                },
18✔
75
                                'name'         => function () {
18✔
76
                                        return ! empty( $this->data['name'] ) ? esc_html( $this->data['name'] ) : null;
17✔
77
                                },
18✔
78
                        ];
18✔
79
                }
80
        }
81
}
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