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

Yoast / wordpress-seo / 5066322038

pending completion
5066322038

push

github

GitHub
Merge pull request #20316 from Yoast/JRF/ghactions-run-more-selectively

2550 of 29012 relevant lines covered (8.79%)

0.32 hits per line

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

0.0
/src/memoizers/presentation-memoizer.php
1
<?php
2

3
namespace Yoast\WP\SEO\Memoizers;
4

5
use Yoast\WP\SEO\Context\Meta_Tags_Context;
6
use Yoast\WP\SEO\Models\Indexable;
7
use Yoast\WP\SEO\Presentations\Indexable_Presentation;
8
use YoastSEO_Vendor\Symfony\Component\DependencyInjection\ContainerInterface;
9

10
/**
11
 * The presentation memoizer.
12
 */
13
class Presentation_Memoizer {
14

15
        /**
16
         * The service container.
17
         *
18
         * @var ContainerInterface
19
         */
20
        protected $container;
21

22
        /**
23
         * Cache with indexable presentations.
24
         *
25
         * @var Indexable_Presentation[]
26
         */
27
        protected $cache = [];
28

29
        /**
30
         * Presentation_Memoizer constructor.
31
         *
32
         * @param ContainerInterface $service_container The service container.
33
         */
34
        public function __construct( ContainerInterface $service_container ) {
35
                $this->container = $service_container;
×
36
        }
37

38
        /**
39
         * Gets the presentation of an indexable for a specific page type.
40
         * This function is memoized by the indexable so every call with the same indexable will yield the same result.
41
         *
42
         * @param Indexable         $indexable The indexable to get a presentation of.
43
         * @param Meta_Tags_Context $context   The current meta tags context.
44
         * @param string            $page_type The page type.
45
         *
46
         * @return Indexable_Presentation The indexable presentation.
47
         */
48
        public function get( Indexable $indexable, Meta_Tags_Context $context, $page_type ) {
49
                if ( ! isset( $this->cache[ $indexable->id ] ) ) {
×
50
                        $presentation = $this->container->get( "Yoast\WP\SEO\Presentations\Indexable_{$page_type}_Presentation", ContainerInterface::NULL_ON_INVALID_REFERENCE );
×
51

52
                        if ( ! $presentation ) {
×
53
                                $presentation = $this->container->get( Indexable_Presentation::class );
×
54
                        }
55

56
                        $context->presentation = $presentation->of(
×
57
                                [
×
58
                                        'model'   => $indexable,
×
59
                                        'context' => $context,
×
60
                                ]
×
61
                        );
×
62

63
                        $this->cache[ $indexable->id ] = $context->presentation;
×
64
                }
65

66
                return $this->cache[ $indexable->id ];
×
67
        }
68

69
        /**
70
         * Clears the memoization of either a specific indexable or all indexables.
71
         *
72
         * @param Indexable|int|null $indexable Optional. The indexable or indexable id to clear the memoization of.
73
         */
74
        public function clear( $indexable = null ) {
75
                if ( $indexable instanceof Indexable ) {
×
76
                        unset( $this->cache[ $indexable->id ] );
×
77
                        return;
×
78
                }
79
                if ( \is_int( $indexable ) ) {
×
80
                        unset( $this->cache[ $indexable ] );
×
81
                        return;
×
82
                }
83
                if ( $indexable === null ) {
×
84
                        $this->cache = [];
×
85
                }
86
        }
87
}
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