Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
81.82% covered (warning)
81.82%
9 / 11
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
WordAds_Formats
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
9
100.00% covered (success)
100.00%
1 / 1
 get_format_slug
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
9
1<?php
2/**
3 * WordAds Formats Class file.
4 *
5 * This file contains the definition of the WordAds_Formats class, which handles
6 * determining the appropriate WordAds format slug based on ad slot dimensions.
7 *
8 * @package automattic/jetpack
9 */
10
11declare( strict_types = 1 );
12
13if ( ! defined( 'ABSPATH' ) ) {
14    exit( 0 );
15}
16
17/**
18 * Class WordAds_Formats
19 *
20 * Set of WordAds methods working with formats and Ad dimensions.
21 */
22class WordAds_Formats {
23    /**
24     * Determine the WordAds format based on the ad dimensions.
25     *
26     * @param int $width  The width of the ad slot.
27     * @param int $height The height of the ad slot.
28     *
29     * @return string WordAds Format enum.
30     */
31    public static function get_format_slug( int $width, int $height ): string {
32        if ( $width === 300 && $height === 250 ) {
33            return 'gutenberg_rectangle';
34        }
35
36        if ( $width === 728 && $height === 90 ) {
37            return 'gutenberg_leaderboard';
38        }
39
40        if ( $width === 320 && $height === 50 ) {
41            return 'gutenberg_mobile_leaderboard';
42        }
43
44        if ( $width === 160 && $height === 600 ) {
45            return 'gutenberg_skyscraper';
46        }
47
48        return '';
49    }
50}