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

AxeWP / wp-graphql-rank-math / 5246956983

pending completion
5246956983

push

github

web-flow
release: 0.0.13 (#56)

* chore: version bump

* chore: update changelog

2501 of 2738 relevant lines covered (91.34%)

10.7 hits per line

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

58.82
/src/Modules/Redirection/Data/Loader/RedirectionsLoader.php
1
<?php
2
/**
3
 * DataLoader - Redirections
4
 *
5
 * @package WPGraphQL\RankMath\Modules\Redirection\Data\Loader
6
 */
7

8
namespace WPGraphQL\RankMath\Modules\Redirection\Data\Loader;
9

10
use GraphQL\Error\UserError;
11
use WPGraphQL\Data\Loader\AbstractDataLoader;
12
use WPGraphQL\RankMath\Modules\Redirection\Model\Redirection;
13
use WPGraphQL\RankMath\Utils\RMUtils;
14

15
/**
16
 * Class - RedirectionsLoader
17
 */
18
class RedirectionsLoader extends AbstractDataLoader {
19
        /**
20
         * Loader name.
21
         *
22
         * @var string
23
         */
24
        public static string $name = 'redirections';
25

26
        /**
27
         * {@inheritDoc}
28
         */
29
        protected function get_model( $entry, $key ): Redirection {
30
                return new Redirection( $entry );
8✔
31
        }
32

33
        /**
34
         * {@inheritDoc}
35
         *
36
         * @throws \GraphQL\Error\UserError If a redirection does not exist.
37
         */
38
        protected function loadKeys( array $keys ) {
39
                if ( empty( $keys ) ) {
2✔
40
                        return $keys;
×
41
                }
42

43
                $table = RMUtils::get_redirections_table();
2✔
44

45
                $redirections = $table->where( 'id', 'IN', $keys )->get( ARRAY_A );
2✔
46

47
                $loaded = [];
2✔
48

49
                foreach ( $keys as $key ) {
2✔
50
                        $index = array_search( $key, array_column( $redirections, 'id' ) );
2✔
51
                        if ( ! isset( $redirections[ $index ] ) ) {
2✔
52
                                throw new UserError(
×
53
                                        sprintf(
×
54
                                                // translators: %s is the redirection ID.
55
                                                __( 'Redirection with ID "%s" does not exist.', 'wp-graphql-rank-math' ),
×
56
                                                $key
×
57
                                        ),
×
58
                                );
×
59
                        }
60

61

62
                        $loaded[ $key ] = $redirections[ $index ];
2✔
63
                }
64

65
                return $loaded;
2✔
66
        }
67
}
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