• 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/generators/twitter-image-generator.php
1
<?php
2

3
namespace Yoast\WP\SEO\Generators;
4

5
use Yoast\WP\SEO\Context\Meta_Tags_Context;
6
use Yoast\WP\SEO\Helpers\Image_Helper;
7
use Yoast\WP\SEO\Helpers\Twitter\Image_Helper as Twitter_Image_Helper;
8
use Yoast\WP\SEO\Helpers\Url_Helper;
9
use Yoast\WP\SEO\Models\Indexable;
10
use Yoast\WP\SEO\Values\Images;
11

12
/**
13
 * Represents the generator class for the Twitter images.
14
 */
15
class Twitter_Image_Generator implements Generator_Interface {
16

17
        /**
18
         * The image helper.
19
         *
20
         * @var Image_Helper
21
         */
22
        protected $image;
23

24
        /**
25
         * The URL helper.
26
         *
27
         * @var Url_Helper
28
         */
29
        protected $url;
30

31
        /**
32
         * The Twitter image helper.
33
         *
34
         * @var Twitter_Image_Helper
35
         */
36
        protected $twitter_image;
37

38
        /**
39
         * Twitter_Image_Generator constructor.
40
         *
41
         * @codeCoverageIgnore
42
         *
43
         * @param Image_Helper         $image         The image helper.
44
         * @param Url_Helper           $url           The url helper.
45
         * @param Twitter_Image_Helper $twitter_image The Twitter image helper.
46
         */
47
        public function __construct( Image_Helper $image, Url_Helper $url, Twitter_Image_Helper $twitter_image ) {
48
                $this->image         = $image;
49
                $this->url           = $url;
50
                $this->twitter_image = $twitter_image;
51
        }
52

53
        /**
54
         * Retrieves the images for an indexable.
55
         *
56
         * @param Meta_Tags_Context $context The context.
57
         *
58
         * @return array The images.
59
         */
60
        public function generate( Meta_Tags_Context $context ) {
61
                $image_container = $this->get_image_container();
×
62

63
                $this->add_from_indexable( $context->indexable, $image_container );
×
64

65
                return $image_container->get_images();
×
66
        }
67

68
        /**
69
         * Adds an image based on the given indexable.
70
         *
71
         * @param Indexable $indexable       The indexable.
72
         * @param Images    $image_container The image container.
73
         */
74
        protected function add_from_indexable( Indexable $indexable, Images $image_container ) {
75
                if ( $indexable->twitter_image_id ) {
×
76
                        $image_container->add_image_by_id( $indexable->twitter_image_id );
×
77
                        return;
×
78
                }
79

80
                if ( $indexable->twitter_image ) {
×
81
                        $image_container->add_image_by_url( $indexable->twitter_image );
×
82
                }
83
        }
84

85
        /**
86
         * Retrieves an instance of the image container.
87
         *
88
         * @codeCoverageIgnore
89
         *
90
         * @return Images The image container.
91
         */
92
        protected function get_image_container() {
93
                $image_container             = new Images( $this->image, $this->url );
94
                $image_container->image_size = $this->twitter_image->get_image_size();
95

96
                return $image_container;
97
        }
98
}
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